knmodels.RdIt implements the models in Knorr-Held, L. (2000) with three different constraint approaches: sum-to-zero, contrast or diagonal add.
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 control.st argument. See inla
If it is to be shown the model fitting progress. Useful if more than one interaction type is being fitted.
Named list of arguments to control
the spacetime interaction. It should contains:
time to be used as the index set for the
main temporal effect which will be considered
for the constraints when it is the case.
space to be used as the index set for the
main spatial effect which will be considered
for the constraints when it is the case.
spacetime to be the index set for the
spacetime interaction effect.
graph to be the graph for the spatial neighbor
structure to be used in a f term
for the main spatial random effect term or for
building the spacetime interaction model.
type to specify the spacetime interaction type.
1 to 4 corresponds to the four
interaction types in Knorr-Held, L. (2000) with
all the needed sum-to-zero constraints.
2c, 3c and 4c are
the contrast version considering the first time
or space constrained to be equal to zero.
2d, 3d and 4d are the
corresponding versions when considering the
diagonal add approach.
diagonal to be the value to be added to the
diagonal when using the diagonal add approach.
timeref to specify the time point to be the
reference time in the contrast parametrization.
spaceref to specify the area to be the
reference for the contrast parametrization.
... where additional arguments can be
passed to f function.
Specification of the hyperparameter,
fixed or random, initial value, prior and its
parameters for the spacetime interaction. See
?inla.models and look for generic0.
By default we scale it and use the PC-prior to set
the prior using the pc.prec prior with
param = c(0.5, 0.5). See documentation with
?inla.doc("pc.prec").
...Arguments to be passed to the
inla function.
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.
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)))
#> [1] 20
### 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)
#> Error in system(paste(shQuote(inla.call.no.remote()), "-s -m qinv", "-r", reordering, "-t", num.threads, "-S", smtp, qinv.file, constr.file, out.file), intern = TRUE): error in running command
str(dat)
#> Error: object 'dat' not found
sapply(dat$x, summary)
#> Error: object 'dat' not found
nd <- length(dat$x$eta)
#> Error: object 'dat' not found
dat$e <- runif(nd, 0.9, 1.1)*rgamma(n, 40, 2)
#> Error: object 'nd' not found
dat$y <- rpois(nd, dat$e*exp(dat$x$eta-3))
#> Error: object 'nd' not found
summary(dat$y)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'object' in selecting a method for function 'summary': object 'dat' not found
### 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))
#> Error in eval(mcall$data): object 'dat' not found
sapply(res, function(x)
c(dic=x$dic$dic, waic=x$waic$waic, cpo=-sum(log(x$cpo$cpo))))
#> Error: object 'res' not found