View source: R/analysis_helpers.R
| estimate_forecast_variance | R Documentation |
Estimates forecast variance from historical forecast errors relative to
the benchmark using a rolling window. Used to approximate the time-varying predictive
standard deviation for each competing model forecast, required by compute_klic,
compute_zp, and compute_kupiec.
estimate_forecast_variance(
forecast_matrix,
benchmark_col = ncol(forecast_matrix),
window_size = 20
)
forecast_matrix |
|
benchmark_col |
Index or name of the benchmark column. Defaults to the last column. |
window_size |
|
For each competing forecast k and period t, the forecast error is defined
as e_{t,k} = \text{benchmark}_t - \hat{y}_{t,k}. The variance of these errors
is estimated over a rolling window:
If t < window_size: variance is computed over observations
1:t (expanding window).
If t >= window_size: variance is computed over observations
max(1, t - window_size):t (rolling window of size window_size).
For t = 1 the variance of a single observation is undefined (NA).
Estimated variances that are NA, zero, or negative are replaced by
1e-6 to ensure numerical stability in downstream computations.
The benchmark column in the returned matrix is set to zero throughout.
matrix of dimension P x K_total containing
estimated variances. Columns correspond to the same forecasts as
forecast_matrix; the benchmark column contains zeros.
compute_klic, compute_zp,
compute_kupiec
data(metals)
forecast_variance <- estimate_forecast_variance(metals, benchmark_col = 15,
window_size = 20)
head(forecast_variance)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.