add_fitted_samples {gratia} | R Documentation |
Add posterior draws from a model to a data object
Description
Adds draws from the posterior distribution of model
to the data object
using one of fitted_samples()
, predicted_samples()
, or
posterior_samples()
.
Usage
add_fitted_samples(object, model, n = 1, seed = NULL, ...)
add_predicted_samples(object, model, n = 1, seed = NULL, ...)
add_posterior_samples(object, model, n = 1, seed = NULL, ...)
add_smooth_samples(object, model, n = 1, seed = NULL, select = NULL, ...)
Arguments
object |
a data frame or tibble to which the posterior draws will be added. |
model |
a fitted GAM (or GAM-like) object for which a posterior draw method exists. |
n |
integer; the number of posterior draws to add. |
seed |
numeric; a value to seed the random number generator. |
... |
arguments are passed to the posterior draw function, currently one
of |
select |
character; select which smooth's posterior to draw from. The
default, |
Examples
load_mgcv()
df <- data_sim("eg1", n = 400, seed = 42)
m <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = df, method = "REML")
# add fitted samples (posterior draws of the expected value of the response)
# note that there are 800 rows in the output: 400 data by `n = 2` samples.
df |>
add_fitted_samples(m, n = 2, seed = 84)
# add posterior draws from smooth s(x2)
df |>
add_smooth_samples(m, n = 2, seed = 2, select= "s(x2)")