simulate: Simulate from the posterior distribution of a GAM

Description Usage Arguments Value Author(s) Examples

Description

Simulations from the posterior distribution of a fitted GAM model involve making random draws from a multivariate normal with mean vector equal to the estimated model coefficients and covariance matrix equal to the covariance matrix of the coefficients.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## S3 method for class 'gam'
simulate(object, nsim = 1, seed = NULL, newdata = NULL,
  freq = FALSE, unconditional = FALSE, ...)

## S3 method for class 'gamm'
simulate(object, nsim = 1, seed = NULL, newdata = NULL,
  freq = FALSE, unconditional = FALSE, ...)

## S3 method for class 'scam'
simulate(object, nsim = 1, seed = NULL, newdata = NULL,
  freq = FALSE, parametrized = TRUE, ...)

Arguments

object

a fitted GAM, typically the result of a call to gam() or gamm().

nsim

numeric; the number of posterior simulations to return.

seed

numeric; a random seed for the simulations.

newdata

data frame; new observations at which the posterior draws from the model should be evaluated. If not supplied, the data used to fit the model will be used for newdata, if available in object.

freq

logical; TRUE to return the frequentist covariance matrix of the parameter estimators, FALSE to return the Bayesian posterior covariance matrix of the parameters.

unconditional

logical; if TRUE (and freq == FALSE) then the Bayesian smoothing parameter uncertainty corrected covariance matrix is returned, if available.

...

arguments passed to methods

parametrized

logical; use parametrized coefficients and covariance matrix, which respect the linear inequality constraints of the model.

Value

(Currently) A matrix with nsim columns.

Author(s)

Gavin L. Simpson

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
library("mgcv")
set.seed(2)
dat <- gamSim(1, n = 400, dist = "normal", scale = 2)
m1 <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = dat, method = "REML")

sims <- simulate(m1, nsim = 5, seed = 42)
head(sims)

m2 <- gamm(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = dat, method = "REML")

sims <- simulate(m2, nsim = 5, seed = 42)
head(sims)

gavinsimpson/tsgam documentation built on May 16, 2019, 10:11 p.m.