View source: R/predict.mvgam.R
| predict.mvgam | R Documentation |
Predict from a fitted mvgam model
## S3 method for class 'mvgam'
predict(
object,
newdata,
data_test,
type = "link",
process_error = FALSE,
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 if your model included a latent temporal trend (i.e. if
you used something other than "None" for the trend_model argument), the
predictions returned by this function will ignore autocorrelation
coefficients or GP length scale coefficients by assuming the process is
stationary. This approach is similar to how predictions are computed from
other types of regression models that can include correlated residuals,
ultimately treating the temporal dynamics as random effect nuisance
parameters. The predict function is therefore more suited to
scenario-based posterior simulation from the GAM components of a
mvgam model, while the hindcast / forecast functions
hindcast.mvgam() and forecast.mvgam() are better suited to generate
predictions that respect the temporal dynamics of estimated latent trends
at the actual time points supplied in data and newdata.
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
Nicholas J Clark
hindcast.mvgam(),
forecast.mvgam(),
fitted.mvgam(),
augment.mvgam()
## Not run:
# Simulate 4 time series with hierarchical seasonality
# and independent AR1 dynamic processes
set.seed(123)
simdat <- sim_mvgam(
seasonality = 'hierarchical',
prop_trend = 0.75,
trend_model = AR(),
family = gaussian()
)
# Fit a model with shared seasonality
# and AR(1) dynamics
mod1 <- mvgam(
y ~ s(season, bs = 'cc', k = 6),
data = simdat$data_train,
family = gaussian(),
trend_model = AR(),
noncentred = TRUE,
chains = 2,
silent = 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)
# Use plot_predictions(), which relies on predict()
# to more easily see how the latent AR(1) dynamics are
# being ignored when using predict()
plot_predictions(
mod1,
by = c('time', 'series', 'series'),
points = 0.5
)
# Using the hindcast() function will give a more accurate
# representation of how the AR(1) processes were estimated to give
# accurate predictions to the in-sample training data
hc <- hindcast(mod1)
plot(hc) +
plot(hc, series = 2) +
plot(hc, series = 3)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.