I'm having issues successful running models with linear combinations - my models have run previously (years ago), but i'm getting back to some old code and can't replicate ()or even run!) the model... model without linear combinations work fine - 2 examples below, neither of the models with linear combinations work for me - they just run for hours - any thoughts welcome, I'm sure it must be something obvious....
### Dummy data:
set.seed(12)
library(spdep)
library(gstat)
x1 <- runif(100)
x2 <- runif(100)
x3 <- x1 + runif(100)/3
xy <- expand.grid(x = 1:10, y =1:10)
g.dummy <- gstat(formula=z~1, locations=~x+y, dummy=T, beta=1,
model=vgm(psill=0.025,model="Exp",range=3), nmax=20)
yy <- predict(g.dummy, newdata=xy, nsim=1)
y <- x1 + rnorm(100)/2 + yy[,3]
y1 <- x1 + x3 + rnorm(100)/2 + yy[,3]
ID <- 1:100
neighs <- dnearneigh(as.matrix(xy), d1 = 0, d2 = 1.5) #identified neighbours within 1.75km (i.e. queen's case adjacency)
nb2INLA( "dummy.txt", neighs)
dummy.data <- data.frame( y = y, y1 = y1, x1 = c(scale(x1)), x2 = c(scale(x2)),
x3 = c(scale(x3)), ID = ID)
x.vals <- seq(min(x2), max(x2), length = 100)
lc <- inla.make.lincombs(x2=cbind(x.vals),"(Intercept)" = cbind(rep(1, 100)))
# model without linear combinations works
test.full <- inla(y ~ x1 + x2 + f(ID, model = "besag", graph = "dummy.txt",
hyper = list(prec = list(prior="pc.prec", param=c(1,0.5)))),
family = "gaussian",
# lincomb = all.lincombs,
control.compute = list(dic=TRUE, waic = TRUE),
data = dummy.data, control.predictor = list(compute = TRUE))
summary(test.full)
# model with linear combinations doesn't work
test.full.lc <- inla(y ~ x1 + x2 + f(ID, model = "besag", graph = "dummy.txt",
hyper = list(prec = list(prior="pc.prec", param=c(1,0.5)))),
family = "gaussian",
lincomb = lc,
control.compute = list(dic=TRUE, waic = TRUE),
data = dummy.data, control.predictor = list(compute = TRUE))