Separable space-time model + prediction via sampling: coding query

71 views
Skip to first unread message

Julianne Meisner

unread,
Nov 7, 2019, 6:35:27 PM11/7/19
to R-inla discussion group
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


Elias T. Krainski

unread,
Nov 8, 2019, 8:30:24 AM11/8/19
to r-inla-disc...@googlegroups.com

What is the output of

length(knots)

Elias

--
You received this message because you are subscribed to the Google Groups "R-inla discussion group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to r-inla-discussion...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/r-inla-discussion-group/a9ab763f-9b38-4b85-8490-754d67ebb7d3%40googlegroups.com.

Julianne Meisner

unread,
Nov 11, 2019, 2:41:25 PM11/11/19
to R-inla discussion group
Any other assistance on this issue would be much appreciated-- I haven't made any headway in the past 4 days. 

Thanks,
Julianne

Elias T. Krainski

unread,
Nov 11, 2019, 3:29:16 PM11/11/19
to r-inla-disc...@googlegroups.com

Dear Julianne,

It is hard to tell what is the problem without reproducible code. If you provide it, we can try and see what is going  on.

Best regards,

Elias

--
You received this message because you are subscribed to the Google Groups "R-inla discussion group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to r-inla-discussion...@googlegroups.com.

Julianne Meisner

unread,
Nov 15, 2019, 5:58:18 PM11/15/19
to Elias T. Krainski, R-inla discussion group
Thanks, Elias, I was able to get back to this today and discovered it was an issue in how I was building my stack, which I have now resolved. 

I still have one remaining question, which I hope will be more straightforward to answer. When predicting by sampling (using inla.posterior.sample) using a space-time model, I should be building my projection matrix as Aprd<-inla.spde.make.A(mesh, loc.pred, group=kIdx), where kIdx is the index for the group (time) I want to do prediction for and loc.pred=# prediction locations, correct? The resulting matrix will have nrows=loc.pred and ncols=mesh$n.

Many thanks,
Julianne



--
Julianne Meisner, BVM&S(Vet) MS
PhD student | Center for One Health Research
Department of Epidemiology | University of Washington
Reply all
Reply to author
Forward
0 new messages