I upgraded from 21.02.23 to 23.09.09 and my model spatiotemporal model gives an error when trying to draw posterior samples and the fitted parameters are off compared to the previous version which looked good.
GitId: 5829adacd2938bbeabc52513438b1504e8438f65 - Sat Sep 9 15:30:58 2023 +0300
Error:2 Reason: Matrix is not (numerical) positive definite
Line:389 Function: GMRFLib_init_problem
The model formula and fit code and summary are at the end. Note that s2 is an spde in space, s is an spde on the same spatial mesh with an additional 1d mesh on time (c.f. Chapter 7.2 of Krainski et al textbook), and t is a descretized time step. The idea is to have a global temporal trend, global spatial mean, and a (separable) spatiotemporal interaction.
There are no errors in the fit but comparing the summary to the successful one on the earlier INLA version there are two differences: First, the intercept 0 +/- 10 has a huge SD (the outcome is standardized) whereas on the earlier INLA version the intercept was 0 +/- 0.03. Second, The earlier version had one quarter the range and stdev for the s2 term.
Note that there is no problem (fit agrees with earlier version and inla.posterior.samples() works) if I drop the spatiotemporal interaction f(s, ...).
Thanks for your help. I plan to try an intermediate INLA version tomorrow.
Eric
----------
mesh <- inla.mesh.2d(
loc = coo, boundary = bnd,
max.edge = c(1000, 1000),
cutoff = 10
)
spde <- inla.spde2.pcmatern(
mesh = mesh, alpha = 1.5,
prior.range = c(10, 0.01), # P(range < 10000) = 0.01
prior.sigma = c(5, 0.01) # P(sigma > 3) = 0.01
)
timesn <- 20
mesh.t = inla.mesh.1d(seq(min(subset_RS21$t)+0.5, max(subset_RS21$t)-0.5, length=timesn))
indexs <- inla.spde.make.index("s",
n.spde = spde$n.spde,
n.group = timesn
)
indexs2 <- inla.spde.make.index("s2",
n.spde = spde$n.spde
)
A <- inla.spde.make.A(mesh = mesh, loc = coo, group = subset_RS21$t, group.mesh=mesh.t)
A2 <- inla.spde.make.A(mesh = mesh, loc = coo)
stk.e <- inla.stack(
tag = "est",
data = list(y = subset_RS21$log_n2o %>% scale),
A = list(1, A, A2),
effects = list(data.frame(b0 = rep(1, nrow(subset_RS21)),
t=as.factor(subset_RS21$t_1h)),
s = indexs,
s2 = indexs2)
)
pred_RS21 = expand_grid(
pixels_RS %>% sample_n(5),
t = seq(min(floor(subset_RS21$t)), ceiling(max(subset_RS21$t)))
)
coop <- pred_RS21[, c("X","Y")] %>% as.matrix
Ap <- inla.spde.make.A(mesh = mesh, loc = coop, group = pred_RS21$t, group.mesh=mesh.t)
Ap2 <- inla.spde.make.A(mesh = mesh, loc = coop)
stk.p <- inla.stack(
tag = "pred",
data = list(y = NA),
A = list(1, Ap, Ap2),
effects = list(data.frame(b0 = rep(1, nrow(pred_RS21)),
t=as.factor(pred_RS21$t)),
s = indexs,
s2 = indexs2)
)
stk.full <- inla.stack(stk.e, stk.p)
formula <- y ~ 0 + b0 +
f(s2, model=spde) +
f(t, model="rw1") +
f(s, model = spde, group = s.group, control.group = list(model = "rw1"))
res <- inla(formula,
data = inla.stack.data(stk.full),
control.predictor = list(
compute = TRUE,
A = inla.stack.A(stk.full)
),
control.compute=list(config=TRUE)
)
summary(res)
Fixed effects:
mean sd 0.025quant 0.5quant 0.975quant mode kld
b0 0 10.584 -20.755 0 20.755 0 0
Random effects:
Name Model
s2 SPDE2 model
t RW1 model
s SPDE2 model
Model hyperparameters:
mean sd 0.025quant 0.5quant
Precision for the Gaussian observations 22.51 0.811 20.945 22.502
Range for s2 88.35 124.444 7.895 51.580
Stdev for s2 1.46 1.743 0.114 0.926
Precision for t 82.81 16.183 55.508 81.279
Range for s 154.44 17.037 123.881 153.425
Stdev for s 2.34 0.190 1.991 2.331
0.975quant mode
Precision for the Gaussian observations 24.14 22.491
Range for s2 399.57 20.046
Stdev for s2 6.01 0.312
Precision for t 118.97 78.303
Range for s 190.88 151.239
Stdev for s 2.74 2.313