For internal use: This function is primarily used internally by
forecast.ffc_gam(). Most users should call forecast() directly on their
ffc_gam object instead of using this function, which requires properly
structured coefficient data and has specific format requirements.
Usage
# S3 method for class 'fts_ts'
forecast(
object,
model = "ARIMA",
h = get_stan_param("h", "forecast"),
n_samples = 25,
stationary = FALSE,
...
)Arguments
- object
An object of class
fts_tscontaining time-varying basis function coefficients extracted from anffc_gamobject usingfts_coefs()- model
A
characterstring representing a valid univariate model definition from the fable package, ensemble methods, or one of the built-in Bayesian dynamic factor models. Note that if a fable model is used, the chosen method must have an associatedgenerate()method in order to simulate forecast realisations. Valid models currently include:'ENS','ARDF','GPDF', 'VARDF,'ETS','ARIMA','AR','RW','NAIVE', and'NNETAR'. The'ENS'option combines ETS and Random Walk forecasts with equal weights, hedging bets between exponential smoothing and random walk assumptions to provide more robust predictions when model uncertainty is high.- h
A positive
integerspecifying the length of the forecast horizon- n_samples
A positive
integerspecifying the number of forecast realisation paths to simulate from the fitted forecastmodel- stationary
If
TRUE, the fitted time series models are constrained to be stationary. Default isFALSE. This option only works whenmodel == 'ARIMA'- ...
Other arguments to pass to the Stan dynamic factor models (i.e. the (V)AR order
lag = ...or the number of factorsK = ...)
Value
A tsibble object containing the forecast prediction (.sim) for each
replicate realisation (.rep) at each timestep in the forecast horizon h
Details
Basis function coefficient time series will be used as input
to the specified model to train a forecasting model that will then be
extrapolated h timesteps into the future. A total of times forecast realisations
will be returned for each basis coefficient
Examples
# Extract coefficients and generate forecasts
mod <- ffc_gam(
deaths ~ offset(log(population)) + sex +
fts(age, k = 8, bs = "cr", time_k = 10),
time = "year",
data = qld_mortality,
family = poisson(),
engine = "bam"
)
coefs <- fts_coefs(mod, summary = FALSE, n_samples = 5)
# Generate ETS forecasts
forecast(coefs, model = "ETS", h = 3)
#> # A tsibble: 2,625 x 6 [1Y]
#> # Key: .basis, .realisation, .model, .rep [875]
#> .basis .realisation .model year .rep .sim
#> <chr> <int> <chr> <dbl> <chr> <dbl>
#> 1 fts_bs_s_age__1 1 ETS 2021 1 -1.93
#> 2 fts_bs_s_age__1 1 ETS 2022 1 -1.90
#> 3 fts_bs_s_age__1 1 ETS 2023 1 -1.86
#> 4 fts_bs_s_age__1 1 ETS 2021 10 -1.93
#> 5 fts_bs_s_age__1 1 ETS 2022 10 -1.88
#> 6 fts_bs_s_age__1 1 ETS 2023 10 -1.83
#> 7 fts_bs_s_age__1 1 ETS 2021 11 -1.92
#> 8 fts_bs_s_age__1 1 ETS 2022 11 -1.88
#> 9 fts_bs_s_age__1 1 ETS 2023 11 -1.84
#> 10 fts_bs_s_age__1 1 ETS 2021 12 -1.93
#> # ℹ 2,615 more rows