library(fpp2)
## Loading required package: ggplot2
## Loading required package: forecast
## Loading required package: fma
## Loading required package: expsmooth
library(seasonal)
View(enplanements)
enplanements
## Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov
## 1979 21.12 22.92 25.90 24.38 23.41 26.82 26.90 28.72 22.87 23.10 23.11
## 1980 21.35 22.23 24.40 23.41 22.06 24.53 24.00 24.97 20.57 21.55 20.14
## 1981 20.24 20.63 22.03 22.68 22.80 23.78 24.16 22.64 20.50 21.44 20.91
## 1982 20.52 21.66 23.82 24.01 22.52 24.68 24.19 24.73 20.85 21.84 21.70
## 1983 21.83 23.44 26.98 24.61 24.10 26.67 25.63 26.40 23.17 24.24 23.88
## 1984 22.60 23.67 27.00 26.91 26.63 28.93 27.72 29.79 25.61 26.81 26.97
## 1985 25.35 26.91 31.60 31.09 30.70 32.09 32.02 33.16 26.82 28.68 27.80
## 1986 28.07 30.01 34.12 32.90 32.92 34.86 35.67 37.81 30.65 31.96 31.01
## 1987 28.72 33.39 37.76 37.51 35.87 36.86 37.71 38.41 31.65 32.87 32.23
## 1988 29.64 32.87 37.12 35.32 34.82 36.97 36.89 38.76 32.99 34.59 34.28
## 1989 30.52 32.37 35.62 33.81 33.86 37.91 37.03 39.38 32.68 34.72 34.52
## 1990 31.06 33.95 37.11 36.00 34.66 37.88 37.50 39.98 33.08 34.73 34.11
## 1991 30.57 32.06 33.58 34.89 34.21 36.77 37.25 38.73 32.54 34.29 32.28
## 1992 29.81 31.59 34.74 33.74 34.42 40.61 42.74 43.74 36.24 35.02 34.12
## 1993 31.31 33.82 36.59 37.32 36.62 39.34 39.92 40.97 36.62 38.19 37.15
## 1994 32.98 36.23 40.84 39.87 39.97 43.15 44.07 44.43 39.66 41.05 40.60
## 1995 36.43 38.77 42.64 42.19 41.16 44.83 44.28 45.61 39.87 41.86 41.57
## 1996 37.17 41.92 46.55 45.10 44.46 47.47 47.00 48.37 41.76 44.38 41.25
## 1997 39.95 43.00 48.02 45.89 45.47 48.83 49.24 49.53 42.79 44.97 43.60
## 1998 39.21 43.46 47.77 48.41 47.05 50.52 49.88 50.26 43.80 46.72 45.95
## 1999 40.88 44.99 49.85 49.69 47.90 52.24 53.45 52.02 45.89 49.14 49.00
## 2000 41.37 46.47 52.86 51.68 51.98 56.12 55.41 54.38 47.74 50.53 50.93
## 2001 43.83 47.56 52.82 52.10 50.72 54.89 55.50 56.14 31.41 39.82 41.50
## 2002 38.13 42.43 48.05 46.48 46.58 50.29
## Dec
## 1979 22.14
## 1980 21.39
## 1981 21.70
## 1982 22.38
## 1983 23.96
## 1984 26.30
## 1985 30.46
## 1986 32.30
## 1987 31.88
## 1988 32.56
## 1989 32.91
## 1990 32.73
## 1991 34.29
## 1992 33.79
## 1993 36.30
## 1994 39.48
## 1995 40.40
## 1996 43.97
## 1997 44.05
## 1998 45.37
## 1999 45.81
## 2000 46.69
## 2001 40.45
## 2002
summary(enplanements)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 20.14 27.18 34.88 35.67 42.78 56.14
autoplot(enplanements)

#Total emplanements has an upward trend withb seasonality. August usually experiences the most enplanements while January sees the least. There is a major drop-off in September 2001, due to 9/11.
#Since this data shows trend and seasonality, my first forecast will be done using an STL decomp
EnplanementSTL = mstl(enplanements)
autoplot(EnplanementSTL)

#mstl captures the trend and most of the seasonality. Monthly variations and the September '01 outlier are picked up in the remainder
EnplanementSTL_Fcast = forecast(EnplanementSTL, h = 12)
autoplot(EnplanementSTL_Fcast)

summary(EnplanementSTL_Fcast)
##
## Forecast method: STL + ETS(M,A,N)
##
## Model Information:
## ETS(M,A,N)
##
## Call:
## ets(y = x, model = etsmodel, allow.multiplicative.trend = allow.multiplicative.trend)
##
## Smoothing parameters:
## alpha = 0.6133
## beta = 1e-04
##
## Initial states:
## l = 23.6725
## b = 0.0859
##
## sigma: 0.0324
##
## AIC AICc BIC
## 1660.145 1660.362 1678.354
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.0135202 1.286378 0.7352451 -0.1299084 2.201578 0.3770559
## ACF1
## Training set 0.0423878
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jul 2002 50.03229 48.13705 51.92752 47.13377 52.93080
## Aug 2002 50.28361 48.05685 52.51036 46.87808 53.68913
## Sep 2002 41.61821 39.10206 44.13437 37.77009 45.46634
## Oct 2002 44.83096 42.05432 47.60760 40.58446 49.07747
## Nov 2002 44.37167 41.35596 47.38738 39.75954 48.98381
## Dec 2002 43.32655 40.08843 46.56467 38.37427 48.27883
## Jan 2003 39.71476 36.26766 43.16186 34.44288 44.98664
## Feb 2003 43.73576 40.09081 47.38071 38.16129 49.31023
## Mar 2003 48.80412 44.97071 52.63753 42.94143 54.66681
## Apr 2003 48.04856 44.03476 52.06235 41.90999 54.18712
## May 2003 47.44245 43.25530 51.62960 41.03875 53.84615
## Jun 2003 51.29231 46.93798 55.64664 44.63294 57.95168
#The 95% confidence forecast for the following month is realtively tight, between 47.134-52.931 enplanements. As time goes the CI increases, in one year enplanementts are forecasted with 95% confidence at 44.633 - 57.951
#The AICc is 1660.132
#Since the magnitude of the seasonality appears to be increasing over time, my next forecast will be using a Holt Winters with multiplicative seasonality. To fight against overforecasting, I will be using damped trends.
HWEnplanements1 = hw(enplanements, damped=TRUE, phi = .8, seasonal="multiplicative")
HWEnplanements2 = hw(enplanements, damped=TRUE, phi = .85, seasonal="multiplicative")
HWEnplanements3 = hw(enplanements, damped=TRUE, phi = .9, seasonal="multiplicative")
HWEnplanements4 = hw(enplanements, damped=TRUE, phi = .95, seasonal="multiplicative")
summary(HWEnplanements1)
##
## Forecast method: Damped Holt-Winters' multiplicative method
##
## Model Information:
## Damped Holt-Winters' multiplicative method
##
## Call:
## hw(y = enplanements, seasonal = "multiplicative", damped = TRUE,
##
## Call:
## phi = 0.8)
##
## Smoothing parameters:
## alpha = 0.5442
## beta = 0.0765
## gamma = 1e-04
## phi = 0.8
##
## Initial states:
## l = 24.8407
## b = -0.3438
## s = 0.9459 0.9571 0.9785 0.9205 1.1113 1.0881
## 1.0889 1.0077 1.0295 1.0535 0.9472 0.8718
##
## sigma: 0.0375
##
## AIC AICc BIC
## 1750.381 1752.699 1812.293
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.09721221 1.391465 0.8405949 0.1925616 2.465815 0.4310825
## ACF1
## Training set 0.1014219
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jul 2002 50.32251 47.90192 52.74311 46.62053 54.02449
## Aug 2002 51.55858 48.64159 54.47557 47.09743 56.01973
## Sep 2002 42.81569 40.01864 45.61274 38.53797 47.09341
## Oct 2002 45.60066 42.22162 48.97970 40.43286 50.76846
## Nov 2002 44.67364 40.97681 48.37046 39.01983 50.32744
## Dec 2002 44.21138 40.17921 48.24354 38.04471 50.37805
## Jan 2003 40.78700 36.73234 44.84167 34.58592 46.98808
## Feb 2003 44.35228 39.59062 49.11395 37.06994 51.63462
## Mar 2003 49.36285 43.68387 55.04183 40.67760 58.04810
## Apr 2003 48.26098 42.35040 54.17156 39.22153 57.30043
## May 2003 47.25875 41.13187 53.38563 37.88850 56.62901
## Jun 2003 51.08541 44.10819 58.06264 40.41468 61.75615
## Jul 2003 51.06264 43.74599 58.37929 39.87279 62.25249
## Aug 2003 52.16332 44.35031 59.97633 40.21435 64.11228
## Sep 2003 43.21644 36.47164 49.96124 32.90116 53.53172
## Oct 2003 45.94143 38.49102 53.39183 34.54701 57.33584
## Nov 2003 44.94028 37.38597 52.49459 33.38697 56.49360
## Dec 2003 44.42222 36.69916 52.14527 32.61082 56.23361
## Jan 2004 40.94245 33.59492 48.28999 29.70537 52.17954
## Feb 2004 44.48740 36.26082 52.71398 31.90594 57.06887
## Mar 2004 49.48308 40.06929 58.89687 35.08592 63.88023
## Apr 2004 48.35497 38.90454 57.80540 33.90178 62.80816
## May 2004 47.33235 37.84150 56.82321 32.81735 61.84736
## Jun 2004 51.14904 40.63898 61.65911 35.07529 67.22280
#AICc = 1752.699
summary(HWEnplanements2)
##
## Forecast method: Damped Holt-Winters' multiplicative method
##
## Model Information:
## Damped Holt-Winters' multiplicative method
##
## Call:
## hw(y = enplanements, seasonal = "multiplicative", damped = TRUE,
##
## Call:
## phi = 0.85)
##
## Smoothing parameters:
## alpha = 0.3995
## beta = 0.0691
## gamma = 1e-04
## phi = 0.85
##
## Initial states:
## l = 24.7025
## b = 0.1088
## s = 0.9444 0.9598 0.9811 0.923 1.1082 1.0918
## 1.09 1.0094 1.0258 1.0511 0.9461 0.8694
##
## sigma: 0.0387
##
## AIC AICc BIC
## 1767.206 1769.524 1829.119
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.09645696 1.424298 0.8906889 0.1752837 2.608077 0.4567722
## ACF1
## Training set 0.2413328
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jul 2002 50.24097 47.75145 52.73050 46.43358 54.04837
## Aug 2002 51.22420 48.42287 54.02553 46.93993 55.50846
## Sep 2002 42.82105 40.22881 45.41330 38.85656 46.78555
## Oct 2002 45.65669 42.60453 48.70885 40.98881 50.32456
## Nov 2002 44.78937 41.50008 48.07867 39.75883 49.81991
## Dec 2002 44.16751 40.62672 47.70831 38.75234 49.58269
## Jan 2003 40.74130 37.19927 44.28334 35.32423 46.15837
## Feb 2003 44.40330 40.24313 48.56346 38.04087 50.76572
## Mar 2003 49.39981 44.44129 54.35833 41.81640 56.98322
## Apr 2003 48.26883 43.10577 53.43189 40.37262 56.16505
## May 2003 47.54449 42.15109 52.93789 39.29599 55.79298
## Jun 2003 51.38441 45.22924 57.53958 41.97089 60.79793
## Jul 2003 51.50397 45.01432 57.99362 41.57891 61.42903
## Aug 2003 52.31396 45.40430 59.22363 41.74654 62.88139
## Sep 2003 43.59253 37.57580 49.60925 34.39074 52.79431
## Oct 2003 46.35367 39.68672 53.02062 36.15745 56.54989
## Nov 2003 45.36901 38.58629 52.15173 34.99573 55.74228
## Dec 2003 44.65227 37.72913 51.57540 34.06425 55.24029
## Jan 2004 41.12065 34.52223 47.71908 31.02923 51.21207
## Feb 2004 44.75416 37.33553 52.17278 33.40835 56.09997
## Mar 2004 49.73114 41.22975 58.23254 36.72938 62.73290
## Apr 2004 48.54370 39.99908 57.08831 35.47584 61.61156
## May 2004 47.77439 39.12796 56.42081 34.55082 60.99795
## Jun 2004 51.59543 42.00652 61.18434 36.93046 66.26040
#AICc = 1769.524
summary(HWEnplanements3)
##
## Forecast method: Damped Holt-Winters' multiplicative method
##
## Model Information:
## Damped Holt-Winters' multiplicative method
##
## Call:
## hw(y = enplanements, seasonal = "multiplicative", damped = TRUE,
##
## Call:
## phi = 0.9)
##
## Smoothing parameters:
## alpha = 0.5675
## beta = 0.0355
## gamma = 1e-04
## phi = 0.9
##
## Initial states:
## l = 24.9154
## b = 0.16
## s = 0.9455 0.9611 0.9794 0.9224 1.1122 1.0918
## 1.0899 1.0088 1.0269 1.0483 0.9439 0.8698
##
## sigma: 0.0374
##
## AIC AICc BIC
## 1748.072 1750.390 1809.985
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.07700019 1.37824 0.8330178 0.1297219 2.458219 0.4271967
## ACF1
## Training set 0.09895672
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jul 2002 50.23518 47.83019 52.64018 46.55706 53.91331
## Aug 2002 51.21239 48.34946 54.07533 46.83391 55.59088
## Sep 2002 42.50046 39.79635 45.20457 38.36488 46.63604
## Oct 2002 45.15247 41.94184 48.36309 40.24224 50.06269
## Nov 2002 44.33426 40.85924 47.80927 39.01968 49.64883
## Dec 2002 43.63678 39.90693 47.36663 37.93247 49.34109
## Jan 2003 40.15761 36.44710 43.86812 34.48287 45.83234
## Feb 2003 43.59455 39.27155 47.91754 36.98310 50.20599
## Mar 2003 48.43659 43.31309 53.56008 40.60087 56.27230
## Apr 2003 47.46302 42.13547 52.79057 39.31523 55.61081
## May 2003 46.63722 41.10717 52.16726 38.17974 55.09470
## Jun 2003 50.40062 44.11209 56.68915 40.78314 60.01810
## Jul 2003 50.50094 43.89352 57.10836 40.39576 60.60612
## Aug 2003 51.45605 44.41803 58.49406 40.69233 62.21977
## Sep 2003 42.68232 36.59601 48.76864 33.37411 51.99054
## Oct 2003 45.32625 38.60450 52.04801 35.04622 55.60629
## Nov 2003 44.48775 37.64173 51.33377 34.01766 54.95784
## Dec 2003 43.77269 36.79686 50.74851 33.10408 54.44129
## Jan 2004 40.27012 33.63607 46.90418 30.12421 50.41603
## Feb 2004 43.70444 36.27418 51.13469 32.34085 55.06802
## Mar 2004 48.54643 40.04178 57.05108 35.53968 61.55318
## Apr 2004 47.55986 38.98643 56.13330 34.44793 60.67180
## May 2004 46.72284 38.06718 55.37850 33.48515 59.96052
## Jun 2004 50.48388 40.88401 60.08374 35.80215 65.16560
#AICc = 1750.390
summary(HWEnplanements4)
##
## Forecast method: Damped Holt-Winters' multiplicative method
##
## Model Information:
## Damped Holt-Winters' multiplicative method
##
## Call:
## hw(y = enplanements, seasonal = "multiplicative", damped = TRUE,
##
## Call:
## phi = 0.95)
##
## Smoothing parameters:
## alpha = 0.5191
## beta = 0.0011
## gamma = 0.0508
## phi = 0.95
##
## Initial states:
## l = 25.0062
## b = -0.2332
## s = 0.9406 0.9501 0.9676 0.9198 1.1038 1.0813
## 1.1082 0.9989 1.0582 1.0619 0.9502 0.8592
##
## sigma: 0.0386
##
## AIC AICc BIC
## 1764.508 1766.826 1826.421
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.1585707 1.438699 0.8789381 0.3948532 2.568506 0.450746
## ACF1
## Training set 0.1322248
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jul 2002 49.88428 47.41879 52.34977 46.11364 53.65492
## Aug 2002 50.70212 47.87688 53.52736 46.38129 55.02295
## Sep 2002 42.22946 39.63646 44.82247 38.26381 46.19512
## Oct 2002 44.59375 41.62280 47.56470 40.05008 49.13743
## Nov 2002 43.60822 40.49103 46.72542 38.84089 48.37556
## Dec 2002 42.94742 39.68132 46.21353 37.95235 47.94250
## Jan 2003 39.49978 36.32507 42.67449 34.64448 44.35508
## Feb 2003 43.08634 39.44596 46.72672 37.51886 48.65382
## Mar 2003 47.98657 43.74313 52.23000 41.49680 54.47634
## Apr 2003 47.33189 42.96728 51.69650 40.65679 54.00699
## May 2003 46.18656 41.75919 50.61393 39.41549 52.95763
## Jun 2003 50.12984 45.14791 55.11177 42.51064 57.74904
## Jul 2003 49.85761 44.69917 55.01605 41.96846 57.74677
## Aug 2003 50.67647 45.26658 56.08635 42.40277 58.95017
## Sep 2003 42.20925 37.56821 46.85029 35.11140 49.30710
## Oct 2003 44.57356 39.53363 49.61349 36.86565 52.28147
## Nov 2003 43.58955 38.52835 48.65075 35.84911 51.32999
## Dec 2003 42.93004 37.81793 48.04215 35.11174 50.74833
## Jan 2004 39.48467 34.66819 44.30115 32.11850 46.85084
## Feb 2004 43.07077 37.69444 48.44710 34.84838 51.29316
## Mar 2004 47.97019 41.84872 54.09165 38.60821 57.33216
## Apr 2004 47.31663 41.14940 53.48387 37.88466 56.74861
## May 2004 46.17251 40.03071 52.31431 36.77943 55.56558
## Jun 2004 50.11545 43.31733 56.91357 39.71862 60.51228
#AICc = 1766.826
#The HW model with a dampness of .9 produces the best model by looking at the lowest AICc
EnplanementHW_Fcast = forecast(HWEnplanements3, h = 12)
autoplot(EnplanementHW_Fcast)

summary(EnplanementHW_Fcast)
##
## Forecast method: Damped Holt-Winters' multiplicative method
##
## Model Information:
## Damped Holt-Winters' multiplicative method
##
## Call:
## hw(y = enplanements, seasonal = "multiplicative", damped = TRUE,
##
## Call:
## phi = 0.9)
##
## Smoothing parameters:
## alpha = 0.5675
## beta = 0.0355
## gamma = 1e-04
## phi = 0.9
##
## Initial states:
## l = 24.9154
## b = 0.16
## s = 0.9455 0.9611 0.9794 0.9224 1.1122 1.0918
## 1.0899 1.0088 1.0269 1.0483 0.9439 0.8698
##
## sigma: 0.0374
##
## AIC AICc BIC
## 1748.072 1750.390 1809.985
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.07700019 1.37824 0.8330178 0.1297219 2.458219 0.4271967
## ACF1
## Training set 0.09895672
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jul 2002 50.23518 47.83019 52.64018 46.55706 53.91331
## Aug 2002 51.21239 48.34946 54.07533 46.83391 55.59088
## Sep 2002 42.50046 39.79635 45.20457 38.36488 46.63604
## Oct 2002 45.15247 41.94184 48.36309 40.24224 50.06269
## Nov 2002 44.33426 40.85924 47.80927 39.01968 49.64883
## Dec 2002 43.63678 39.90693 47.36663 37.93247 49.34109
## Jan 2003 40.15761 36.44710 43.86812 34.48287 45.83234
## Feb 2003 43.59455 39.27155 47.91754 36.98310 50.20599
## Mar 2003 48.43659 43.31309 53.56008 40.60087 56.27230
## Apr 2003 47.46302 42.13547 52.79057 39.31523 55.61081
## May 2003 46.63722 41.10717 52.16726 38.17974 55.09470
## Jun 2003 50.40062 44.11209 56.68915 40.78314 60.01810
#The 95% confidence forecast for the following month is between 46.557-53.913 enplanements. As time goes the CI increases, in one year enplanementts are forecasted with 95% confidence at 40.783 - 60.018. These ranges are more spread out than the STL model.
#The AICc is 1750.390, higher than our STL model
#For the last forecast, I will use R's auto.arima() function to find the best arima model to forecast. auto.arima() does not consider all models, so I must set the parameters 'stepwise' and 'appproximation' to 'FALSE' to make it work harder to find the best model.
ARIMAEnplanements = auto.arima(enplanements, stepwise = FALSE, approximation = FALSE)
EnplanementARIMA_Fcast = forecast(ARIMAEnplanements, h = 12)
autoplot(EnplanementARIMA_Fcast)

summary(EnplanementARIMA_Fcast)
##
## Forecast method: ARIMA(2,0,1)(0,1,1)[12]
##
## Model Information:
## Series: enplanements
## ARIMA(2,0,1)(0,1,1)[12]
##
## Coefficients:
## ar1 ar2 ma1 sma1
## 1.3533 -0.3676 -0.7274 -0.4591
## s.e. 0.1175 0.1115 0.0888 0.0969
##
## sigma^2 estimated as 2.236: log likelihood=-491.66
## AIC=993.32 AICc=993.55 BIC=1011.31
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.06316179 1.452447 0.8129972 0.1198717 2.413514 0.4169296
## ACF1
## Training set -0.007664775
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jul 2002 50.67834 48.76179 52.59488 47.74723 53.60945
## Aug 2002 50.75927 48.49827 53.02028 47.30137 54.21718
## Sep 2002 34.50244 32.06183 36.94304 30.76985 38.23502
## Oct 2002 40.45092 37.88172 43.02012 36.52166 44.38017
## Nov 2002 41.41446 38.73846 44.09046 37.32188 45.50704
## Dec 2002 39.51247 36.74186 42.28307 35.27519 43.74974
## Jan 2003 36.69537 33.83860 39.55214 32.32632 41.06442
## Feb 2003 40.99241 38.05617 43.92864 36.50182 45.48299
## Mar 2003 46.59598 43.58598 49.60597 41.99259 51.19936
## Apr 2003 45.48170 42.40300 48.56041 40.77323 50.19018
## May 2003 45.16279 42.01990 48.30568 40.35616 49.96943
## Jun 2003 49.12578 45.92281 52.32874 44.22727 54.02428
#The 95% confidence forecast for the following month is between 47.747-53.609 enplanements. As time goes the CI increases, in one year enplanementts are forecasted with 95% confidence at 44.227 - 54.024. These ranges are the least spread out compared to the other two models.
#The AICc is 993.55, than all other models tested.
autoplot(enplanements) +
autolayer(EnplanementSTL_Fcast, series="STL", PI=FALSE) +
autolayer(EnplanementHW_Fcast, series="HW",PI=FALSE) +
autolayer(EnplanementARIMA_Fcast, series="ARIMA", PI=FALSE) +
xlab("Year") +
ylab("Enplanements") +
ggtitle("Enplanements") +
guides(colour=guide_legend(title="Forecast"))

#By checking the lowest AICc, the ARIMA model is determined to be the best model, than the STL, and lastly the HW.