library(Rcmdr)
## Loading required package: splines
## Loading required package: RcmdrMisc
## Loading required package: car
## Loading required package: sandwich
## The Commander GUI is launched only in interactive sessions
library(RcmdrPlugin.epack)
## Loading required package: TeachingDemos
## Loading required package: tseries
## Loading required package: abind
## Loading required package: MASS
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## 
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## Loading required package: forecast
## Loading required package: timeDate
## This is forecast 6.2
library(forecast)
data("AirPassengers")
a=ets(AirPassengers)
a
## ETS(M,A,M) 
## 
## Call:
##  ets(y = AirPassengers) 
## 
##   Smoothing parameters:
##     alpha = 0.5901 
##     beta  = 0.0058 
##     gamma = 1e-04 
## 
##   Initial states:
##     l = 126.9791 
##     b = 1.6483 
##     s=0.8865 0.7928 0.9226 1.0582 1.2186 1.2371
##            1.1069 0.9818 0.985 1.0149 0.8946 0.901
## 
##   sigma:  0.0367
## 
##      AIC     AICc      BIC 
## 1391.174 1395.457 1438.691
predict(a,10)
##          Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## Jan 1961       444.9979 424.0692 465.9267 412.9901 477.0057
## Feb 1961       444.1187 419.8324 468.4049 406.9760 481.2613
## Mar 1961       506.4125 475.2920 537.5330 458.8178 554.0072
## Apr 1961       493.9890 460.5937 527.3844 442.9153 545.0628
## May 1961       494.8520 458.5835 531.1205 439.3841 550.3198
## Jun 1961       560.6983 516.6174 604.7792 493.2823 628.1143
## Jul 1961       629.8161 577.1310 682.5012 549.2412 710.3910
## Aug 1961       623.4715 568.3301 678.6129 539.1400 707.8031
## Sep 1961       544.0719 493.4577 594.6861 466.6642 621.4796
## Oct 1961       476.6947 430.2464 523.1430 405.6581 547.7313
str(predict(a,20))
## List of 9
##  $ model    :List of 18
##   ..$ loglik    : num -680
##   ..$ aic       : num 1391
##   ..$ bic       : num 1439
##   ..$ aicc      : num 1395
##   ..$ mse       : num 121
##   ..$ amse      : num 194
##   ..$ fit       :List of 4
##   .. ..$ value  : num 1359
##   .. ..$ par    : num [1:16] 5.90e-01 5.82e-03 1.21e-04 1.27e+02 1.65 ...
##   .. ..$ fail   : int 1
##   .. ..$ fncount: int 2001
##   ..$ residuals : Time-Series [1:144] from 1949 to 1961: -0.0336 0.0329 -0.0134 -0.011 -0.0747 ...
##   ..$ fitted    : Time-Series [1:144] from 1949 to 1961: 116 114 134 130 131 ...
##   ..$ states    : mts [1:145, 1:14] 127 126 130 131 132 ...
##   .. ..- attr(*, "dimnames")=List of 2
##   .. .. ..$ : NULL
##   .. .. ..$ : chr [1:14] "l" "b" "s1" "s2" ...
##   .. ..- attr(*, "tsp")= num [1:3] 1949 1961 12
##   .. ..- attr(*, "class")= chr [1:3] "mts" "ts" "matrix"
##   ..$ par       : Named num [1:16] 5.90e-01 5.82e-03 1.21e-04 1.27e+02 1.65 ...
##   .. ..- attr(*, "names")= chr [1:16] "alpha" "beta" "gamma" "l" ...
##   ..$ m         : num 12
##   ..$ method    : chr "ETS(M,A,M)"
##   ..$ components: chr [1:4] "M" "A" "M" "FALSE"
##   ..$ call      : language ets(y = AirPassengers)
##   ..$ initstate : Named num [1:14] 126.979 1.648 0.887 0.793 0.923 ...
##   .. ..- attr(*, "names")= chr [1:14] "l" "b" "s1" "s2" ...
##   ..$ sigma2    : num 0.00135
##   ..$ x         : Time-Series [1:144] from 1949 to 1961: 112 118 132 129 121 135 148 148 136 119 ...
##   ..- attr(*, "class")= chr "ets"
##  $ mean     : Time-Series [1:20] from 1961 to 1963: 445 444 506 494 495 ...
##  $ level    : num [1:2] 80 95
##  $ x        : Time-Series [1:144] from 1949 to 1961: 112 118 132 129 121 135 148 148 136 119 ...
##  $ upper    : mts [1:20, 1:2] 466 468 538 527 531 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ : NULL
##   .. ..$ : chr [1:2] "Series 1" "Series 2"
##   ..- attr(*, "tsp")= num [1:3] 1961 1963 12
##   ..- attr(*, "class")= chr [1:3] "mts" "ts" "matrix"
##  $ lower    : mts [1:20, 1:2] 424 420 475 461 459 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ : NULL
##   .. ..$ : chr [1:2] "Series 1" "Series 2"
##   ..- attr(*, "tsp")= num [1:3] 1961 1963 12
##   ..- attr(*, "class")= chr [1:3] "mts" "ts" "matrix"
##  $ fitted   : Time-Series [1:144] from 1949 to 1961: 116 114 134 130 131 ...
##  $ method   : chr "ETS(M,A,M)"
##  $ residuals: Time-Series [1:144] from 1949 to 1961: -0.0336 0.0329 -0.0134 -0.011 -0.0747 ...
##  - attr(*, "class")= chr "forecast"
b=auto.arima(AirPassengers)
b
## Series: AirPassengers 
## ARIMA(0,1,1)(0,1,0)[12]                    
## 
## Coefficients:
##           ma1
##       -0.3184
## s.e.   0.0877
## 
## sigma^2 estimated as 137.3:  log likelihood=-508.32
## AIC=1020.64   AICc=1020.73   BIC=1026.39
predict(b,10)
## $pred
##           Jan      Feb      Mar      Apr      May      Jun      Jul
## 1961 446.7582 420.7582 448.7582 490.7582 501.7582 564.7582 651.7582
##           Aug      Sep      Oct
## 1961 635.7582 537.7582 490.7582
## 
## $se
##           Jan      Feb      Mar      Apr      May      Jun      Jul
## 1961 11.71600 14.17842 16.27239 18.12605 19.80699 21.35602 22.80006
##           Aug      Sep      Oct
## 1961 24.15793 25.44344 26.66705
ts.plot(AirPassengers)

newdataset=predar3(b,fore1=48)

#MAPE should be minimum, and AIC should be minimum