Last data update: 2014.03.03

R: All posible combinations forecast averaging
Forecast_comb_allR Documentation

All posible combinations forecast averaging

Description

Combine different forecasts using complete subset regressions. Apart from the simple averaging, weights based on information criteria (AIC, corrected AIC, Hannan Quinn and BIC) or based on the Mallow criterion are also available.

Usage

Forecast_comb_all(obs, fhat, fhat_new = NULL)

Arguments

obs

Observed series.

fhat

fhat Matrix of available forecasts.

fhat_new

Matrix of available forecasts as a test set. Optional, default to NULL.

Details

OLS forecast combination is based on

obs_t = const + ∑_{i = 1}^p w_{i} widehat{obs}_{it} + e_t,

where obs is the observed values and widehat{obs} is the forecast, one out of the p forecasts available.

The function computes the complete subset regressions. So a matrix of forecasts based on all possible subsets of fhat is returned.

Those forecasts can later be cross-sectionally averaged to create a single combined forecast.

Additional weight-vectors which are based on different information criteria are also returned. This is in case the user would like to perform the frequensit version of forecast averaging or based on the Mallows criterion (see references for more details).

Although the function is geared towards forecast averaging, it can be used in any other application as a generic complete subset regression.

Value

Forecast_comb_all returns a list that contains the following objects:

pred

Vector of fitted values if fhat_new is not NULL or the vector of predictions if fhat_new is provided.

full_model_crit

List. The values of information criteria computed based on a full model, the one which includes all available forecasts.

aic

A vector of weights for all possible forecast combinations based on the Akaike's information criterion.

aicc

A vector of weights for all possible forecast combinations based on the corrected Akaike's information criterion.

bic

A vector of weights for all possible forecast combinations based on the Bayesian's information criterion.

hq

A vector of weights for all possible forecast combinations based on the Hannan Quinn's information criterion.

mal

A vector of weights for all possible forecast combinations based on the Mallow's information criterion.

Author(s)

Eran Raviv (eeraviv@gmail.com)

References

Hansen, B. (2008) Least-squares forecast averaging. Journal of Econometrics, Vol. 146, No. 2. , pp. 342-350

Kapetanios, G., Labhard V., Price, S. Forecasting Using Bayesian and Information-Theoretic Model Averaging. Journal of Business & Economic Statistics, Vol. 26, Iss. 1, 2008

Koenker R. (2005) Quantile Regression. Cambridge University Press.

Graham, E., Garganob, A., Timmermann, A. (2013) Complete subset regressions. Journal of Econometrics. Vol 177, 2, pp. 357-373.

Examples

library(MASS)
tt <- NROW(Boston)/2
TT <- NROW(Boston)
y <- Boston[1:tt, 14] # dependent variable is columns number 14
 # Create two sets of explanatory variables
 x1 <- Boston[1:tt, 1:6] # The first 6 explanatories
 x2 <- Boston[1:tt, 7:13]# The last 6 explanatories
# create two forecasts based on the two different x1 and x2
 coef1 <- lm(y ~ as.matrix(x1))$coef
 coef2 <- lm(y ~ as.matrix(x2))$coef
 f1 <- t(coef1 %*%  t(cbind(rep(1,tt), Boston[(tt+1):TT, 1:6] )))
 f2 <- t(coef2 %*% t(cbind(rep(1,tt), Boston[(tt+1):TT, 7:13] )))
 ff <- cbind(f1,f2)
 comb_all <- Forecast_comb_all(obs = Boston[(tt+1):TT, 14], fhat = ff)
 # To get the combined forecasts from the all subset regression:
 Combined_forecast <- apply(comb_all$pred, 1, mean)
# To get the combined forecasts based on aic criteria for example:
Combined_forecast_aic <- t(comb_all$aic %*% t(comb_all$pred))

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(ForecastCombinations)
Loading required package: quantreg
Loading required package: SparseM

Attaching package: 'SparseM'

The following object is masked from 'package:base':

    backsolve

Loading required package: quadprog
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/ForecastCombinations/Forecast_comb_all.Rd_%03d_medium.png", width=480, height=480)
> ### Name: Forecast_comb_all
> ### Title: All posible combinations forecast averaging
> ### Aliases: Forecast_comb_all
> 
> ### ** Examples
> 
> library(MASS)
> tt <- NROW(Boston)/2
> TT <- NROW(Boston)
> y <- Boston[1:tt, 14] # dependent variable is columns number 14
>  # Create two sets of explanatory variables
>  x1 <- Boston[1:tt, 1:6] # The first 6 explanatories
>  x2 <- Boston[1:tt, 7:13]# The last 6 explanatories
> # create two forecasts based on the two different x1 and x2
>  coef1 <- lm(y ~ as.matrix(x1))$coef
>  coef2 <- lm(y ~ as.matrix(x2))$coef
>  f1 <- t(coef1 %*%  t(cbind(rep(1,tt), Boston[(tt+1):TT, 1:6] )))
>  f2 <- t(coef2 %*% t(cbind(rep(1,tt), Boston[(tt+1):TT, 7:13] )))
>  ff <- cbind(f1,f2)
>  comb_all <- Forecast_comb_all(obs = Boston[(tt+1):TT, 14], fhat = ff)
   |                                                                               |                                                                      |   0%   |                                                                               |======================================================================| 100%>  # To get the combined forecasts from the all subset regression:
>  Combined_forecast <- apply(comb_all$pred, 1, mean)
> # To get the combined forecasts based on aic criteria for example:
> Combined_forecast_aic <- t(comb_all$aic %*% t(comb_all$pred))
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>