smooth.construct.spde.smooth.spec: Matérn via SPDEs in GAMs

Description Usage Arguments Details Note Author(s) References Examples

View source: R/spde_smooth.R

Description

Uses constructors from package R-INLA to build the stochastic partial differential equation Matérn model of Lindgren et al (2011). Details also in Miller et al (2019).

Usage

1
2
3
4
5
## S3 method for class 'spde.smooth.spec'
smooth.construct(object, data, knots)

## S3 method for class 'spde.smooth'
Predict.matrix(object, data)

Arguments

object

a smooth specification object, usually generated by a term s(x,bs="bs",...)

data

a list containing just the data (including any by variable) required by this term, with names corresponding to object$term (and object$by). The by variable is the last element.

knots

a list containing any knots supplied for basis setup — in same order and with same names as data. Can be NULL. See details for further information.

Details

For one dimensional smooths a mesh will be autogenerated using INLA::inla.mesh.1d with k evenly spaces basis functions (degree 2 B-splines). For other cases you need to supply xt$mesh which should be an object generated by INLA::inla.mesh.

If you want to compare "smoothing parameter" estimates with those produced by R-INLA then you need to add the control = gam.control(scalePenalty = FALSE) option to your mgcv::gam call.

Note

The INLA package is required to use this function see the R-INLA website for details on installation.

Author(s)

David L Miller

References

Miller, D. L., Glennie, R., & Seaton, A. E. (2019). Understanding the Stochastic Partial Differential Equation Approach to Smoothing. Journal of Agricultural, Biological and Environmental Statistics. https://doi.org/10.1007/s13253-019-00377-z Lindgren, F., Rue, H., & Lindström, J. (2011). An explicit link between Gaussian fields and Gaussian Markov random fields: The stochastic partial differential equation approach. Journal of the Royal Statistical Society: Series B (Statistical Methodology), 73(4), 423–498. https://doi.org/10.1111/j.1467-9868.2011.00777.x

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## Not run: 
library(mgcv)
set.seed(2) ## simulate some data... 
dat <- gamSim(1,n=400,dist="normal",scale=2)

# fit model, ensuring smoothing parameters are comparable
# to those generated by INLA
b <- gam(y~s(x2, bs="spde", k=50),data=dat,
         control = gam.control(scalePenalty = FALSE))
# look at results
summary(b)
plot(b)

# get hyperparameter estimates (as defined in Lindgren et al. 2011)
tau <- b$sp[1]
kappa <- b$sp[2]
# compute correlation range (rho) and marginal variance (sigma)
rho <- sqrt(8*1.5) / kappa

## End(Not run)

dill/gamUtils documentation built on Jan. 10, 2021, 4:49 p.m.