View source: R/predict.mvgam.R
| predict.mvgam | R Documentation |
Predict from the GAM component of an mvgam model
## S3 method for class 'mvgam'
predict(
object,
newdata,
data_test,
type = "link",
process_error = TRUE,
summary = TRUE,
robust = FALSE,
probs = c(0.025, 0.975),
...
)
object |
|
newdata |
Optional |
data_test |
Deprecated. Still works in place of |
type |
When this has the value |
process_error |
Logical. If |
summary |
Should summary statistics be returned
instead of the raw values? Default is |
robust |
If |
probs |
The percentiles to be computed by the |
... |
Ignored |
Note that for all types of predictions for models that did not include
a trend_formula, uncertainty in the dynamic trend
component can be ignored by setting process_error = FALSE. However,
if a trend_formula was supplied in the model, predictions for this component cannot be
ignored. If process_error = TRUE, trend predictions will ignore autocorrelation
coefficients or GP length scale coefficients, ultimately assuming the process is stationary.
This method is similar to the types of posterior predictions returned from brms models
when using autocorrelated error predictions for newdata.
This function is therefore more suited to posterior simulation from the GAM components
of a mvgam model, while the forecasting functions
plot_mvgam_fc and forecast.mvgam are better suited to generate h-step ahead forecasts
that respect the temporal dynamics of estimated latent trends.
Predicted values on the appropriate scale.
If summary = FALSE and type != "terms",
the output is a matrix of dimension n_draw x n_observations
containing predicted values for each posterior draw in object.
If summary = TRUE and type != "terms", the output is an n_observations x E
matrix. The number of summary statistics E is equal to 2 +
length(probs): The Estimate column contains point estimates (either
mean or median depending on argument robust), while the
Est.Error column contains uncertainty estimates (either standard
deviation or median absolute deviation depending on argument
robust). The remaining columns starting with Q contain
quantile estimates as specified via argument probs.
If type = "terms" and summary = FALSE, the output is a named list
containing a separate slot for each effect, with the effects returned as
matrices of dimension n_draw x 1. If summary = TRUE, the output resembles that
from predict.gam when using the call
predict.gam(object, type = "terms", se.fit = TRUE), where mean contributions
from each effect are returned in matrix form while standard errors (representing
the interval: (max(probs) - min(probs)) / 2) are returned in a separate matrix
# Simulate 4 time series with hierarchical seasonality
# and independent AR1 dynamic processes
set.seed(111)
simdat <- sim_mvgam(seasonality = 'hierarchical',
trend_model = 'AR1',
family = gaussian())
# Fit a model with shared seasonality
mod1 <- mvgam(y ~ s(season, bs = 'cc', k = 6),
data = simdat$data_train,
family = gaussian(),
trend_model = AR(),
noncentred = TRUE,
chains = 2)
# Generate predictions against observed data
preds <- predict(mod1, summary = TRUE)
head(preds)
# Generate predictions against test data
preds <- predict(mod1, newdata = simdat$data_test, summary = TRUE)
head(preds)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.