Draw samples from the posterior distribution of an estimated model
posterior_samples(model, ...)# S3 method for gam
posterior_samples(
model,
n,
data = newdata,
seed = NULL,
method = c("gaussian", "mh", "inla", "user"),
n_cores = 1,
burnin = 1000,
thin = 1,
t_df = 40,
rw_scale = 0.25,
freq = FALSE,
unconditional = FALSE,
weights = NULL,
draws = NULL,
...,
newdata = NULL,
ncores = NULL
)
A tibble (data frame) with 3 columns containing the posterior predicted values in long format. The columns are
row
(integer) the row of data
that each posterior draw relates to,
draw
(integer) an index, in range 1:n
, indicating which draw each row
relates to,
response
(numeric) the predicted response for the indicated row of
data
.
a fitted model of the supported types
arguments passed to other methods. For fitted_samples()
, these
are passed on to predict.gam()
. For posterior_samples()
these are
passed on to fitted_samples()
. For predicted_samples()
these are
passed on to the relevant simulate()
method.
numeric; the number of posterior samples to return.
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 data
, if available in model
.
numeric; a random seed for the simulations.
character; which method should be used to draw samples from
the posterior distribution. "gaussian"
uses a Gaussian (Laplace)
approximation to the posterior. "mh"
uses a Metropolis Hastings sampler
that alternates t proposals with proposals based on a shrunken version of
the posterior covariance matrix. "inla"
uses a variant of Integrated
Nested Laplace Approximation due to Wood (2019), (currently not
implemented). "user"
allows for user-supplied posterior draws
(currently not implemented).
number of cores for generating random variables from a
multivariate normal distribution. Passed to mvnfast::rmvn()
.
Parallelization will take place only if OpenMP is supported (but appears
to work on Windows with current R
).
numeric; number of samples to discard as the burnin draws.
Only used with method = "mh"
.
numeric; the number of samples to skip when taking n
draws.
Results in thin * n
draws from the posterior being taken. Only used with
method = "mh"
.
numeric; degrees of freedome for t distribution proposals. Only
used with method = "mh"
.
numeric; Factor by which to scale posterior covariance
matrix when generating random walk proposals. Negative or non finite to
skip the random walk step. Only used with method = "mh"
.
logical; TRUE
to use the frequentist covariance matrix of
the parameter estimators, FALSE
to use the Bayesian posterior
covariance matrix of the parameters.
logical; if TRUE
(and freq == FALSE
) then the
Bayesian smoothing parameter uncertainty corrected covariance matrix is
used, if available.
numeric; a vector of prior weights. If data
is null
then defaults to object[["prior.weights"]]
, otherwise a vector of ones.
matrix; user supplied posterior draws to be used when
method = "user"
.
Deprecated: use data
instead.
Deprecated; use n_cores
instead. The number of cores for
generating random variables from a multivariate normal distribution.
Passed to mvnfast::rmvn()
. Parallelization will take place only if
OpenMP is supported (but appears to work on Windows with current R
).
Gavin L. Simpson
Wood, S.N., (2020). Simplified integrated nested Laplace approximation. Biometrika 107, 223--230. tools:::Rd_expr_doi("10.1093/biomet/asz044")