Ordinarily, if you want to account for the effect spatial boundaries have on certain variables. You could fit as follows as highlighted in Virgilio Gómez-Rubio's Bayesian inference with INLA article.
library("rgdal")
boston.tr <- readOGR(system.file("shapes/boston_tracts.shp", package="spData")1)
boston.adj <- poly2nb(boston.tr)
W.boston <- nb2mat(boston.adj, style = "B")
W.boston.rs <- nb2mat(boston.adj, style = "W")
boston.form <- log(CMEDV2) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) +
AGE + log(DIS) + log(RAD) + TAX + PTRATIO + B + log(LSTAT)
boston.tr$ID <- 1:length(boston.tr)
boston.bym <- inla(update(boston.form, . ~. +
f(ID, model = "bym", graph = W.boston)), data = as.data.frame(boston.tr),
control.compute = list(dic = TRUE, waic = TRUE, cpo = TRUE),
control.predictor = list(compute = TRUE))
However, assuming the boston.tr shapefile was not spacial boundaries (polygons) but spacial points (coordinates), How can I go about fitting the same model.
I tried creating a binary adjacency matrix so that two points are neighbors only if they are at least 10 kilometers apart but I get the following err
Error in inla(formula, .... Covariate does not match 'values' 2958 times. Indexes for mismatch:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 85