Learn R Programming

odpc (version 2.0.5)

forecast.odpcs: Get Forecast From an odpcs Object

Description

Get forecasts from an odpcs object.

Usage

# S3 method for odpcs
forecast(object, h, Z = NULL, add_residuals = FALSE, …)

Arguments

object

An object of class odpcs, usually the result of odpc.

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 auto.arima.

Value

A matrix that is the h-steps ahead forecast of the original series.

Details

Suppose \(q\) dynamic principal components were fitted to the data, each with \((k_{1}^{i},k_{2}^{i})\) lags, \(i=1,\dots,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{\alpha}}^{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}=\sum\limits_{i=1}^{q}\left( \widehat{\alpha}_{j}% ^{i}+\sum\limits_{v=0}^{k_{2}^{i}}\widehat{b}_{v,j}^{i}\widehat{f}% _{T+h-v|T}^{i}\right) \quad j=1,\dots,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.

See Also

odpc, crit.odpc, cv.odpc, components_odpcs, auto.arima, forecast.Arima

Examples

Run this code
# NOT RUN {
  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
# }

Run the code above in your browser using DataLab