smooth.construct.spde.smooth.spec | R Documentation |
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).
## S3 method for class 'spde.smooth.spec'
smooth.construct(object, data, knots)
## S3 method for class 'spde.smooth'
Predict.matrix(object, data)
object |
a smooth specification object, usually generated by a term |
data |
a list containing just the data (including any |
knots |
a list containing any knots supplied for basis setup — in same order and with same names as |
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.
The INLA
package is required to use this function see the R-INLA website for details on installation.
David L Miller
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
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.