forecast.odpcs | R Documentation |
Get forecasts from an odpcs
object.
## S3 method for class 'odpcs' forecast(object, h, Z = NULL, add_residuals = FALSE, ...)
object |
An object of class |
h |
Integer. Number of periods for forecasting. |
Z |
Original data. Only used if add_residuals = TRUE. |
add_residuals |
Logical. Should the forecasts of the reconstruction residuals be added to the final forecast? Default is FALSE. |
... |
Additional arguments to be passed to |
Suppose q dynamic principal components were fitted to the data, each with
(k_{1}^{i},k_{2}^{i}) lags, i=1,…,q. Let \widehat{\mathbf{f}}_{T}%
^{i} be the vector with the estimated values for the i-th dynamic principal
component and \widehat{\mathbf{B}}^{i}, \widehat{\boldsymbol{α}}^{i}
be the corresponding loadings and intercepts.
Forecasts of the series are built by first fitting a SARIMA model to the components
using auto.arima
and getting their forecasts using forecast.Arima
.
Let \widehat{f}_{T+h|T}^{i} for h>0 be the forecast of f_{T+h}^{i}
with information until time T. Then the h-steps ahead forecast of
\mathbf{z}_{T} is obtained as
\widehat{z}_{T+h|T,j}=∑\limits_{i=1}^{q}≤ft( \widehat{α}_{j}% ^{i}+∑\limits_{v=0}^{k_{2}^{i}}\widehat{b}_{v,j}^{i}\widehat{f}% _{T+h-v|T}^{i}\right) \quad j=1,…,m.
If add_residuals = TRUE, univariate SARIMA models are fitted to the residuals of the reconstruction, and their forecasts are added to the forecasts described above.
A matrix that is the h-steps ahead forecast of the original series.
odpc
, crit.odpc
, cv.odpc
, components_odpcs
, auto.arima
, forecast.Arima
T <- 201 #length of series m <- 10 #number of series set.seed(1234) f <- matrix(0, 2 * T + 1, 1) v <- rnorm(2 * T + 1) f[1] <- rnorm(1) theta <- 0.7 for (t in 2:(2 * T)){ f[t] <- theta * f[t - 1] + v[t] } f <- f[T:(2 * T)] x <- matrix(0, T, m) u <- matrix(rnorm(T * m), T, m) for (i in 1:m) { x[, i] <- sin(2 * pi * (i/m)) * f[1:T] + cos(2 * pi * (i/m)) * f[2:(T + 1)] + u[, i] } fit <- odpc(x[1:(T - 1), ], ks = c(1)) forecasts <- forecast.odpcs(fit, h = 1) mse <- mean((x[T, ] - forecasts)**2) mse
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.