Description Usage Arguments Value Author(s) See Also Examples
It implements the models in Knorr-Held, L. (2000) with three different constraint approaches: sum-to-zero, contrast or diagonal add.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
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 contains:
|
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | ### 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 points
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))))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.