A function for forecasting of generalized autoregressive score (GAS) models of Creal et al. (2013) and Harvey (2013).
Method "mean_path"
filters time-varying parameters based on zero score and then generates mean of time series.
Method "simulated_paths"
repeatedly simulates time series, simultaneously filters time-varying parameters, and then estimates mean, standard deviation, and quantiles (see Blasques et al., 2016).
Instead of supplying arguments about the model, the function can be applied to the gas
object obtained by the gas()
function.
gas_forecast(gas_object = NULL, method = "mean_path", t_ahead = 1L,
x_ahead = NULL, rep_ahead = 1000L, quant = c(0.025, 0.975), y = NULL,
x = NULL, distr = NULL, param = NULL, scaling = "unit",
regress = "joint", p = 1L, q = 1L, par_static = NULL,
par_link = NULL, par_init = NULL, coef_est = NULL)
A list
of S3 class gas_forecast
with components:
The time series.
The exogenous variables.
The out-of-sample exogenous variables.
The conditional distribution.
The parametrization of the conditional distribution.
The scaling function.
The specification of the regression and dynamic equation.
The length of the time series.
The length of the out-of-sample time series.
The dimension of the model.
The number of exogenous variables.
The score order.
The autoregressive order.
The static parameters.
The parameters with the logarithmic/logistic links.
The initial values of the time-varying parameters.
The estimated coefficients.
The method used for forecasting.
The mean of the forecasted time series.
The standard deviation of the forecasted time series. Only for method = "simulated_paths"
.
The quantiles of the forecasted time series. Only for method = "simulated_paths"
.
The mean of the forecasted time-varying parameters.
The standard deviation of the forecasted time-varying parameters. Only for method = "simulated_paths"
.
The quantiles of the forecasted time-varying parameters. Only for method = "simulated_paths"
.
The mean of the forecasted scores.
The standard deviation of the forecasted scores. Only for method = "simulated_paths"
.
The quantiles of the forecasted scores. Only for method = "simulated_paths"
.
An optional GAS estimate, i.e. a list of S3 class gas
returned by function gas()
.
A method used for forecasting. Supported methods are "mean_path"
and "simulated_paths"
.
A number of observations to forecast.
Out-of-sample exogenous variables. For a single variable common for all time-varying parameters, a numeric vector. For multiple variables common for all time-varying parameters, a numeric matrix with observations in rows. For individual variables for each time-varying parameter, a list of numeric vectors or matrices in the above form. The number of observation must be equal to t_ahead
.
A number of simulation repetitions for method = "simulated_paths"
.
A numeric vector of probabilities determining quantiles for method = "simulated_paths"
.
A time series. For univariate time series, a numeric vector or a matrix with a single column. For multivariate times series, a numeric matrix with observations in rows.
Optional exogenous variables. For a single variable common for all time-varying parameters, a numeric vector. For multiple variables common for all time-varying parameters, a numeric matrix with observations in rows. For individual variables for each time-varying parameter, a list of numeric vectors or matrices in the above form. The number of observation must be equal to the number of observations of y
.
A conditional distribution. See distr()
for available distributions.
A parametrization of the conditional distribution. If NULL
, default parametrization is used. See distr()
for available parametrizations.
A scaling function for the score. The supported scaling functions are the unit scaling (scaling = "unit"
), the inverse of the Fisher information matrix scaling (scaling = "fisher_inv"
), and the inverse square root of the Fisher information matrix scaling (scaling = "fisher_inv_sqrt"
). The latter two scalings use the Fisher information for the time-varying parameters only. For the full Fisher information matrix for both time-varying and static parameters, there are the "full_fisher_inv"
and "full_fisher_inv_sqrt"
scalings. For the individual Fisher information for each parameter, there are the "diag_fisher_inv"
and "diag_fisher_inv_sqrt"
scalings. Note that when the parametrization is orthogonal (see distr()
), there are no differences between these scaling variants.
A specification of the regression and dynamic equation with regard to exogenous variables. The supported specifications are exogenous variables and dynamics within the same equation (regress = "joint"
) and separate equations for exogenous variables and dynamics in the fashion of regression models with dynamic errors (regress = "sep"
). In a stationary model without exogenous variables, the two specifications are equivalent, although with differently parametrized intercept.
A score order. For order common for all parameters, a numeric vector of length 1. For individual order for each parameter, a numeric vector of length equal to the number of parameters. Defaults to 1L
.
An autoregressive order. For order common for all parameters, a numeric vector of length 1. For individual order for each parameter, a numeric vector of length equal to the number of parameters. Defaults to 1L
.
An optional logical vector indicating static parameters. Overrides x
, p
, and q
.
An optional logical vector indicating whether the logarithmic/logistic link should be applied to restricted parameters in order to obtain unrestricted values. Defaults to applying the logarithmic/logistic link for time-varying parameters and keeping the original link for constant parameters.
An optional numeric vector of initial values of time-varying parameters. For NA
values or when NULL
, set initial values to unconditional values of time-varying parameters. For example, in the case of GAS(1,1) model with regress = "joint"
, to omega / (1 - phi1)
. Not to be confused with starting values for the optimization coef_start
.
A numeric vector of estimated coefficients.
Blasques, F., Koopman, S. J., Łasak, K., and Lucas, A. (2016). In-Sample Confidence Bands and Out-of-Sample Forecast Bands for Time-Varying Parameters in Observation-Driven Models. International Journal of Forecasting, 32(3), 875–887. tools:::Rd_expr_doi("10.1016/j.ijforecast.2015.11.018").
Creal, D., Koopman, S. J., and Lucas, A. (2013). Generalized Autoregressive Score Models with Applications. Journal of Applied Econometrics, 28(5), 777–795. tools:::Rd_expr_doi("10.1002/jae.1279").
Harvey, A. C. (2013). Dynamic Models for Volatility and Heavy Tails: With Applications to Financial and Economic Time Series. Cambridge University Press. tools:::Rd_expr_doi("10.1017/cbo9781139540933").
gas()
# Load the Daily Toilet Paper Sales dataset
data("toilet_paper_sales")
y <- toilet_paper_sales$quantity
x <- as.matrix(toilet_paper_sales[3:9])
# Estimate GAS model based on the negative binomial distribution
est_negbin <- gas(y = y, x = x, distr = "negbin", regress = "sep")
est_negbin
# Forecast the model by the "mean_paths" method
x_ahead <- cbind(kronecker(matrix(1, 53, 1), diag(7)), 1)[3:367, -1]
fcst_negbin <- gas_forecast(est_negbin, t_ahead = 365, x_ahead = x_ahead)
fcst_negbin
# Plot the forecasted expected value
plot(fcst_negbin)
Run the code above in your browser using DataLab