Description Usage Arguments Value Examples
View source: R/helper_functions.R
Compute the one-step forecasting estimate under a dynamic function-on-scalars regression model.
1 | forecast_dfosr(X_Tp1 = NULL, post_sims, factor_model = "AR")
|
X_Tp1 |
the |
post_sims |
a named list of posterior draws for the following parameters:
|
factor_model |
model for the (dynamic) factors; must be one of
|
Yfore
, the m x 1
curve forecasting estimate
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | ## Not run:
# Simulate some data:
sim_data = simulate_dfosr(T = 200, m = 50, p_0 = 2, p_1 = 2)
Y = sim_data$Y; X = sim_data$X; tau = sim_data$tau
T = nrow(Y); m = ncol(Y); p = ncol(X) # Dimensions
# Delete and store the last time point (for forecasting):
Y_Tp1 = Y[T,]; X_Tp1 = X[T,]
Y = Y[-T,]; X = X[-T,]; T = nrow(Y);
# Run the MCMC w/ K = 6:
out = dfosr(Y = Y, tau = tau, X = X, K = 6,
factor_model = 'AR',
use_dynamic_reg = TRUE,
mcmc_params = list("beta", "fk", "alpha", "mu_k", "ar_phi"))
# Compute one-step forecasts:
Yfore = forecast_dfosr(X_Tp1 = X_Tp1,
post_sims = out,
factor_model = "AR")
# Plot the results:
plot(tau, Yfore, ylim = range(Yfore, Y_Tp1, Y[T,], na.rm=TRUE),
main = 'One-Step Forecast',
lwd = 8, col = "cyan", type = 'l')
# Add the most recent observed curve:
lines(tau, Y[T,], type='p', pch = 2)
# Add the realized curve:
lines(tau, Y_Tp1, type='p')
# And the true curve:
lines(tau, sim_data$Y_true[T+1,], lwd=8, col='black', lty=6)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.