Extract or compute hindcasts and forecasts for a fitted mvgam
object
Source: R/forecast.mvgam.R
forecast.mvgam.Rd
Extract or compute hindcasts and forecasts for a fitted mvgam
object
Usage
forecast(object, ...)
# S3 method for mvgam
forecast(object, newdata, data_test, n_cores = 1, type = "response", ...)
Arguments
- object
list
object returned frommvgam
. Seemvgam()
- ...
Ignored
- newdata
Optional
dataframe
orlist
of test data containing the same variables that were included in the originaldata
used to fit the model. If included, the covariate information innewdata
will be used to generate forecasts from the fitted model equations. If this samenewdata
was originally included in the call tomvgam
, then forecasts have already been produced by the generative model and these will simply be extracted and plotted. However if nonewdata
was supplied to the original model call, an assumption is made that thenewdata
supplied here comes sequentially after the data supplied in the original model (i.e. we assume there is no time gap between the last observation of series 1 in the original data and the first observation for series 1 innewdata
)- data_test
Deprecated. Still works in place of
newdata
but users are recommended to usenewdata
instead for more seamless integration intoR
workflows- n_cores
Deprecated. Parallel processing is no longer supported
- type
When this has the value
link
(default) the linear predictor is calculated on the link scale. Ifexpected
is used, predictions reflect the expectation of the response (the mean) but ignore uncertainty in the observation process. Whenresponse
is used, the predictions take uncertainty in the observation process into account to return predictions on the outcome scale. Whenvariance
is used, the variance of the response with respect to the mean (mean-variance relationship) is returned. Whentype = "terms"
, each component of the linear predictor is returned separately in the form of alist
(possibly with standard errors, ifsummary = TRUE
): this includes parametric model components, followed by each smooth component, but excludes any offset and any intercept. Two special cases are also allowed: typelatent_N
will return the estimated latent abundances from an N-mixture distribution, while typedetection
will return the estimated detection probability from an N-mixture distribution
Value
An object of class mvgam_forecast
containing hindcast and forecast distributions.
See mvgam_forecast-class
for details.
Details
Posterior predictions are drawn from the fitted mvgam
and used to simulate a forecast distribution
Examples
# \donttest{
simdat <- sim_mvgam(n_series = 3, trend_model = AR())
mod <- mvgam(y ~ s(season, bs = 'cc', k = 6),
trend_model = AR(),
noncentred = TRUE,
data = simdat$data_train,
chains = 2,
silent = 2)
#> Error in get_mvgam_priors(formula = formula, trend_formula = trend_formula, data = data, family = family, use_lv = use_lv, n_lv = n_lv, use_stan = TRUE, trend_model = trend_model, trend_map = trend_map, drift = drift, knots = knots): object 'silent' not found
# Hindcasts on response scale
hc <- hindcast(mod)
#> Error in hindcast(mod): object 'mod' not found
str(hc)
#> Error in str(hc): object 'hc' not found
plot(hc, series = 1)
#> Error in plot(hc, series = 1): object 'hc' not found
plot(hc, series = 2)
#> Error in plot(hc, series = 2): object 'hc' not found
plot(hc, series = 3)
#> Error in plot(hc, series = 3): object 'hc' not found
# Forecasts on response scale
fc <- forecast(mod, newdata = simdat$data_test)
#> Error in forecast(mod, newdata = simdat$data_test): object 'mod' not found
str(fc)
#> Error in str(fc): object 'fc' not found
plot(fc, series = 1)
#> Error in plot(fc, series = 1): object 'fc' not found
plot(fc, series = 2)
#> Error in plot(fc, series = 2): object 'fc' not found
plot(fc, series = 3)
#> Error in plot(fc, series = 3): object 'fc' not found
# Forecasts as expectations
fc <- forecast(mod, newdata = simdat$data_test, type = 'expected')
#> Error in forecast(mod, newdata = simdat$data_test, type = "expected"): object 'mod' not found
plot(fc, series = 1)
#> Error in plot(fc, series = 1): object 'fc' not found
plot(fc, series = 2)
#> Error in plot(fc, series = 2): object 'fc' not found
plot(fc, series = 3)
#> Error in plot(fc, series = 3): object 'fc' not found
# Dynamic trend extrapolations
fc <- forecast(mod, newdata = simdat$data_test, type = 'trend')
#> Error in forecast(mod, newdata = simdat$data_test, type = "trend"): object 'mod' not found
plot(fc, series = 1)
#> Error in plot(fc, series = 1): object 'fc' not found
plot(fc, series = 2)
#> Error in plot(fc, series = 2): object 'fc' not found
plot(fc, series = 3)
#> Error in plot(fc, series = 3): object 'fc' not found
# }