simulate.gam | R Documentation |
Simulations from the posterior distribution of a fitted GAM model involve computing predicted values for the observation data for which simulated data are required, then generating random draws from the probability distribution used when fitting the model.
## S3 method for class 'gam'
simulate(
object,
nsim = 1,
seed = NULL,
data = newdata,
weights = NULL,
...,
newdata = NULL
)
## S3 method for class 'gamm'
simulate(
object,
nsim = 1,
seed = NULL,
data = newdata,
weights = NULL,
...,
newdata = NULL
)
## S3 method for class 'scam'
simulate(
object,
nsim = 1,
seed = NULL,
data = newdata,
weights = NULL,
...,
newdata = NULL
)
object |
a fitted GAM, typically the result of a call to mgcv::gam'
or |
nsim |
numeric; the number of posterior simulations to return. |
seed |
numeric; a random seed for the simulations. |
data |
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 |
weights |
numeric; a vector of prior weights. If |
... |
arguments passed to methods. |
newdata |
Deprecated. Use |
For simulate.gam()
to function, the family
component of the fitted
model must contain, or be updateable to contain, the required random
number generator. See mgcv::fix.family.rd()
.
(Currently) A data frame with nsim
columns.
Gavin L. Simpson
load_mgcv()
dat <- data_sim("eg1", n = 400, dist = "normal", scale = 2, seed = 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.