Dear all,
My problems may be coming from the ID column which is a list of 1834 unique IDs, not starting at 1 (i.e. 2, 3, 4, 8 ....2053). The lattice has 1834 squares. My code is:
lattice <- readOGR("grid_with_points.shp")
data <- lattice@data # first variable is 'ID' = chr
Lattice_Temp <- poly2nb(lattice, row.names = data$ID)
nb2INLA("Lattice.graph", Lattice_Temp)
Lattice.adj <- "Lattice.graph"
data$ID <- as.numeric(data$ID)
formula <- NUMPOINTS ~ NGcost_mea + elev_mean + elev_min + elev_max +
X1_mean + X2_mean + X3_mean + X4_mean + X5_mean + X6_mean + X7_mean +
X8_mean + X9_mean + X10_mean + X11_mean + X12_mean + X13_mean + X14_mean + X15_mean + X16_mean + X17_mean + X18_mean + X19_mean + X21_mean + X22_mean + X23_mean + X24_mean + X25_mean + X26_mean + X27_mean + X28_mean + X29_mean + X30_mean + X31_mean + X32_mean + X33_mean + X34_mean + X35_mean + X36_mean + X37_mean + X38_mean + X39_mean + X40_mean + X41_mean + X42_mean + X43_mean + X44_mean + X45_mean + X46_mean + f(ID, model = "bym", graph = Lattice.adj)
Mod_Lattice <- inla(formula,
family = "poisson",
data = data,
control.compute = list(cpo = T, dic = T, waic = T))
I get " f(ID). Covariate does not match 'values' 177 times. Indexes for mismatch:929 930 [...etc...] 1834. This is not what you want. Use NA values in the covariate"
Yet if I leave ID as a 'chr' field I get this instead: "In f(ID): 'covariate' must match 'values', and both must either be 'numeric', or 'factor'/'character'." Scylla and Charybdis....
Looking at the helpfile for poly2nb, it seems a character vector is expected for the
region.id. I tried setting it as numeric: no immediate problem, but I still get the 'covariate does not match' error. I tried not setting row.names at all - this gives me a
region.id of 1:1834 but the same error.
Does anyone have any advice? And what's that about NA values?