rm(list = ls())
library(INLA)
pl.dom <- cbind(c(0, 1, 1, 0.7, 0), c(0, 0, 0.7, 1, 1))
mesh5 <- inla.mesh.2d(loc.domain = pl.dom, max.e = c(0.092, 0.2))
coords <- as.matrix(SPDEtoy[, 1:2])
A5 <- inla.spde.make.A(mesh5, loc = coords)
spde5 <- inla.spde2.matern(
mesh = mesh5,
alpha = 1.5,
B.tau = matrix(c(-0.5 * log(4 * pi), 0.5,-0.5), 1, 3),
B.kappa = matrix(c(0, 0, 1), 1, 3)
)
stk5 <- inla.stack(
data = list(resp = SPDEtoy$y),
A = list(A5, 1),
effects = list(i = 1:spde5$n.spde,
beta0 = rep(1, nrow(SPDEtoy))),
tag = 'est'
)
# working default ---------------------------------------------------------
res5 <- inla(
resp ~ 0 + beta0 + f(i, model = spde5),
data = inla.stack.data(stk5),
control.predictor = list(A = inla.stack.A(stk5))
)
# try1 to reset prior -----------------------------------------------------
res5 <- inla(
resp ~ 0 + beta0 + f(
i,
model = spde5,
hyper = list(
theta1 = list(param = c(2.01, 1.01), prior = "loggamma"),
theta2 = list(param = c(2.01, 1.01), prior = "loggamma")
)
),
data = inla.stack.data(stk5),
control.predictor = list(A = inla.stack.A(stk5))
)
# try2 to reset prior -----------------------------------------------------
spde5$f$hyper.default <- list(
theta1 = list(param = c(2.01, 1.01), prior = "loggamma"),
theta2 = list(param = c(2.01, 1.01), prior = "loggamma")
)
res5 <- inla(
resp ~ 0 + beta0 + f(i, model = spde5),
data = inla.stack.data(stk5),
control.predictor = list(A = inla.stack.A(stk5))
)
I get the following error:
I could not find the inla.set.hyper in the documentation for the users, so I can not tell what is wrong, but telling from the 'read-only' hint, is it forbidden to change priors for theta1 and theta2? Is there a way to work around this, or have I misunderstood some of the hints above?