inla.knmodels {INLA} | R Documentation

## Spacetime interaction models

### Description

It implements the models in Knorr-Held, L. (2000) with three different constraint approaches: sum-to-zero, contrast or diagonal add.

### Usage

    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),
      ...,
      envir = parent.frame()
    )

### Arguments

`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 `control.st` argument. See `inla`
`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: 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.
`envir` | Environment in which to evaluate the ... arguments.

### Value

`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.

### Author(s)

Elias T. Krainski

### See Also

`inla.knmodels.sample()` to sample from

### Examples

    ### define space domain as a grid
    grid <- sp::SpatialGrid(sp::GridTopology(c(0,0), c(1, 1), c(4, 5)))
    (n <- nrow(xy <- sp::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')),
         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))))

[Package INLA version 25.06.07 Index]