inla.knmodels {INLA} | R Documentation |
It implements the models in Knorr-Held, L. (2000) with three different constraint approaches: sum-to-zero, contrast or diagonal add.
inla.knmodels( formula, progress = FALSE, control.st = list(time, space, spacetime, graph, type = c(paste(1:4), paste0(2:4, "c"), paste0(2:4, "d")), diagonal = 1e-05, timeref = 1, spaceref = 1, ...), ... )
formula |
The formula specifying the other model components, without
the spacetime interaction term. The spacetime interaction term will be added
accordly to the specification in the |
progress |
If it is to be shown the model fitting progress. Useful if more than one interaction type is being fitted. |
control.st |
Named list of arguments to control the spacetime interaction. It should contain:
|
... |
Arguments to be passed to the |
inla.knmodels
returns an object of class "inla"
. or a
list of objects of this class if it is asked to compute more than one
interaction type at once. Note: when the model type is 2c, 3c, 4c, 2d, 3d
or 4d, it also includes linear combinations summary.
Elias T. Krainski
inla.knmodels.sample
to sample from
### define space domain as a grid grid <- SpatialGrid(GridTopology(c(0,0), c(1, 1), c(4, 5))) (n <- nrow(xy <- coordinates(grid))) ### build a spatial neighborhood list jj <- lapply(1:n, function(i) which(sqrt((xy[i,1]-xy[,1])^2 + (xy[i,2]-xy[,2])^2)==1)) ### build the spatial adjacency matrix graph <- sparseMatrix(rep(1:n, sapply(jj, length)), unlist(jj), x=1, dims=c(n, n)) ### some random data at 10 time point dat <- inla.knmodels.sample(graph, m=10, tau.t=2, tau.s=2, tau.st=3) str(dat) sapply(dat$x, summary) nd <- length(dat$x$eta) dat$e <- runif(nd, 0.9, 1.1)*rgamma(n, 40, 2) dat$y <- rpois(nd, dat$e*exp(dat$x$eta-3)) summary(dat$y) ### fit the type 4 considering three different approaches tgraph <- sparseMatrix(i=c(2:10, 1:9), j=c(1:9, 2:10), x=1) res <- inla.knmodels(y ~ f(time, model='bym2', graph=tgraph) + f(space, model='bym2', graph=graph), data=dat, family='poisson', E=dat$E, progress=TRUE, control.st=list(time=time, space=space, spacetime=spacetime, graph=graph, type=c(4, '4c', '4d')), control.compute=list(dic=TRUE, waic=TRUE, cpo=TRUE)) sapply(res, function(x) c(dic=x$dic$dic, waic=x$waic$waic, cpo=-sum(log(x$cpo$cpo))))