Hello,
I'm sure there's something I'm doing wrong but I can't figure it out. I'm fitting a separable space-time model in R-INLA, with the goal of doing prediction via sampling using inla.posterior.sample. The first issue has to do with the model fitting, which I am doing as follows:
knots=min(cattle_data@data$time):max(cattle_data@data$time)
mesh = inla.mesh.2d(loc.domain = loc.mesh,
max.edge = c(0.3,0.6),
offset = c(1, 1))
spde_RE<-inla.spde2.matern(mesh, alpha=2)
A<-inla.spde.make.A(mesh, loc=coords_cattle, group=cattle_data@data$time, n.group=length(knots))
iset <- inla.spde.make.index('i', n.spde=spde_RE$n.spde, n.group=length(knots))
stk.dat.c<-inla.stack(
data=list(resp=cattle_data@data$n.cattle),
A=list(A,1),
effects=list(c(iset, list(intercept=1)), list(cattle_data@data)),
tag='est')
pcprior<-list(theta = list(prior = "pc.prec", params = c(3, 0.05)))
f.spde <- resp ~ 0 + intercept + urban + f(i, model=spde_RE, hyper = pcprior, group=i.group, control.group=list(model="ar1"))
res<-inla (f.spde, data=inla.stack.data(stk.dat.c), family="zeroinflatedpoisson1", offset=log(cattle_data@data$mem.cattle), control.predictor=list(A=inla.stack.A(stk.dat.c)),
num.threads = inla.getOption("num.threads"), control.compute=list(config = TRUE), verbose=TRUE)
-------------------------
The dataset has 6,290 rows, the mesh has 1,428 vertices, and there are 17 knots in total. There is at least one row in the dataset (cattle_data) corresponding to each knot (i.e., each "time" value). My goal is to do prediction via sampling using inla.posterior.sample.
The A matrix is 6290 x 24276 as expected, but res$summary.random$i has 1,428 rows (that is, equal to the number of mesh vertices). I believe this should have # rows = # mesh vertices * # knots, that is 24,276. Is that correct? Similarly, the corresponding entry in res$misc$configs$contents$length is 1,428.
The second issue has to do with the mesh for prediction. My code for this is:
Aprd<-inla.spde.make.A(mesh, loc.pred, group=kIdx, n.group=length(knots))
Where "kIdx" is the group index (1-17), and there are 90,000 locations for prediction. This is a 1428 x 24276 matrix.
My thought is if the corresponding draw from inla.posterior.sample is of length 24276, I can then do draw%*%Aprd for prediction. Is my Aprd code a matrix to project from the space-time mesh, to a space only mesh at the indicated knot, and then I need a second matrix to project to the prediction locations?
Alternatively, if you can point me to an example of sampling via prediction on a separable space-time model, that would be helpful. As you may be able to tell, I am not a statistician!
Thanks,
Julianne