1 - Comb OLS

## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
data(electricity)

print(head(electricity))
##             arima      ets     nnet  dampedt     dotm Actual
## Jan 2007 36980.16 35692.31 37047.91 35540.66 36044.28  36420
## Feb 2007 33587.29 33708.15 34523.56 33962.34 33821.69  32901
## Mar 2007 36005.55 37366.20 36049.72 37317.91 37119.29  34595
## Apr 2007 30925.25 30550.24 30721.91 30356.77 30350.95  29665
## May 2007 30394.78 29167.64 29241.89 28766.40 28910.84  30154
## Jun 2007 28938.14 29004.18 29211.91 29006.25 28229.28  28607
(forecasting_methods <- colnames(electricity)[1:5])
## [1] "arima"   "ets"     "nnet"    "dampedt" "dotm"
train_obs <- electricity[1:84, "Actual"]
train_pred <- electricity[1:84, forecasting_methods]
test_obs <- electricity[85:123, "Actual"]
test_pred <- electricity[85:123, forecasting_methods]
data <- ForecastComb::foreccomb(train_obs, train_pred, test_obs, test_pred)
start <- proc.time()[3]
obj <- ahead::comb_OLS(data)
## Registered S3 methods overwritten by 'ahead':
##   method                      from        
##   plot.foreccomb_res          ForecastComb
##   predict.foreccomb_res       ForecastComb
##   print.foreccomb_res_summary ForecastComb
##   summary.foreccomb_res       ForecastComb
print(proc.time()[3] - start)
## elapsed 
##    0.07
print(class(obj))
## [1] "foreccomb_res" "comb_OLS"
print(obj$Accuracy_Test)
##                 ME     RMSE      MAE        MPE     MAPE
## Test set -40.07742 671.5214 536.0331 -0.2470512 1.841961
print(obj$Weights)
## [1]  0.02152869 -0.20646266  0.20992792 -1.04349858  1.97991049
# check
print(mean(predict(obj, test_pred) - test_obs))
## [1] 40.07742
plot(obj)

2 - Comb Ridge

start <- proc.time()[3]
obj <- ahead::comb_Ridge(data)
print(proc.time()[3] - start)
## elapsed 
##   0.007
print(obj$Weights)
## [1]    95.81502  -582.80574   685.98452 -2745.54330  5530.43579
print(class(obj))
## [1] "foreccomb_res" "comb_Ridge"
print(obj$Accuracy_Test)
##                ME     RMSE      MAE       MPE     MAPE
## Test set -46.9685 672.4224 532.7352 -0.263655 1.827328
# check 
print(mean(predict(obj, test_pred) - test_obs))
## [1] 46.9685
plot(obj)

3 - Comb GLMNET

start <- proc.time()[3]
obj <- ahead::comb_GLMNET(data)
print(proc.time()[3] - start)
## elapsed 
##   0.286
print(class(obj))
## [1] "foreccomb_res" "comb_GLMNET"
print(obj$Weights)
## [1] 0.02511533 0.00000000 0.26187911 0.00000000 0.66946352
print(obj$Accuracy_Test)
##                ME     RMSE      MAE       MPE     MAPE
## Test set 96.97216 707.1726 531.9225 0.3429199 1.796003
print(mean(predict(obj, test_pred) - test_obs))
## [1] 96.97216
plot(obj)