predicted_samples | R Documentation |
Predicted values of the response (new response data) are drawn from the
fitted model, created via simulate()
(e.g. simulate.gam()
) and returned
in a tidy, long, format. These predicted values do not include the
uncertainty in the estimated model; they are simply draws from the
conditional distribution of the response.
predicted_samples(model, ...)
## S3 method for class 'gam'
predicted_samples(
model,
n = 1,
data = newdata,
seed = NULL,
weights = NULL,
...,
newdata = NULL
)
model |
a fitted model of the supported types |
... |
arguments passed to other methods. For |
n |
numeric; the number of posterior samples to return. |
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 |
seed |
numeric; a random seed for the simulations. |
weights |
numeric; a vector of prior weights. If |
newdata |
Deprecated: use |
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
.
Gavin L. Simpson
load_mgcv()
dat <- data_sim("eg1", n = 1000, dist = "normal", scale = 2, seed = 2)
m <- gam(y ~ s(x0) + s(x1) + s(x2) + s(x3), data = dat, method = "REML")
predicted_samples(m, n = 5, seed = 42)
## Can pass arguments to predict.gam()
newd <- data.frame(
x0 = runif(10), x1 = runif(10), x2 = runif(10),
x3 = runif(10)
)
## Exclude s(x2)
predicted_samples(m, n = 5, newd, exclude = "s(x2)", seed = 25)
## Exclude s(x1)
predicted_samples(m, n = 5, newd, exclude = "s(x1)", seed = 25)
## Select which terms --- result should be the same as previous
## but note that we have to include any parametric terms, including the
## constant term
predicted_samples(m,
n = 5, newd, seed = 25,
terms = c("Intercept", "s(x0)", "s(x2)", "s(x3)")
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.