#CHAPTER 7

# 1

library(fpp2)
## Loading required package: ggplot2
## Loading required package: forecast
## Loading required package: fma
## Loading required package: expsmooth
library(seasonal)
View(pigs)
mypigsts=ts(pigs, frequency = 12, start = 1980)
ses(mypigsts, h = 4)
##          Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## Sep 1995       98816.41 85605.43 112027.4 78611.97 119020.8
## Oct 1995       98816.41 85034.52 112598.3 77738.83 119894.0
## Nov 1995       98816.41 84486.34 113146.5 76900.46 120732.4
## Dec 1995       98816.41 83958.37 113674.4 76092.99 121539.8
plot(ses(mypigsts, h =4))

#The 95% interval produced by R grows as the forecast gets longer, while the manually computed interval does not change


# 2,3

#ses model is not populating

# 4

# 5

# a

autoplot(books)  

#Both book styles have an increasing trend with some seasonal component. There also seems to be a lag for the paperback books

# b

hardbooksses = ses(books[, 1], alpha=NULL, initial="simple", h=4)
plot(hardbooksses)

paperbooksses = ses(books[, 2], alpha=NULL, initial="simple", h=4)
plot(paperbooksses)

# c

summary(hardbooksses)
## 
## Forecast method: Simple exponential smoothing
## 
## Model Information:
## Simple exponential smoothing 
## 
## Call:
##  ses(y = books[, 1], h = 4, initial = "simple", alpha = NULL) 
## 
##   Smoothing parameters:
##     alpha = 0.2125 
## 
##   Initial states:
##     l = 199 
## 
##   sigma:  34.7918
## Error measures:
##                    ME     RMSE      MAE       MPE     MAPE      MASE
## Training set 1.749509 34.79175 28.64424 -2.770157 16.56938 0.7223331
##                    ACF1
## Training set -0.1268119
## 
## Forecasts:
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 31       210.1537 165.5663 254.7411 141.9631 278.3443
## 32       210.1537 164.5706 255.7368 140.4404 279.8671
## 33       210.1537 163.5962 256.7112 138.9501 281.3573
## 34       210.1537 162.6418 257.6657 137.4905 282.8170
summary(paperbooksses)
## 
## Forecast method: Simple exponential smoothing
## 
## Model Information:
## Simple exponential smoothing 
## 
## Call:
##  ses(y = books[, 2], h = 4, initial = "simple", alpha = NULL) 
## 
##   Smoothing parameters:
##     alpha = 0.3473 
## 
##   Initial states:
##     l = 139 
## 
##   sigma:  32.0198
## Error measures:
##                    ME     RMSE      MAE      MPE     MAPE      MASE
## Training set 9.729512 32.01982 26.34467 3.104207 13.05063 0.7860035
##                    ACF1
## Training set -0.1629044
## 
## Forecasts:
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 31       240.3808 199.3457 281.4158 177.6231 303.1385
## 32       240.3808 196.9410 283.8206 173.9453 306.8162
## 33       240.3808 194.6626 286.0990 170.4608 310.3008
## 34       240.3808 192.4924 288.2692 167.1418 313.6197
#RMSE for paperback ses = 32.01982, RMSE for hardcover ses = 34.79175

# 6

# a

holtpaper = holt(books[,1], initial = "simple", h=4)
holthard = holt(books[,2], initial = "simple", h=4)  
holtpaper
##    Point Forecast    Lo 80    Hi 80     Lo 95    Hi 95
## 31       222.0198 171.3391 272.7005 144.51038 299.5292
## 32       229.6900 164.8869 294.4932 130.58215 328.7979
## 33       237.3603 145.1171 329.6035  96.28648 378.4341
## 34       245.0306 115.5205 374.5406  46.96203 443.0991
holthard
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 31       250.7888 205.8783 295.6992 182.1041 319.4734
## 32       254.7002 202.4087 306.9917 174.7272 334.6731
## 33       258.6116 196.3180 320.9052 163.3418 353.8814
## 34       262.5230 187.9901 337.0559 148.5347 376.5113
autoplot(holtpaper)

autoplot(holthard)

# b

summary(holtpaper)
## 
## Forecast method: Holt's method
## 
## Model Information:
## Holt's method 
## 
## Call:
##  holt(y = books[, 1], h = 4, initial = "simple") 
## 
##   Smoothing parameters:
##     alpha = 0.2984 
##     beta  = 0.4984 
## 
##   Initial states:
##     l = 199 
##     b = -27 
## 
##   sigma:  39.5463
## Error measures:
##                    ME     RMSE      MAE      MPE    MAPE      MASE
## Training set 7.769881 39.54634 33.53769 1.633334 18.1962 0.8457331
##                    ACF1
## Training set -0.1088638
## 
## Forecasts:
##    Point Forecast    Lo 80    Hi 80     Lo 95    Hi 95
## 31       222.0198 171.3391 272.7005 144.51038 299.5292
## 32       229.6900 164.8869 294.4932 130.58215 328.7979
## 33       237.3603 145.1171 329.6035  96.28648 378.4341
## 34       245.0306 115.5205 374.5406  46.96203 443.0991
summary(holthard)
## 
## Forecast method: Holt's method
## 
## Model Information:
## Holt's method 
## 
## Call:
##  holt(y = books[, 2], h = 4, initial = "simple") 
## 
##   Smoothing parameters:
##     alpha = 0.439 
##     beta  = 0.1574 
## 
##   Initial states:
##     l = 139 
##     b = -11 
## 
##   sigma:  35.0438
## Error measures:
##                  ME     RMSE      MAE     MPE     MAPE      MASE
## Training set 7.1932 35.04383 27.99177 2.42376 14.18243 0.8351453
##                     ACF1
## Training set -0.07743099
## 
## Forecasts:
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 31       250.7888 205.8783 295.6992 182.1041 319.4734
## 32       254.7002 202.4087 306.9917 174.7272 334.6731
## 33       258.6116 196.3180 320.9052 163.3418 353.8814
## 34       262.5230 187.9901 337.0559 148.5347 376.5113
#The RMSE for holtpaper is 39.54634 and the RMSE for holthard is 35.04383. 

# c

#The holt seemed to produce a better looking forecast as it is at least capturing the upward trend, but the SES models have lower RMSE

# d

#The 95% interval produced by R grows as the forecast gets longer, while the manually computed interval does not change

# 7

holt1 = holt(eggs, h = 100)
holt2 = holt(eggs, damped=TRUE, phi = 0.8, h=100)
holt3 = holt(eggs, damped=TRUE, phi = 0.85, h=100)
holt4 = holt(eggs, damped=TRUE, phi = 0.9, h=100)
holt5 = holt(eggs, damped=TRUE, phi = 0.95, h=100)
autoplot(holt1)

autoplot(holt2)

autoplot(holt3)

autoplot(holt4)

autoplot(holt5)

summary(holt1)
## 
## Forecast method: Holt's method
## 
## Model Information:
## Holt's method 
## 
## Call:
##  holt(y = eggs, h = 100) 
## 
##   Smoothing parameters:
##     alpha = 0.8124 
##     beta  = 1e-04 
## 
##   Initial states:
##     l = 314.7232 
##     b = -2.7222 
## 
##   sigma:  27.1665
## 
##      AIC     AICc      BIC 
## 1053.755 1054.437 1066.472 
## 
## Error measures:
##                      ME     RMSE      MAE       MPE     MAPE      MASE
## Training set 0.04499087 26.58219 19.18491 -1.142201 9.653791 0.9463626
##                    ACF1
## Training set 0.01348202
## 
## Forecasts:
##      Point Forecast       Lo 80     Hi 80       Lo 95    Hi 95
## 1994    59.78553313   24.970286  94.60078    6.540207 113.0309
## 1995    57.06372643   12.206005 101.92145  -11.540238 125.6677
## 1996    54.34191973    1.308668 107.37517  -26.765440 135.4493
## 1997    51.62011302   -8.488401 111.72863  -40.307926 143.5482
## 1998    48.89830632  -17.537664 115.33428  -52.706742 150.5034
## 1999    46.17649962  -26.035964 118.38896  -64.262933 156.6159
## 2000    43.45469292  -34.106500 121.01589  -75.164916 162.0743
## 2001    40.73288622  -41.832449 123.29822  -85.539898 167.0057
## 2002    38.01107951  -49.273098 125.29526  -95.478551 171.5007
## 2003    35.28927281  -56.472472 127.05102 -105.048206 175.6268
## 2004    32.56746611  -63.464327 128.59926 -114.300487 179.4354
## 2005    29.84565941  -70.275216 129.96654 -123.276007 182.9673
## 2006    27.12385271  -76.926479 131.17418 -132.007398 186.2551
## 2007    24.40204600  -83.435566 132.23966 -140.521350 189.3254
## 2008    21.68023930  -89.816966 133.17744 -148.840022 192.2005
## 2009    18.95843260  -96.082866 133.99973 -156.982051 194.8989
## 2010    16.23662590 -102.243631 134.71688 -164.963291 197.4365
## 2011    13.51481920 -108.308165 135.33780 -172.797358 199.8270
## 2012    10.79301249 -114.284184 135.87021 -180.496053 202.0821
## 2013     8.07120579 -120.178426 136.32084 -188.069681 204.2121
## 2014     5.34939909 -125.996817 136.69562 -195.527304 206.2261
## 2015     2.62759239 -131.744601 136.99979 -202.876944 208.1321
## 2016    -0.09421431 -137.426446 137.23802 -210.125737 209.9373
## 2017    -2.81602102 -143.046526 137.41448 -217.280071 211.6480
## 2018    -5.53782772 -148.608596 137.53294 -224.345686 213.2700
## 2019    -8.25963442 -154.116046 137.59678 -231.327766 214.8085
## 2020   -10.98144112 -159.571946 137.60906 -238.231008 216.2681
## 2021   -13.70324782 -164.979092 137.57260 -245.059687 217.6532
## 2022   -16.42505453 -170.340036 137.48993 -251.817706 218.9676
## 2023   -19.14686123 -175.657116 137.36339 -258.508640 220.2149
## 2024   -21.86866793 -180.932478 137.19514 -265.135773 221.3984
## 2025   -24.59047463 -186.168101 136.98715 -271.702130 222.5212
## 2026   -27.31228133 -191.365811 136.74125 -278.210504 223.5859
## 2027   -30.03408804 -196.527300 136.45912 -284.663482 224.5953
## 2028   -32.75589474 -201.654137 136.14235 -291.063466 225.5517
## 2029   -35.47770144 -206.747783 135.79238 -297.412688 226.4573
## 2030   -38.19950814 -211.809598 135.41058 -303.713228 227.3142
## 2031   -40.92131484 -216.840851 134.99822 -309.967029 228.1244
## 2032   -43.64312155 -221.842733 134.55649 -316.175908 228.8897
## 2033   -46.36492825 -226.816355 134.08650 -322.341569 229.6117
## 2034   -49.08673495 -231.762762 133.58929 -328.465610 230.2921
## 2035   -51.80854165 -236.682939 133.06586 -334.549533 230.9324
## 2036   -54.53034835 -241.577809 132.51711 -340.594753 231.5341
## 2037   -57.25215506 -246.448244 131.94393 -346.602603 232.0983
## 2038   -59.97396176 -251.295068 131.34714 -352.574344 232.6264
## 2039   -62.69576846 -256.119059 130.72752 -358.511164 233.1196
## 2040   -65.41757516 -260.920954 130.08580 -364.414190 233.5790
## 2041   -68.13938186 -265.701450 129.42269 -370.284491 234.0057
## 2042   -70.86118857 -270.461210 128.73883 -376.123079 234.4007
## 2043   -73.58299527 -275.200863 128.03487 -381.930915 234.7649
## 2044   -76.30480197 -279.921006 127.31140 -387.708914 235.0993
## 2045   -79.02660867 -284.622209 126.56899 -393.457946 235.4047
## 2046   -81.74841537 -289.305013 125.80818 -399.178839 235.6820
## 2047   -84.47022208 -293.969936 125.02949 -404.872385 235.9319
## 2048   -87.19202878 -298.617469 124.23341 -410.539337 236.1553
## 2049   -89.91383548 -303.248085 123.42041 -416.180415 236.3527
## 2050   -92.63564218 -307.862233 122.59095 -421.796308 236.5250
## 2051   -95.35744888 -312.460345 121.74545 -427.387675 236.6728
## 2052   -98.07925559 -317.042831 120.88432 -432.955146 236.7966
## 2053  -100.80106229 -321.610088 120.00796 -438.499326 236.8972
## 2054  -103.52286899 -326.162494 119.11676 -444.020793 236.9751
## 2055  -106.24467569 -330.700413 118.21106 -449.520103 237.0308
## 2056  -108.96648239 -335.224193 117.29123 -454.997790 237.0648
## 2057  -111.68828910 -339.734170 116.35759 -460.454367 237.0778
## 2058  -114.41009580 -344.230666 115.41047 -465.890327 237.0701
## 2059  -117.13190250 -348.713991 114.45019 -471.306143 237.0423
## 2060  -119.85370920 -353.184443 113.47702 -476.702272 236.9949
## 2061  -122.57551590 -357.642310 112.49128 -482.079153 236.9281
## 2062  -125.29732261 -362.087868 111.49322 -487.437211 236.8426
## 2063  -128.01912931 -366.521384 110.48313 -492.776852 236.7386
## 2064  -130.74093601 -370.943117 109.46124 -498.098471 236.6166
## 2065  -133.46274271 -375.353314 108.42783 -503.402447 236.4770
## 2066  -136.18454941 -379.752215 107.38312 -508.689149 236.3200
## 2067  -138.90635612 -384.140052 106.32734 -513.958929 236.1462
## 2068  -141.62816282 -388.517050 105.26072 -519.212132 235.9558
## 2069  -144.34996952 -392.883424 104.18349 -524.449088 235.7491
## 2070  -147.07177622 -397.239385 103.09583 -529.670117 235.5266
## 2071  -149.79358292 -401.585134 101.99797 -534.875530 235.2884
## 2072  -152.51538963 -405.920870 100.89009 -540.065628 235.0348
## 2073  -155.23719633 -410.246781  99.77239 -545.240700 234.7663
## 2074  -157.95900303 -414.563051  98.64505 -550.401029 234.4830
## 2075  -160.68080973 -418.869861  97.50824 -555.546889 234.1853
## 2076  -163.40261643 -423.167382  96.36215 -560.678543 233.8733
## 2077  -166.12442314 -427.455784  95.20694 -565.796249 233.5474
## 2078  -168.84622984 -431.735228  94.04277 -570.900257 233.2078
## 2079  -171.56803654 -436.005874  92.86980 -575.990809 232.8547
## 2080  -174.28984324 -440.267874  91.68819 -581.068139 232.4885
## 2081  -177.01164994 -444.521379  90.49808 -586.132476 232.1092
## 2082  -179.73345665 -448.766534  89.29962 -591.184043 231.7171
## 2083  -182.45526335 -453.003480  88.09295 -596.223054 231.3125
## 2084  -185.17707005 -457.232353  86.87821 -601.249720 230.8956
## 2085  -187.89887675 -461.453288  85.65553 -606.264245 230.4665
## 2086  -190.62068345 -465.666414  84.42505 -611.266828 230.0255
## 2087  -193.34249016 -469.871857  83.18688 -616.257661 229.5727
## 2088  -196.06429686 -474.069741  81.94115 -621.236934 229.1083
## 2089  -198.78610356 -478.260186  80.68798 -626.204828 228.6326
## 2090  -201.50791026 -482.443308  79.42749 -631.161524 228.1457
## 2091  -204.22971696 -486.619220  78.15979 -636.107193 227.6478
## 2092  -206.95152367 -490.788035  76.88499 -641.042007 227.1390
## 2093  -209.67333037 -494.949859  75.60320 -645.966131 226.6195
summary(holt2)
## 
## Forecast method: Damped Holt's method
## 
## Model Information:
## Damped Holt's method 
## 
## Call:
##  holt(y = eggs, h = 100, damped = TRUE, phi = 0.8) 
## 
##   Smoothing parameters:
##     alpha = 0.8385 
##     beta  = 1e-04 
##     phi   = 0.8 
## 
##   Initial states:
##     l = 303.7339 
##     b = 5.0811 
## 
##   sigma:  27.3966
## 
##      AIC     AICc      BIC 
## 1054.290 1054.972 1067.007 
## 
## Error measures:
##                     ME     RMSE      MAE       MPE     MAPE      MASE
## Training set -3.311145 26.65797 19.46082 -3.094339 10.09642 0.9599732
##                      ACF1
## Training set -0.008690086
## 
## Forecasts:
##      Point Forecast       Lo 80    Hi 80       Lo 95    Hi 95
## 1994       62.96540   27.855308  98.0755    9.269147 116.6617
## 1995       62.96415   17.143380 108.7849   -7.112669 133.0410
## 1996       62.96314    8.497566 117.4287  -20.334769 146.2611
## 1997       62.96234    1.046579 124.8781  -31.729643 157.6543
## 1998       62.96169   -5.600015 131.5234  -41.894391 167.8178
## 1999       62.96118  -11.657334 137.5797  -51.157988 177.0803
## 2000       62.96077  -17.258876 143.1804  -59.724591 185.6461
## 2001       62.96044  -22.494248 148.4151  -67.731227 193.6521
## 2002       62.96017  -27.427050 153.3474  -75.275156 201.1955
## 2003       62.95996  -32.104356 158.0243  -82.428367 208.3483
## 2004       62.95980  -36.562171 162.4818  -89.245917 215.1655
## 2005       62.95966  -40.828761 166.7481  -95.771032 221.6904
## 2006       62.95955  -44.926800 170.8459 -102.038386 227.9575
## 2007       62.95947  -48.874810 174.7937 -108.076300 233.9952
## 2008       62.95940  -52.688148 178.6069 -113.908260 239.8271
## 2009       62.95934  -56.379718 182.2984 -119.554000 245.4727
## 2010       62.95930  -59.960487 185.8791 -125.030291 250.9489
## 2011       62.95926  -63.439870 189.3584 -130.351528 256.2701
## 2012       62.95923  -66.826017 192.7445 -135.530178 261.4486
## 2013       62.95921  -70.126043 196.0445 -140.577121 266.4955
## 2014       62.95919  -73.346203 199.2646 -145.501921 271.4203
## 2015       62.95918  -76.492028 202.4104 -150.313038 276.2314
## 2016       62.95917  -79.568440 205.4868 -155.017997 280.9363
## 2017       62.95916  -82.579838 208.4982 -159.623529 285.5418
## 2018       62.95915  -85.530180 211.4485 -164.135683 290.0540
## 2019       62.95914  -88.423033 214.3413 -168.559917 294.4782
## 2020       62.95914  -91.261633 217.1799 -172.901179 298.8195
## 2021       62.95914  -94.048923 219.9672 -177.163968 303.0822
## 2022       62.95913  -96.787587 222.7059 -181.352392 307.2707
## 2023       62.95913  -99.480086 225.3983 -185.470212 311.3885
## 2024       62.95913 -102.128677 228.0469 -189.520882 315.4391
## 2025       62.95913 -104.735442 230.6537 -193.507584 319.4258
## 2026       62.95913 -107.302301 233.2206 -197.433255 323.3515
## 2027       62.95912 -109.831033 235.7493 -201.300617 327.2189
## 2028       62.95912 -112.323287 238.2415 -205.112191 331.0304
## 2029       62.95912 -114.780599 240.6988 -208.870325 334.7886
## 2030       62.95912 -117.204399 243.1226 -212.577205 338.4955
## 2031       62.95912 -119.596020 245.5143 -216.234874 342.1531
## 2032       62.95912 -121.956711 247.8750 -219.845240 345.7635
## 2033       62.95912 -124.287643 250.2059 -223.410092 349.3283
## 2034       62.95912 -126.589913 252.5082 -226.931110 352.8494
## 2035       62.95912 -128.864553 254.7828 -230.409872 356.3281
## 2036       62.95912 -131.112534 257.0308 -233.847863 359.7661
## 2037       62.95912 -133.334774 259.2530 -237.246484 363.1647
## 2038       62.95912 -135.532135 261.4504 -240.607059 366.5253
## 2039       62.95912 -137.705436 263.6237 -243.930835 369.8491
## 2040       62.95912 -139.855449 265.7737 -247.218997 373.1372
## 2041       62.95912 -141.982909 267.9012 -250.472666 376.3909
## 2042       62.95912 -144.088509 270.0068 -253.692904 379.6111
## 2043       62.95912 -146.172911 272.0912 -256.880721 382.7990
## 2044       62.95912 -148.236742 274.1550 -260.037078 385.9553
## 2045       62.95912 -150.280599 276.1988 -263.162888 389.0811
## 2046       62.95912 -152.305051 278.2233 -266.259020 392.1773
## 2047       62.95912 -154.310641 280.2289 -269.326305 395.2445
## 2048       62.95912 -156.297886 282.2161 -272.365534 398.2838
## 2049       62.95912 -158.267281 284.1855 -275.377463 401.2957
## 2050       62.95912 -160.219297 286.1375 -278.362815 404.2811
## 2051       62.95912 -162.154388 288.0726 -281.322281 407.2405
## 2052       62.95912 -164.072986 289.9912 -284.256524 410.1748
## 2053       62.95912 -165.975506 291.8937 -287.166176 413.0844
## 2054       62.95912 -167.862345 293.7806 -290.051847 415.9701
## 2055       62.95912 -169.733884 295.6521 -292.914120 418.8324
## 2056       62.95912 -171.590491 297.5087 -295.753555 421.6718
## 2057       62.95912 -173.432516 299.3508 -298.570689 424.4889
## 2058       62.95912 -175.260298 301.1785 -301.366041 427.2843
## 2059       62.95912 -177.074163 302.9924 -304.140107 430.0583
## 2060       62.95912 -178.874423 304.7927 -306.893368 432.8116
## 2061       62.95912 -180.661380 306.5796 -309.626283 435.5445
## 2062       62.95912 -182.435325 308.3536 -312.339298 438.2575
## 2063       62.95912 -184.196538 310.1148 -315.032841 440.9511
## 2064       62.95912 -185.945289 311.8635 -317.707325 443.6256
## 2065       62.95912 -187.681840 313.6001 -320.363149 446.2814
## 2066       62.95912 -189.406441 315.3247 -323.000699 448.9189
## 2067       62.95912 -191.119336 317.0376 -325.620347 451.5386
## 2068       62.95912 -192.820761 318.7390 -328.222451 454.1407
## 2069       62.95912 -194.510943 320.4292 -330.807361 456.7256
## 2070       62.95912 -196.190101 322.1083 -333.375413 459.2937
## 2071       62.95912 -197.858449 323.7767 -335.926931 461.8452
## 2072       62.95912 -199.516193 325.4344 -338.462232 464.3805
## 2073       62.95912 -201.163533 327.0818 -340.981620 466.8999
## 2074       62.95912 -202.800662 328.7189 -343.485392 469.4036
## 2075       62.95912 -204.427767 330.3460 -345.973834 471.8921
## 2076       62.95912 -206.045030 331.9633 -348.447226 474.3655
## 2077       62.95912 -207.652628 333.5709 -350.905835 476.8241
## 2078       62.95912 -209.250733 335.1690 -353.349925 479.2682
## 2079       62.95912 -210.839510 336.7578 -355.779750 481.6980
## 2080       62.95912 -212.419121 338.3374 -358.195556 484.1138
## 2081       62.95912 -213.989722 339.9080 -360.597583 486.5158
## 2082       62.95912 -215.551466 341.4697 -362.986065 488.9043
## 2083       62.95912 -217.104502 343.0227 -365.361228 491.2795
## 2084       62.95912 -218.648973 344.5672 -367.723292 493.6415
## 2085       62.95912 -220.185019 346.1033 -370.072473 495.9907
## 2086       62.95912 -221.712777 347.6310 -372.408977 498.3272
## 2087       62.95912 -223.232380 349.1506 -374.733009 500.6513
## 2088       62.95912 -224.743957 350.6622 -377.044766 502.9630
## 2089       62.95912 -226.247633 352.1659 -379.344441 505.2627
## 2090       62.95912 -227.743532 353.6618 -381.632220 507.5505
## 2091       62.95912 -229.231772 355.1500 -383.908287 509.8265
## 2092       62.95912 -230.712471 356.6307 -386.172820 512.0911
## 2093       62.95912 -232.185741 358.1040 -388.425992 514.3442
summary(holt3)
## 
## Forecast method: Damped Holt's method
## 
## Model Information:
## Damped Holt's method 
## 
## Call:
##  holt(y = eggs, h = 100, damped = TRUE, phi = 0.85) 
## 
##   Smoothing parameters:
##     alpha = 0.8404 
##     beta  = 1e-04 
##     phi   = 0.85 
## 
##   Initial states:
##     l = 302.9994 
##     b = 1.9504 
## 
##   sigma:  27.3869
## 
##      AIC     AICc      BIC 
## 1054.224 1054.905 1066.940 
## 
## Error measures:
##                   ME     RMSE      MAE      MPE     MAPE      MASE
## Training set -3.1767 26.64853 19.48625 -3.04623 10.10199 0.9612276
##                      ACF1
## Training set -0.008367522
## 
## Forecasts:
##      Point Forecast        Lo 80     Hi 80       Lo 95    Hi 95
## 1994       62.95303   27.8553681  98.05069    9.275788 116.6303
## 1995       62.95112   17.1038416 108.79840   -7.166243 133.0685
## 1996       62.94950    8.4311547 117.46785  -20.429115 146.3281
## 1997       62.94812    0.9589769 124.93727  -31.856095 157.7523
## 1998       62.94695   -5.7055538 131.59946  -42.047995 167.9419
## 1999       62.94596  -11.7786764 137.67059  -51.335508 177.2274
## 2000       62.94511  -17.3945007 143.28472  -59.923722 185.8139
## 2001       62.94439  -22.6430020 148.53178  -67.950231 193.8390
## 2002       62.94378  -27.5880217 153.47558  -75.512662 201.4002
## 2003       62.94326  -32.2768022 158.16332  -82.683258 208.5698
## 2004       62.94282  -36.7454670 162.63110  -89.517257 215.4029
## 2005       62.94244  -41.0223727 166.90726  -96.058021 221.9429
## 2006       62.94212  -45.1302640 171.01451 -102.340330 228.2246
## 2007       62.94185  -49.0877158 174.97142 -108.392587 234.2763
## 2008       62.94162  -52.9101309 178.79337 -114.238344 240.1216
## 2009       62.94143  -56.6104506 182.49330 -119.897391 245.7802
## 2010       62.94126  -60.1996727 186.08219 -125.386544 251.2691
## 2011       62.94112  -63.6872367 189.56947 -130.720238 256.6025
## 2012       62.94100  -67.0813172 192.96331 -135.910972 261.7930
## 2013       62.94089  -70.3890486 196.27084 -140.969657 266.8514
## 2014       62.94081  -73.6167017 199.49832 -145.905880 271.7875
## 2015       62.94073  -76.7698235 202.65129 -150.728125 276.6096
## 2016       62.94067  -79.8533487 205.73469 -155.443936 281.3253
## 2017       62.94062  -82.8716907 208.75292 -160.060064 285.9413
## 2018       62.94057  -85.8288151 211.70996 -164.582571 290.4637
## 2019       62.94053  -88.7283015 214.60937 -169.016933 294.8980
## 2020       62.94050  -91.5733934 217.45439 -173.368108 299.2491
## 2021       62.94047  -94.3670413 220.24799 -177.640609 303.5216
## 2022       62.94045  -97.1119382 222.99284 -181.838554 307.7195
## 2023       62.94043  -99.8105504 225.69141 -185.965714 311.8466
## 2024       62.94041 -102.4651426 228.34597 -190.025554 315.9064
## 2025       62.94040 -105.0778009 230.95859 -194.021262 319.9021
## 2026       62.94038 -107.6504518 233.53122 -197.955786 323.8366
## 2027       62.94037 -110.1848785 236.06563 -201.831851 327.7126
## 2028       62.94037 -112.6827356 238.56347 -205.651989 331.5327
## 2029       62.94036 -115.1455618 241.02628 -209.418553 335.2993
## 2030       62.94035 -117.5747907 243.45549 -213.133734 339.0144
## 2031       62.94035 -119.9717608 245.85245 -216.799581 342.6803
## 2032       62.94034 -122.3377240 248.21841 -220.418007 346.2987
## 2033       62.94034 -124.6738533 250.55453 -223.990806 349.8715
## 2034       62.94033 -126.9812495 252.86192 -227.519662 353.4003
## 2035       62.94033 -129.2609475 255.14161 -231.006158 356.8868
## 2036       62.94033 -131.5139213 257.39458 -234.451783 360.3324
## 2037       62.94033 -133.7410893 259.62174 -237.857941 363.7386
## 2038       62.94032 -135.9433184 261.82397 -241.225959 367.1066
## 2039       62.94032 -138.1214281 264.00207 -244.557090 370.4377
## 2040       62.94032 -140.2761939 266.15684 -247.852519 373.7332
## 2041       62.94032 -142.4083506 268.28899 -251.113371 376.9940
## 2042       62.94032 -144.5185952 270.39923 -254.340711 380.2214
## 2043       62.94032 -146.6075899 272.48823 -257.535552 383.4162
## 2044       62.94032 -148.6759639 274.55660 -260.698857 386.5795
## 2045       62.94032 -150.7243160 276.60495 -263.831541 389.7122
## 2046       62.94032 -152.7532167 278.63385 -266.934476 392.8151
## 2047       62.94032 -154.7632097 280.64384 -270.008495 395.8891
## 2048       62.94032 -156.7548141 282.63545 -273.054391 398.9350
## 2049       62.94032 -158.7285255 284.60916 -276.072922 401.9536
## 2050       62.94032 -160.6848176 286.56545 -279.064812 404.9454
## 2051       62.94032 -162.6241437 288.50478 -282.030756 407.9114
## 2052       62.94032 -164.5469377 290.42757 -284.971415 410.8520
## 2053       62.94032 -166.4536153 292.33425 -287.887427 413.7681
## 2054       62.94032 -168.3445750 294.22521 -290.779400 416.6600
## 2055       62.94032 -170.2201994 296.10083 -293.647920 419.5286
## 2056       62.94031 -172.0808555 297.96149 -296.493548 422.3742
## 2057       62.94031 -173.9268961 299.80753 -299.316823 425.1975
## 2058       62.94031 -175.7586603 301.63929 -302.118265 427.9989
## 2059       62.94031 -177.5764743 303.45710 -304.898371 430.7790
## 2060       62.94031 -179.3806520 305.26128 -307.657623 433.5383
## 2061       62.94031 -181.1714957 307.05213 -310.396482 436.2771
## 2062       62.94031 -182.9492969 308.82993 -313.115395 438.9960
## 2063       62.94031 -184.7143364 310.59497 -315.814790 441.6954
## 2064       62.94031 -186.4668852 312.34751 -318.495082 444.3757
## 2065       62.94031 -188.2072046 314.08783 -321.156670 447.0373
## 2066       62.94031 -189.9355473 315.81618 -323.799942 449.6806
## 2067       62.94031 -191.6521571 317.53279 -326.425271 452.3059
## 2068       62.94031 -193.3572698 319.23790 -329.033015 454.9136
## 2069       62.94031 -195.0511133 320.93174 -331.623526 457.5042
## 2070       62.94031 -196.7339082 322.61454 -334.197138 460.0778
## 2071       62.94031 -198.4058679 324.28650 -336.754180 462.6348
## 2072       62.94031 -200.0671990 325.94783 -339.294967 465.1756
## 2073       62.94031 -201.7181018 327.59873 -341.819804 467.7004
## 2074       62.94031 -203.3587700 329.23940 -344.328990 470.2096
## 2075       62.94031 -204.9893918 330.87002 -346.822811 472.7034
## 2076       62.94031 -206.6101495 332.49078 -349.301546 475.1822
## 2077       62.94031 -208.2212200 334.10185 -351.765465 477.6461
## 2078       62.94031 -209.8227748 335.70340 -354.214832 480.0955
## 2079       62.94031 -211.4149807 337.29561 -356.649901 482.5305
## 2080       62.94031 -212.9979995 338.87863 -359.070919 484.9515
## 2081       62.94031 -214.5719884 340.45262 -361.478128 487.3588
## 2082       62.94031 -216.1371001 342.01773 -363.871759 489.7524
## 2083       62.94031 -217.6934833 343.57411 -366.252042 492.1327
## 2084       62.94031 -219.2412823 345.12191 -368.619196 494.4998
## 2085       62.94031 -220.7806377 346.66127 -370.973437 496.8541
## 2086       62.94031 -222.3116861 348.19231 -373.314974 499.1956
## 2087       62.94031 -223.8345605 349.71519 -375.644009 501.5246
## 2088       62.94031 -225.3493906 351.23002 -377.960742 503.8414
## 2089       62.94031 -226.8563024 352.73693 -380.265365 506.1460
## 2090       62.94031 -228.3554189 354.23605 -382.558065 508.4387
## 2091       62.94031 -229.8468598 355.72749 -384.839027 510.7197
## 2092       62.94031 -231.3307417 357.21137 -387.108429 512.9891
## 2093       62.94031 -232.8071785 358.68781 -389.366444 515.2471
summary(holt4)
## 
## Forecast method: Damped Holt's method
## 
## Model Information:
## Damped Holt's method 
## 
## Call:
##  holt(y = eggs, h = 100, damped = TRUE, phi = 0.9) 
## 
##   Smoothing parameters:
##     alpha = 0.8464 
##     beta  = 1e-04 
##     phi   = 0.9 
## 
##   Initial states:
##     l = 297.4547 
##     b = -3.1897 
## 
##   sigma:  27.3608
## 
##      AIC     AICc      BIC 
## 1054.045 1054.727 1066.761 
## 
## Error measures:
##                     ME     RMSE      MAE       MPE     MAPE      MASE
## Training set -2.584906 26.62317 19.53231 -2.832104 10.10674 0.9634993
##                      ACF1
## Training set -0.005019785
## 
## Forecasts:
##      Point Forecast        Lo 80     Hi 80       Lo 95    Hi 95
## 1994       62.91509   27.8508199  97.97936    9.288917 116.5413
## 1995       62.91168   16.9725610 108.85079   -7.346138 133.1695
## 1996       62.90861    8.2142702 117.60294  -20.739162 146.5564
## 1997       62.90584    0.6749005 125.13679  -32.268170 158.0799
## 1998       62.90336   -6.0462386 131.85295  -42.545949 168.3527
## 1999       62.90112  -12.1690224 137.97126  -51.908754 177.7110
## 2000       62.89910  -17.8295529 143.62776  -60.564722 186.3629
## 2001       62.89729  -23.1190194 148.91360  -68.653303 194.4479
## 2002       62.89566  -28.1020598 153.89338  -76.273342 202.0647
## 2003       62.89419  -32.8264695 158.61485  -83.497926 209.2863
## 2004       62.89287  -37.3287720 163.11451  -90.382903 216.1686
## 2005       62.89168  -41.6376237 167.42098  -96.972094 222.7555
## 2006       62.89061  -45.7760001 171.55722 -103.300628 229.0818
## 2007       62.88964  -49.7626585 175.54195 -109.397185 235.1765
## 2008       62.88878  -53.6131483 179.39070 -115.285542 241.0631
## 2009       62.88800  -57.3405307 183.11652 -120.985669 246.7617
## 2010       62.88729  -60.9559032 186.73049 -126.514532 252.2891
## 2011       62.88666  -64.4687896 190.24211 -131.886693 257.6600
## 2012       62.88609  -67.8874358 193.65962 -137.114760 262.8869
## 2013       62.88558  -71.2190377 196.99020 -142.209735 267.9809
## 2014       62.88512  -74.4699198 200.24016 -147.181286 272.9515
## 2015       62.88471  -77.6456758 203.41509 -152.037966 277.8074
## 2016       62.88433  -80.7512818 206.51995 -156.787383 282.5560
## 2017       62.88400  -83.7911879 209.55918 -161.436340 287.2043
## 2018       62.88369  -86.7693925 212.53678 -165.990951 291.7583
## 2019       62.88342  -89.6895046 215.45635 -170.456733 296.2236
## 2020       62.88318  -92.5547944 218.32115 -174.838686 300.6050
## 2021       62.88296  -95.3682365 221.13415 -179.141358 304.9073
## 2022       62.88276  -98.1325460 223.89806 -183.368899 309.1344
## 2023       62.88258 -100.8502089 226.61537 -187.525111 313.2903
## 2024       62.88242 -103.5235087 229.28835 -191.613486 317.3783
## 2025       62.88227 -106.1545483 231.91910 -195.637237 321.4018
## 2026       62.88214 -108.7452698 234.50956 -199.599335 325.3636
## 2027       62.88203 -111.2974709 237.06152 -203.502527 329.2666
## 2028       62.88192 -113.8128195 239.57666 -207.349365 333.1132
## 2029       62.88183 -116.2928668 242.05652 -211.142220 336.9059
## 2030       62.88174 -118.7390580 244.50254 -214.883301 340.6468
## 2031       62.88166 -121.1527424 246.91607 -218.574672 344.3380
## 2032       62.88160 -123.5351821 249.29837 -222.218263 347.9815
## 2033       62.88153 -125.8875595 251.65062 -225.815881 351.5789
## 2034       62.88148 -128.2109843 253.97394 -229.369223 355.1322
## 2035       62.88143 -130.5064997 256.26935 -232.879884 358.6427
## 2036       62.88138 -132.7750876 258.53785 -236.349366 362.1121
## 2037       62.88134 -135.0176737 260.78035 -239.779083 365.5418
## 2038       62.88130 -137.2351319 262.99774 -243.170374 368.9330
## 2039       62.88127 -139.4282883 265.19083 -246.524499 372.2870
## 2040       62.88124 -141.5979246 267.36041 -249.842656 375.6051
## 2041       62.88121 -143.7447815 269.50721 -253.125976 378.8884
## 2042       62.88119 -145.8695617 271.63194 -256.375534 382.1379
## 2043       62.88117 -147.9729324 273.73527 -259.592351 385.3547
## 2044       62.88115 -150.0555280 275.81782 -262.777395 388.5397
## 2045       62.88113 -152.1179521 277.88021 -265.931592 391.6939
## 2046       62.88111 -154.1607797 279.92301 -269.055818 394.8180
## 2047       62.88110 -156.1845588 281.94676 -272.150914 397.9131
## 2048       62.88109 -158.1898125 283.95199 -275.217678 400.9799
## 2049       62.88108 -160.1770405 285.93919 -278.256875 404.0190
## 2050       62.88107 -162.1467202 287.90885 -281.269235 407.0314
## 2051       62.88106 -164.0993084 289.86142 -284.255456 410.0176
## 2052       62.88105 -166.0352425 291.79734 -287.216207 412.9783
## 2053       62.88104 -167.9549414 293.71702 -290.152129 415.9142
## 2054       62.88103 -169.8588068 295.62087 -293.063836 418.8259
## 2055       62.88103 -171.7472242 297.50928 -295.951918 421.7140
## 2056       62.88102 -173.6205635 299.38261 -298.816940 424.5790
## 2057       62.88102 -175.4791804 301.24121 -301.659447 427.4215
## 2058       62.88101 -177.3234164 303.08544 -304.479960 430.2420
## 2059       62.88101 -179.1536003 304.91562 -307.278983 433.0410
## 2060       62.88101 -180.9700486 306.73206 -310.056999 435.8190
## 2061       62.88100 -182.7730658 308.53507 -312.814474 438.5765
## 2062       62.88100 -184.5629456 310.32494 -315.551857 441.3139
## 2063       62.88100 -186.3399711 312.10196 -318.269582 444.0316
## 2064       62.88099 -188.1044152 313.86640 -320.968065 446.7301
## 2065       62.88099 -189.8565415 315.61852 -323.647710 449.4097
## 2066       62.88099 -191.5966044 317.35858 -326.308905 452.0709
## 2067       62.88099 -193.3248497 319.08683 -328.952028 454.7140
## 2068       62.88099 -195.0415149 320.80349 -331.577440 457.3394
## 2069       62.88099 -196.7468297 322.50880 -334.185493 459.9475
## 2070       62.88098 -198.4410164 324.20298 -336.776527 462.5385
## 2071       62.88098 -200.1242899 325.88626 -339.350871 465.1128
## 2072       62.88098 -201.7968585 327.55882 -341.908844 467.6708
## 2073       62.88098 -203.4589239 329.22089 -344.450753 470.2127
## 2074       62.88098 -205.1106815 330.87264 -346.976898 472.7389
## 2075       62.88098 -206.7523208 332.51428 -349.487568 475.2495
## 2076       62.88098 -208.3840253 334.14598 -351.983044 477.7450
## 2077       62.88098 -210.0059734 335.76793 -354.463599 480.2256
## 2078       62.88098 -211.6183380 337.38029 -356.929498 482.6915
## 2079       62.88098 -213.2212869 338.98324 -359.380997 485.1430
## 2080       62.88098 -214.8149833 340.57694 -361.818345 487.5803
## 2081       62.88098 -216.3995855 342.16154 -364.241784 490.0037
## 2082       62.88098 -217.9752474 343.73720 -366.651551 492.4135
## 2083       62.88098 -219.5421188 345.30407 -369.047874 494.8098
## 2084       62.88098 -221.1003450 346.86230 -371.430975 497.1929
## 2085       62.88097 -222.6500676 348.41202 -373.801071 499.5630
## 2086       62.88097 -224.1914245 349.95337 -376.158373 501.9203
## 2087       62.88097 -225.7245494 351.48650 -378.503085 504.2650
## 2088       62.88097 -227.2495731 353.01152 -380.835407 506.5974
## 2089       62.88097 -228.7666226 354.52857 -383.155534 508.9175
## 2090       62.88097 -230.2758216 356.03777 -385.463655 511.2256
## 2091       62.88097 -231.7772908 357.53924 -387.759954 513.5219
## 2092       62.88097 -233.2711477 359.03309 -390.044611 515.8066
## 2093       62.88097 -234.7575070 360.51945 -392.317801 518.0797
summary(holt5)
## 
## Forecast method: Damped Holt's method
## 
## Model Information:
## Damped Holt's method 
## 
## Call:
##  holt(y = eggs, h = 100, damped = TRUE, phi = 0.95) 
## 
##   Smoothing parameters:
##     alpha = 0.8336 
##     beta  = 1e-04 
##     phi   = 0.95 
## 
##   Initial states:
##     l = 309.2389 
##     b = -3.434 
## 
##   sigma:  27.419
## 
##      AIC     AICc      BIC 
## 1054.444 1055.126 1067.160 
## 
## Error measures:
##                     ME     RMSE      MAE       MPE     MAPE      MASE
## Training set -2.313366 26.67977 19.57767 -2.729662 10.11133 0.9657369
##                     ACF1
## Training set 0.001330777
## 
## Forecasts:
##      Point Forecast       Lo 80     Hi 80       Lo 95    Hi 95
## 1994       62.95709   27.818277  98.09591    9.216912 116.6973
## 1995       62.92510   17.177408 108.67280   -7.039958 132.8902
## 1996       62.89471    8.570201 117.21922  -20.187459 145.9769
## 1997       62.86584    1.143640 124.58805  -31.530121 157.2618
## 1998       62.83842   -5.486366 131.16320  -41.655320 167.3322
## 1999       62.81236  -11.531978 137.15670  -50.887494 176.5122
## 2000       62.78761  -17.125076 142.70029  -59.428295 185.0035
## 2001       62.76409  -22.354279 147.88247  -67.413224 192.9414
## 2002       62.74175  -27.282544 152.76605  -74.938529 200.4220
## 2003       62.72053  -31.956504 157.39757  -82.075500 207.5166
## 2004       62.70037  -36.411845 161.81259  -88.878684 214.2794
## 2005       62.68122  -40.676602 166.03904  -95.390927 220.7534
## 2006       62.66302  -44.773274 170.09932 -101.646614 226.9727
## 2007       62.64574  -48.720248 174.01172 -107.673839 232.9653
## 2008       62.62932  -52.532778 177.79141 -113.495908 238.7545
## 2009       62.61372  -56.223688 181.45112 -119.132410 244.3598
## 2010       62.59890  -59.803883 185.00168 -124.600000 249.7978
## 2011       62.58482  -63.282725 188.45236 -129.912976 255.0826
## 2012       62.57144  -66.668326 191.81121 -135.083727 260.2266
## 2013       62.55874  -69.967772 195.08524 -140.123067 265.2405
## 2014       62.54666  -73.187291 198.28062 -145.040507 270.1338
## 2015       62.53520  -76.332396 201.40279 -149.844459 274.9149
## 2016       62.52430  -79.407993 204.45660 -154.542412 279.5910
## 2017       62.51395  -82.418474 207.44638 -159.141066 284.1690
## 2018       62.50412  -85.367784 210.37603 -163.646442 288.6547
## 2019       62.49478  -88.259488 213.24905 -168.063977 293.0535
## 2020       62.48591  -91.096817 216.06863 -172.398600 297.3704
## 2021       62.47748  -93.882710 218.83767 -176.654793 301.6097
## 2022       62.46947  -96.619853 221.55879 -180.836653 305.7756
## 2023       62.46186  -99.310705 224.23443 -184.947929 309.8717
## 2024       62.45463 -101.957526 226.86679 -188.992067 313.9013
## 2025       62.44777 -104.562398 229.45793 -192.972240 317.8678
## 2026       62.44125 -107.127245 232.00974 -196.891381 321.7739
## 2027       62.43505 -109.653847 234.52394 -200.752205 325.6223
## 2028       62.42916 -112.143858 237.00218 -204.557232 329.4156
## 2029       62.42357 -114.598815 239.44595 -208.308805 333.1559
## 2030       62.41826 -117.020152 241.85667 -212.009108 336.8456
## 2031       62.41321 -119.409208 244.23563 -215.660182 340.4866
## 2032       62.40841 -121.767235 246.58406 -219.263934 344.0808
## 2033       62.40386 -124.095406 248.90313 -222.822154 347.6299
## 2034       62.39953 -126.394824 251.19389 -226.336519 351.1356
## 2035       62.39542 -128.666524 253.45737 -229.808608 354.5995
## 2036       62.39152 -130.911481 255.69451 -233.239907 358.0229
## 2037       62.38781 -133.130616 257.90623 -236.631817 361.4074
## 2038       62.38428 -135.324797 260.09336 -239.985660 364.7542
## 2039       62.38093 -137.494844 262.25671 -243.302689 368.0646
## 2040       62.37775 -139.641536 264.39704 -246.584086 371.3396
## 2041       62.37473 -141.765607 266.51507 -249.830974 374.5804
## 2042       62.37186 -143.867758 268.61148 -253.044416 377.7881
## 2043       62.36913 -145.948651 270.68691 -256.225424 380.9637
## 2044       62.36654 -148.008918 272.74200 -259.374958 384.1080
## 2045       62.36408 -150.049158 274.77732 -262.493934 387.2221
## 2046       62.36174 -152.069945 276.79343 -265.583222 390.3067
## 2047       62.35952 -154.071822 278.79086 -268.643654 393.3627
## 2048       62.35741 -156.055311 280.77013 -271.676022 396.3908
## 2049       62.35540 -158.020909 282.73172 -274.681083 399.3919
## 2050       62.35350 -159.969091 284.67609 -277.659562 402.3666
## 2051       62.35169 -161.900312 286.60369 -280.612151 405.3155
## 2052       62.34997 -163.815006 288.51495 -283.539513 408.2395
## 2053       62.34834 -165.713590 290.41027 -286.442283 411.1390
## 2054       62.34679 -167.596465 292.29004 -289.321070 414.0146
## 2055       62.34531 -169.464014 294.15464 -292.176460 416.8671
## 2056       62.34391 -171.316605 296.00443 -295.009012 419.6968
## 2057       62.34258 -173.154592 297.83976 -297.819266 422.5044
## 2058       62.34132 -174.978315 299.66095 -300.607741 425.2904
## 2059       62.34012 -176.788101 301.46834 -303.374935 428.0552
## 2060       62.33898 -178.584265 303.26222 -306.121327 430.7993
## 2061       62.33790 -180.367111 305.04290 -308.847380 433.5232
## 2062       62.33687 -182.136930 306.81066 -311.553540 436.2273
## 2063       62.33589 -183.894003 308.56578 -314.240235 438.9120
## 2064       62.33496 -185.638603 310.30852 -316.907879 441.5778
## 2065       62.33408 -187.370993 312.03915 -319.556872 444.2250
## 2066       62.33324 -189.091423 313.75790 -322.187600 446.8541
## 2067       62.33244 -190.800141 315.46503 -324.800436 449.4653
## 2068       62.33169 -192.497381 317.16075 -327.395740 452.0591
## 2069       62.33097 -194.183372 318.84531 -329.973861 454.6358
## 2070       62.33029 -195.858335 320.51891 -332.535135 457.1957
## 2071       62.32964 -197.522484 322.18176 -335.079888 459.7392
## 2072       62.32902 -199.176027 323.83407 -337.608436 462.2665
## 2073       62.32844 -200.819162 325.47603 -340.121086 464.7780
## 2074       62.32788 -202.452086 327.10784 -342.618133 467.2739
## 2075       62.32735 -204.074986 328.72969 -345.099865 469.7546
## 2076       62.32685 -205.688045 330.34174 -347.566559 472.2203
## 2077       62.32637 -207.291440 331.94418 -350.018488 474.6712
## 2078       62.32592 -208.885342 333.53718 -352.455911 477.1077
## 2079       62.32549 -210.469919 335.12090 -354.879085 479.5301
## 2080       62.32508 -212.045333 336.69549 -357.288257 481.9384
## 2081       62.32469 -213.611742 338.26112 -359.683666 484.3330
## 2082       62.32432 -215.169297 339.81794 -362.065546 486.7142
## 2083       62.32397 -216.718148 341.36609 -364.434123 489.0821
## 2084       62.32364 -218.258439 342.90572 -366.789619 491.4369
## 2085       62.32332 -219.790311 344.43696 -369.132247 493.7789
## 2086       62.32302 -221.313900 345.95995 -371.462217 496.1083
## 2087       62.32274 -222.829341 347.47481 -373.779732 498.4252
## 2088       62.32247 -224.336761 348.98169 -376.084989 500.7299
## 2089       62.32221 -225.836288 350.48070 -378.378182 503.0226
## 2090       62.32196 -227.328045 351.97197 -380.659497 505.3034
## 2091       62.32173 -228.812150 353.45561 -382.929117 507.5726
## 2092       62.32151 -230.288722 354.93174 -385.187221 509.8302
## 2093       62.32130 -231.757873 356.40047 -387.433983 512.0766
# The Holt linear model produced a lower RMSE compared to all the damped models

# 8

# a
#library(readxl)
#file.choose()
#View(retail)
#retailts = ts(retail$A3349335T, frequency = 12, start = c(1982,12), end = c(2013,12))
#autoplot(retailts)
# You must use multiplicative seasonality because the variation of seasonality increases in magnitude throughout the data

# b

#retailhw = hw(retailts,seasonal="multiplicative", h = 12)
#retailhwdamped = hw(retailts,seasonal="multiplicative", damped = TRUE, phi = .8, h = 12)
#autoplot(retailhw)
#autoplot(retailhwdamped)

# c

#summary(retailhw)
#RMSE = 25.20381
#summary(retailhwdamped)
#RMSE = 26.6487
#The regular holt-winters produces the better model due to the lower RMSE

# d
#checkresiduals(retailhw)
#residuals look like white noise

# e

#retailtrain <- window(retailts, end=c(2010, 12))
#retailtest <- window(retailts, start=c(2011,1))
#fit_snaive <- snaive(train, h=36)
#fit1_hw <- hw(train, h=36, seasonal='multiplicative', damped=F)
#fit2_hw <- hw(train, h=36, seasonal='additive', damped=F, lambda='auto')
#summary(fit_snaive)
#RSME = 72.66005
#summary(fit1_hw)
#RMSE = 25.20381
#summary(fit2_hw)
#RMSE = 25.96042
#With the lowest RMSE, the HW Multiplicative method with no damped trend produces the best forecast

# 9

#train <- ts(as.vector(myts), start=c(1982,4), end=c(2010,12), frequency = 12)
#lambda <- BoxCox.lambda(train)
#train.bc <- BoxCox(train, lambda)
#fit.stl <- stl(train.bc, s.window='periodic', robust=T)
#autoplot(fit.stl)
#train.bc.seadj <- train.bc - fit.stl$time.series[,'seasonal']
#autoplot(train.bc.seadj)
#fit.ets <- ets(train.bc.seadj)
#summary(fit.ets)
#ANN is the best fitting ETS model
#fc <- forecast(fit.ets, h=36)
#autoplot(fc)
#forecast is a straight line at the mean, as the model predicts no trend and no seasonality and is not a better model

# 10

View(ukcars)
tscars = ts(ukcars, start = c(1977, 1), end = c(2005, 3), frequency = 12)
tscars
##          Jan     Feb     Mar     Apr     May     Jun     Jul     Aug
## 1977 330.371 371.051 270.670 343.880 358.491 362.822 261.281 240.355
## 1978 298.127 251.464 181.555 192.598 245.652 245.526 225.261 238.211
## 1979 266.150 287.251 225.883 265.313 272.759 234.134 196.462 205.551
## 1980 253.757 267.016 220.388 277.801 283.233 302.072 259.720 297.658
## 1981 356.004 361.540 270.433 311.105 326.688 327.059 274.257 367.606
## 1982 343.318 343.429 275.386 329.747 364.521 378.448 300.798 331.757
## 1983 421.646 416.823 311.713 381.902 422.982 427.722 376.850 458.580
## 1984 462.442 468.232 403.636 413.948 460.496 448.932 407.787 469.408
## 1985 387.100 372.395 335.790 397.080 449.755 402.252 391.847 385.890
## 1986 445.458 428.202 379.048 394.042 432.796 330.371 371.051 270.670
## 1987 240.355 325.382 316.700 171.153 257.217 298.127 251.464 181.555
## 1988 238.211 257.385 228.461 175.371 226.462 266.150 287.251 225.883
## 1989 205.551 291.283 284.422 221.571 250.697 253.757 267.016 220.388
## 1990 297.658 306.129 322.106 256.723 341.877 356.004 361.540 270.433
## 1991 367.606 346.163 348.211 250.008 292.518 343.318 343.429 275.386
## 1992 331.757 362.536 389.133 323.322 391.832 421.646 416.823 311.713
## 1993 458.580 436.225 441.487 369.566 450.723 462.442 468.232 403.636
## 1994 469.408 494.311 433.240 335.106 378.795 387.100 372.395 335.790
## 1995 385.890 424.325 433.280 391.213 408.740 445.458 428.202 379.048
## 1996 270.670 343.880 358.491 362.822 261.281 240.355 325.382 316.700
## 1997 181.555 192.598 245.652 245.526 225.261 238.211 257.385 228.461
## 1998 225.883 265.313 272.759 234.134 196.462 205.551 291.283 284.422
## 1999 220.388 277.801 283.233 302.072 259.720 297.658 306.129 322.106
## 2000 270.433 311.105 326.688 327.059 274.257 367.606 346.163 348.211
## 2001 275.386 329.747 364.521 378.448 300.798 331.757 362.536 389.133
## 2002 311.713 381.902 422.982 427.722 376.850 458.580 436.225 441.487
## 2003 403.636 413.948 460.496 448.932 407.787 469.408 494.311 433.240
## 2004 335.790 397.080 449.755 402.252 391.847 385.890 424.325 433.280
## 2005 379.048 394.042 432.796                                        
##          Sep     Oct     Nov     Dec
## 1977 325.382 316.700 171.153 257.217
## 1978 257.385 228.461 175.371 226.462
## 1979 291.283 284.422 221.571 250.697
## 1980 306.129 322.106 256.723 341.877
## 1981 346.163 348.211 250.008 292.518
## 1982 362.536 389.133 323.322 391.832
## 1983 436.225 441.487 369.566 450.723
## 1984 494.311 433.240 335.106 378.795
## 1985 424.325 433.280 391.213 408.740
## 1986 343.880 358.491 362.822 261.281
## 1987 192.598 245.652 245.526 225.261
## 1988 265.313 272.759 234.134 196.462
## 1989 277.801 283.233 302.072 259.720
## 1990 311.105 326.688 327.059 274.257
## 1991 329.747 364.521 378.448 300.798
## 1992 381.902 422.982 427.722 376.850
## 1993 413.948 460.496 448.932 407.787
## 1994 397.080 449.755 402.252 391.847
## 1995 394.042 432.796 330.371 371.051
## 1996 171.153 257.217 298.127 251.464
## 1997 175.371 226.462 266.150 287.251
## 1998 221.571 250.697 253.757 267.016
## 1999 256.723 341.877 356.004 361.540
## 2000 250.008 292.518 343.318 343.429
## 2001 323.322 391.832 421.646 416.823
## 2002 369.566 450.723 462.442 468.232
## 2003 335.106 378.795 387.100 372.395
## 2004 391.213 408.740 445.458 428.202
## 2005
# a

autoplot(tscars)

#Two seasonality components appear for day of the week and monthly, no trend

# b

mstl(tscars)
##             Data    Trend   Seasonal12    Remainder
## Jan 1977 330.371 345.8690  20.64175486 -36.13973682
## Feb 1977 371.051 337.8915  24.93012742   8.22941719
## Mar 1977 270.670 329.9139 -47.12678711 -12.11714171
## Apr 1977 343.880 321.9364  -3.58162392  25.52522168
## May 1977 358.491 314.0014  24.02169380  20.46788498
## Jun 1977 362.822 306.0664  18.54553900  38.21002080
## Jul 1977 261.281 298.1315 -30.28323002  -6.56722915
## Aug 1977 240.355 290.1389  -3.16599390 -46.61790810
## Sep 1977 325.382 282.1463  27.26274846  15.97290671
## Oct 1977 316.700 274.1538  23.71988475  18.82632759
## Nov 1977 171.153 266.3722 -54.07184792 -41.14733359
## Dec 1977 257.217 258.5906  -0.57536999  -0.79820536
## Jan 1978 298.127 250.8090  20.60138573  26.71664508
## Feb 1978 251.464 246.3740  24.67842175 -19.58844372
## Mar 1978 181.555 241.9391 -47.01307871 -13.37099605
## Apr 1978 192.598 237.5041  -4.05702863 -40.84909891
## May 1978 245.652 235.5648  24.17314164 -14.08591430
## Jun 1978 245.526 233.6254  18.16613398  -6.26555176
## Jul 1978 225.261 231.6861 -29.93440441  23.50934150
## Aug 1978 238.211 233.2590  -2.81078972   7.76278005
## Sep 1978 257.385 234.8320  26.98321328  -4.43016971
## Oct 1978 228.461 236.4049  23.62809764 -31.57200083
## Nov 1978 175.371 237.7121 -53.21433537  -9.12680659
## Dec 1978 226.462 239.0194  -0.84465677 -11.71272395
## Jan 1979 266.150 240.3266  20.55188122   5.27149930
## Feb 1979 287.251 241.2647  24.41784742  21.56847432
## Mar 1979 225.883 242.2027 -46.90797224  30.58823520
## Apr 1979 265.313 243.1408  -4.54057117  26.71277534
## May 1979 272.759 244.5736  24.31691576   3.86845057
## Jun 1979 234.134 246.0065  17.77979071 -29.65226222
## Jul 1979 196.462 247.4393 -29.59178155 -21.38552780
## Aug 1979 205.551 248.0081  -2.46146977 -39.99562020
## Sep 1979 291.283 248.5769  26.69811238  16.00801702
## Oct 1979 284.422 249.1457  23.52970885  11.74663991
## Nov 1979 221.571 252.0019 -52.36446045  21.93357227
## Dec 1979 250.697 254.8581  -1.12399562  -3.03712949
## Jan 1980 253.757 257.7144  20.61660354 -24.57396559
## Feb 1980 267.016 262.0847  24.00567540 -19.07441316
## Mar 1980 220.388 266.4551 -46.29724640   0.23013293
## Apr 1980 277.801 270.8255  -5.37424887  12.34975968
## May 1980 283.233 276.1474  24.40285464 -17.31727164
## Jun 1980 302.072 281.4693  16.71278796   3.88986722
## Jul 1980 259.720 286.7913 -28.91893269   1.84766006
## Aug 1980 297.658 292.2708  -1.90103243   7.28821059
## Sep 1980 306.129 297.7504  26.04943683 -17.67080787
## Oct 1980 322.106 303.2299  23.29638239  -4.42030264
## Nov 1980 256.723 306.6454 -50.36339962   0.44099376
## Dec 1980 341.877 310.0609  -1.58037404  33.39648258
## Jan 1981 356.004 313.4764  20.63170232  21.89592060
## Feb 1981 361.540 315.7451  23.54924618  22.24569561
## Mar 1981 270.433 318.0137 -45.72541142  -1.85532793
## Apr 1981 311.105 320.2824  -6.24043570  -2.93698479
## May 1981 326.688 320.1010  24.46266611 -17.87563803
## Jun 1981 327.059 319.9195  15.62404931  -8.48457266
## Jul 1981 274.257 319.7381 -28.26342821 -17.21764656
## Aug 1981 367.606 319.6907  -1.35850555  49.27376254
## Sep 1981 346.163 319.6434  25.38228473   1.13730403
## Oct 1981 348.211 319.5961  23.03539660   5.57952392
## Nov 1981 250.008 321.3133 -48.39918090 -22.90616260
## Dec 1981 292.518 323.0306  -2.09195509 -28.42065243
## Jan 1982 343.318 324.7479  19.96232012  -1.39219168
## Feb 1982 343.429 326.9783  22.82010164  -6.36937788
## Mar 1982 275.386 329.2087 -44.32816481  -9.49451611
## Apr 1982 329.747 331.4391  -8.18789115   6.49580555
## May 1982 364.521 336.4983  25.00384499   3.01883557
## Jun 1982 378.448 341.5576  13.98516475  22.90528197
## Jul 1982 300.798 346.6168 -26.62875006 -19.19003706
## Aug 1982 331.757 351.9281  -0.08304182 -20.08810609
## Sep 1982 362.536 357.2395  23.22241613 -17.92592484
## Oct 1982 389.133 362.5509  23.02735388   3.55477661
## Nov 1982 323.322 368.0195 -43.62007154  -1.07744086
## Dec 1982 391.832 373.4882  -3.36061239  21.70445710
## Jan 1983 421.646 378.9568  19.09776044  23.59144138
## Feb 1983 416.823 384.9664  21.92962494   9.92699181
## Mar 1983 311.713 390.9760 -43.05840502 -36.20456327
## Apr 1983 381.902 396.9856 -10.22233806  -4.86121529
## May 1983 422.982 401.9104  25.49852778  -4.42691467
## Jun 1983 427.722 406.8352  12.34315843   8.54362115
## Jul 1983 376.850 411.7601 -24.95381934  -9.95623462
## Aug 1983 458.580 416.0485   1.27971183  41.25179230
## Sep 1983 436.225 420.3369  21.19687480  -5.30881260
## Oct 1983 441.487 424.6254  23.19968245  -6.33806216
## Nov 1983 369.566 427.7129 -38.61454689 -19.53234118
## Dec 1983 450.723 430.8004  -4.35957048  24.28217405
## Jan 1984 462.442 433.8879  13.86403125  14.69006396
## Feb 1984 468.232 434.9588  22.29541305  10.97779615
## Mar 1984 403.636 436.0297 -35.13169052   2.73801370
## Apr 1984 413.948 437.1006 -17.49116783  -5.66139501
## May 1984 460.496 433.9535  24.60232584   1.94014674
## Jun 1984 448.932 430.8065  12.75253264   5.37297535
## Jul 1984 407.787 427.6595 -16.40951479  -3.46294182
## Aug 1984 469.408 422.7830  -5.81858660  52.44358023
## Sep 1984 494.311 417.9066  18.17568350  58.22876037
## Oct 1984 433.240 413.0301  22.74195442  -2.53206033
## Nov 1984 335.106 409.4963 -29.37416050 -45.01617285
## Dec 1984 378.795 405.9626  -9.02922579 -18.13833503
## Jan 1985 387.100 402.4288   9.01734613 -24.34613440
## Feb 1985 372.395 400.1413  22.99901404 -50.74526487
## Mar 1985 335.790 397.8537 -26.91639431 -35.14731906
## Apr 1985 397.080 395.5662 -24.52571153  26.03953560
## May 1985 449.755 397.4668  23.88611431  28.40207614
## Jun 1985 402.252 399.3674  13.29119070 -10.40663388
## Jul 1985 391.847 401.2681  -7.78663293  -1.63444386
## Aug 1985 385.890 403.6360 -12.87487899  -4.87109120
## Sep 1985 424.325 406.0039  15.15992697   3.16120944
## Oct 1985 433.280 408.3718  22.27118209   2.63706093
## Nov 1985 391.213 405.9691 -20.16529752   5.40919810
## Dec 1985 408.740 403.5664 -13.72864147  18.90219962
## Jan 1986 445.458 401.1638   4.48392999  39.81028571
## Feb 1986 428.202 395.2864  23.02882468   9.88678384
## Mar 1986 379.048 389.4090 -15.51169060   5.15069195
## Apr 1986 394.042 383.5316 -30.48451843  40.99491260
## May 1986 432.796 374.4995  21.07386725  37.22266807
## Jun 1986 330.371 365.4673  13.67459933 -48.77092287
## Jul 1986 371.051 356.4352   1.42299517  13.19282244
## Aug 1986 270.670 345.2802 -22.04012469 -52.57003744
## Sep 1986 343.880 334.1251  11.89960095  -2.14474284
## Oct 1986 358.491 322.9701  21.39209089  14.12878747
## Nov 1986 362.822 312.7121  -9.84412142  59.95404432
## Dec 1986 261.281 302.4540 -19.41224443 -21.76078815
## Jan 1987 240.355 292.1960   0.08715969 -51.92814774
## Feb 1987 325.382 283.1980  23.16386012  19.02014651
## Mar 1987 316.700 274.2000  -4.03318312  46.53318443
## Apr 1987 171.153 265.2020 -36.41006050 -57.63894350
## May 1987 257.217 258.5880  18.25434608 -19.62531977
## Jun 1987 298.127 251.9739  14.01131812  32.14173852
## Jul 1987 251.464 245.3599  10.54651769  -4.44243074
## Aug 1987 181.555 241.6793 -31.32059470 -28.80373906
## Sep 1987 192.598 237.9988   8.49493190 -53.89568638
## Oct 1987 245.652 234.3182  20.35641426  -9.02258945
## Nov 1987 245.526 233.7109   0.30822683  11.50685559
## Dec 1987 225.261 233.1037 -25.25722725  17.41456728
## Jan 1988 238.211 232.4964  -0.02881577   5.74341340
## Feb 1988 257.385 234.5285  23.62756361  -0.77108876
## Mar 1988 228.461 236.5606   5.64534444 -13.74499238
## Apr 1988 175.371 238.5928 -42.33396845 -20.88780228
## May 1988 226.462 239.3064  13.92693344 -26.77137709
## Jun 1988 266.150 240.0201  17.19853575   8.93134767
## Jul 1988 287.251 240.7338  16.50546003  30.01175048
## Aug 1988 225.883 242.0988 -39.25742003  23.04163800
## Sep 1988 265.313 243.4638   3.05013370  18.79909174
## Oct 1988 272.759 244.8288  20.45270588   7.47752702
## Nov 1988 234.134 245.8812   7.95040003 -19.69755804
## Dec 1988 196.462 246.9335 -28.68456766 -21.78698126
## Jan 1989 205.551 247.9859  -0.11484161 -42.32009823
## Feb 1989 291.283 249.0261  24.09986978  18.15704832
## Mar 1989 284.422 250.0662  15.31112775  19.04464830
## Apr 1989 221.571 251.1064 -48.29741660  18.76205060
## May 1989 250.697 254.7455   9.53318462 -13.58172497
## Jun 1989 253.757 258.3847  20.28804953 -24.91576423
## Jul 1989 267.016 262.0239  22.33533082 -17.34321986
## Aug 1989 220.388 266.5392 -47.36135918   1.21013891
## Sep 1989 277.801 271.0546  -2.59982062   9.34626912
## Oct 1989 283.233 275.5699  20.30131684 -12.63819957
## Nov 1989 302.072 281.3750  15.30236800   5.39464319
## Dec 1989 259.720 287.1801 -32.44578788   4.98569300
## Jan 1990 297.658 292.9852   3.11910670   1.55369234
## Feb 1990 306.129 297.6988  25.35306069 -16.92287714
## Mar 1990 322.106 302.4124  18.79053022   0.90303782
## Apr 1990 256.723 307.1260 -50.67699847   0.27395101
## May 1990 341.877 310.1931   5.41776393  26.26613937
## Jun 1990 356.004 313.2601  21.40901699  21.33483709
## Jul 1990 361.540 316.3272  22.38531854  22.82748630
## Aug 1990 270.433 317.7855 -47.42982546   0.07735458
## Sep 1990 311.105 319.2437  -4.47281790  -3.66592871
## Oct 1990 326.688 320.7020  21.91884989 -15.93287221
## Nov 1990 327.059 320.0958  14.12786965  -7.16465348
## Dec 1990 274.257 319.4895 -31.29367481 -13.93887053
## Jan 1991 367.606 318.8833   5.97024940  42.75244375
## Feb 1991 346.163 319.6150  26.30298737   0.24503238
## Mar 1991 348.211 320.3467  22.04620984   5.81813651
## Apr 1991 250.008 321.0783 -53.19468733 -17.87563972
## May 1991 292.518 322.8770   1.24985209 -31.60887350
## Jun 1991 343.318 324.6757  22.55773353  -3.91544929
## Jul 1991 343.429 326.4744  22.54329559  -5.58870571
## Aug 1991 275.386 329.5224 -47.32723361  -6.80916459
## Sep 1991 329.747 332.5704  -6.11168823   3.28830196
## Oct 1991 364.521 335.6184  23.80466385   5.09796181
## Nov 1991 378.448 341.1966  13.25580620  23.99558709
## Dec 1991 300.798 346.7748 -29.84883962 -16.12799946
## Jan 1992 331.757 352.3531   3.72840287 -24.32447432
## Feb 1992 362.536 357.4666  23.86530412 -18.79587832
## Mar 1992 389.133 362.5801  22.74483365   3.80808939
## Apr 1992 323.322 367.6936 -45.88959725   1.51801755
## May 1992 391.832 373.5035  -1.55013525  19.87868509
## Jun 1992 421.646 379.3133  18.55918923  23.77349016
## Jul 1992 416.823 385.1232  22.17914870   9.52066024
## Aug 1992 311.713 390.8348 -42.02948155 -37.09231513
## Sep 1992 381.902 396.5464 -11.91061843  -2.73378388
## Oct 1992 422.982 402.2580  24.35792604  -3.63393399
## Nov 1992 427.722 406.9026  12.94039252   7.87895756
## Dec 1992 376.850 411.5473 -23.60229410 -11.09499780
## Jan 1993 458.580 416.1919   1.23048982  41.15757632
## Feb 1993 436.225 420.1796  21.21344668  -5.16809505
## Mar 1993 441.487 424.1674  23.27117562  -5.95153849
## Apr 1993 369.566 428.1551 -38.68018874 -19.90888864
## May 1993 450.723 430.7801  -4.36920388  24.31206715
## Jun 1993 462.442 433.4052  14.63144684  14.40535708
## Jul 1993 468.232 436.0303  21.97568691  10.22605766
## Aug 1993 403.636 435.8517 -36.48072727   4.26503621
## Sep 1993 413.948 435.6731 -17.36822927  -4.35689742
## Oct 1993 460.496 435.4946  25.33152208  -0.33008441
## Nov 1993 448.932 431.1240  13.12432716   4.68372184
## Dec 1993 407.787 426.7533 -16.80640971  -2.15992997
## Jan 1994 469.408 422.3827  -5.88205138  52.90732303
## Feb 1994 494.311 418.0037  18.15927580  58.14805062
## Mar 1994 433.240 413.6246  22.77295423  -3.15757303
## Apr 1994 335.106 409.2456 -29.42182143 -44.71774260
## May 1994 378.795 405.9399  -9.03919673 -18.10570299
## Jun 1994 387.100 402.6342   8.96268528 -24.49692070
## Jul 1994 372.395 399.3286  22.50923952 -49.44281063
## Aug 1994 335.790 398.2019 -26.17485153 -36.23702238
## Sep 1994 397.080 397.0752 -24.00647843  24.01130172
## Oct 1994 449.755 395.9485  23.46835237  30.33816812
## Nov 1994 402.252 398.7925  13.20933586  -9.74982912
## Dec 1994 391.847 401.6365  -7.54697093  -2.24253609
## Jan 1995 385.890 404.4805 -12.87794484  -5.71257594
## Feb 1995 424.325 405.6323  15.19730903   3.49535397
## Mar 1995 433.280 406.7842  22.34249333   4.15335345
## Apr 1995 391.213 407.9360 -20.09891897   3.37594953
## May 1995 408.740 403.9805 -13.64787978  18.40739846
## Jun 1995 445.458 400.0250   3.36113812  42.07186868
## Jul 1995 428.202 396.0695  23.11591113   9.01658379
## Aug 1995 379.048 389.2375 -15.78955575   5.60001585
## Sep 1995 394.042 382.4056 -30.55900651  42.19543179
## Oct 1995 432.796 375.5736  21.69260916  35.52978128
## Nov 1995 330.371 365.5800  13.38347649 -48.59251356
## Dec 1995 371.051 355.5865   1.79462142  13.66991397
## Jan 1996 270.670 345.5929 -22.08138545 -52.84150668
## Feb 1996 343.880 334.4539  11.86111987  -2.43505990
## Mar 1996 358.491 323.3150  21.35972504  13.81628704
## Apr 1996 362.822 312.1760  -9.85706322  60.50302740
## May 1996 261.281 302.3423 -19.42108068 -21.64026046
## Jun 1996 240.355 292.5086   0.95785381 -53.11150027
## Jul 1996 325.382 282.6750  23.21136934  19.49567889
## Aug 1996 316.700 274.2893  -4.38575121  46.79648729
## Sep 1996 171.153 265.9036 -36.47911813 -58.27145794
## Oct 1996 257.217 257.5179  17.93964966 -18.24053789
## Nov 1996 298.127 252.0446  15.01873044  31.06367553
## Dec 1996 251.464 246.5713   9.67639618  -4.78369603
## Jan 1997 181.555 241.0980 -31.30138247 -28.24162320
## Feb 1997 192.598 238.1471   8.51649869 -54.06562059
## Mar 1997 245.652 235.1962  20.37664913  -9.92088725
## Apr 1997 245.526 232.2454   0.38753057  12.89311509
## May 1997 225.261 232.9124 -25.18849791  17.53710130
## Jun 1997 238.211 233.5794  -1.44651112   6.07807226
## Jul 1997 257.385 234.2465  23.29888261  -0.16036374
## Aug 1997 228.461 236.1333   6.99322703 -14.66554359
## Sep 1997 175.371 238.0202 -42.44093740 -20.20821459
## Oct 1997 226.462 239.9070  14.12816636 -27.57315377
## Nov 1997 266.150 240.4300  16.57864441   9.14138929
## Dec 1997 287.251 240.9529  17.47538595  28.82266887
## Jan 1998 225.883 241.4759 -39.33119242  23.73826835
## Feb 1998 265.313 243.0463   2.96401028  19.30271514
## Mar 1998 272.759 244.6166  20.35692346   7.78545144
## Apr 1998 234.134 246.1870   6.60397107 -18.65694668
## May 1998 196.462 246.9336 -27.59691393 -22.87472462
## Jun 1998 205.551 247.6803   1.65620562 -43.78550709
## Jul 1998 291.283 248.4270  24.96335668  17.89267892
## Aug 1998 284.422 250.3409  12.64596948  21.43508195
## Sep 1998 221.571 252.2549 -46.16020064  15.47626790
## Oct 1998 250.697 254.1689  10.64800138 -14.11991828
## Nov 1998 253.757 258.2482  18.94104200 -23.43224620
## Dec 1998 267.016 262.3275  19.43896753 -14.75045903
## Jan 1999 220.388 266.4068 -47.16953729   1.15075850
## Feb 1999 277.801 271.2347  -2.44142852   9.00770548
## Mar 1999 283.233 276.0627  20.43983195 -13.26949923
## Apr 1999 302.072 280.8906  12.84440381   8.33698466
## May 1999 259.720 286.7885 -30.05997962   2.99152735
## Jun 1999 297.658 292.6863   4.61030415   0.36140283
## Jul 1999 306.129 298.5841  26.38524401 -18.84037777
## Aug 1999 322.106 302.5014  17.96007389   1.64454211
## Sep 1999 256.723 306.4186 -50.31415321   0.61851898
## Oct 1999 341.877 310.3359   6.65705701  24.88405853
## Nov 1999 356.004 313.1244  20.71657012  22.16301572
## Dec 1999 361.540 315.9129  20.78785053  24.83920560
## Jan 2000 270.433 318.7015 -47.81856456  -0.44990901
## Feb 2000 311.105 319.2924  -4.33564123  -3.85178721
## Mar 2000 326.688 319.8834  21.65010153 -14.84548484
## Apr 2000 327.059 320.4743  13.21534703  -6.63068521
## May 2000 274.257 319.9144 -29.79698113 -15.86045131
## Jun 2000 367.606 319.3545   5.66671876  42.58475454
## Jul 2000 346.163 318.7946  27.00478893   0.36359010
## Aug 2000 348.211 320.1952  18.91831812   9.09752403
## Sep 2000 250.008 321.5957 -50.42036728 -21.16732746
## Oct 2000 292.518 322.9962   4.97620617 -35.45443779
## Nov 2000 343.318 324.8277  20.81214004  -2.32184827
## Dec 2000 343.429 326.6592  19.72601681  -2.95620164
## Jan 2001 275.386 328.4907 -48.39327766  -4.71138377
## Feb 2001 329.747 332.5923  -6.14158090   3.29630054
## Mar 2001 364.521 336.6939  22.96260302   4.86449769
## Apr 2001 378.448 340.7955  13.68284737  23.96963442
## May 2001 300.798 346.3909 -29.44310031 -16.14979234
## Jun 2001 331.757 351.9863   6.80636903 -27.03563612
## Jul 2001 362.536 357.5816  27.69992285 -22.74556439
## Aug 2001 389.133 362.7526  19.95068817   6.42968678
## Sep 2001 323.322 367.9236 -50.45391870   5.85231015
## Oct 2001 391.832 373.0946   3.37177098  15.36563697
## Nov 2001 421.646 379.1435  20.98787861  21.51463212
## Dec 2001 416.823 385.1924  18.75081812  12.87979538
## Jan 2002 311.713 391.2413 -48.53242630 -30.99585742
## Feb 2002 381.902 396.5581  -6.77164300  -7.88447006
## Mar 2002 422.982 401.8749  23.21047959  -2.10342199
## Apr 2002 427.722 407.1918  13.97285518   6.55737308
## May 2002 376.850 411.6743 -29.49216466  -5.33210047
## Jun 2002 458.580 416.1568   7.44653003  34.97671146
## Jul 2002 436.225 420.6393  27.76548956 -12.17974145
## Aug 2002 441.487 424.2131  20.39539423  -3.12150206
## Sep 2002 369.566 427.7870 -50.53673688  -7.68422688
## Oct 2002 450.723 431.3608   2.82907212  16.53310819
## Nov 2002 462.442 433.3246  21.18604157   7.93140811
## Dec 2002 468.232 435.2883  18.50610877  14.43761029
## Jan 2003 403.636 437.2520 -48.66479446  15.04878289
## Feb 2003 413.948 435.5748  -7.40609691 -14.22066247
## Mar 2003 460.496 433.8975  23.44279204   3.15570077
## Apr 2003 448.932 432.2203  14.24104588   2.47069912
## May 2003 407.787 427.2601 -29.56929914  10.09615532
## Jun 2003 469.408 422.3000   8.05779406  39.05017330
## Jul 2003 494.311 417.3399  27.80133244  49.16974609
## Aug 2003 433.240 413.5110  20.81411494  -1.08508357
## Sep 2003 335.106 409.6820 -50.64180192 -23.93421388
## Oct 2003 378.795 405.8531   2.26958458 -29.32764755
## Nov 2003 387.100 402.8427  21.37287402 -37.11562290
## Dec 2003 372.395 399.8324  18.25475767 -45.69219245
## Jan 2004 335.790 396.8221 -48.86880898 -12.16331172
## Feb 2004 397.080 397.2256  -7.81155906   7.66594252
## Mar 2004 449.755 397.6291  23.63317868  28.49270893
## Apr 2004 402.252 398.0326  14.43840110 -10.21900933
## May 2004 391.847 400.6184 -29.61012665  20.83870536
## Jun 2004 385.890 403.2042   8.66678398 -25.98101834
## Jul 2004 424.325 405.7900  27.88437423  -9.34942166
## Aug 2004 433.280 407.6623  21.05963576   4.55809854
## Sep 2004 391.213 409.5345 -50.76226641  32.44078242
## Oct 2004 408.740 411.4067   1.88717866  -4.55388092
## Nov 2004 445.458 413.1591  21.42746567  10.87139294
## Dec 2004 428.202 414.9116  17.97442754  -4.68400807
## Jan 2005 379.048 416.6640 -49.05563208  11.43961243
## Feb 2005 394.042 418.2428  -8.20056273 -16.00020550
## Mar 2005 432.796 419.8215  23.83929086 -10.86480767
## attr(,"seasonal.periods")
## [1] 12
# c

fit.car = stlf(tscars, etsmodel="AAN", damped = TRUE, h = 24)
autoplot(fit.car)

# d

fit.car2 = stlf(tscars, etsmodel="AAN", damped = FALSE, h = 24)
autoplot(fit.car2)

# e

fit.car3 = ets(tscars)
summary(fit.car3)
## ETS(A,N,A) 
## 
## Call:
##  ets(y = tscars) 
## 
##   Smoothing parameters:
##     alpha = 0.4335 
##     gamma = 0.3414 
## 
##   Initial states:
##     l = 278.8164 
##     s = -13.649 -40.5044 5.5455 0.4469 -21.8558 7.5143
##            28.8245 21.8916 -6.6436 -37.109 59.3119 -3.7728
## 
##   sigma:  36.4202
## 
##      AIC     AICc      BIC 
## 4428.210 4429.696 4485.600 
## 
## Training set error measures:
##                     ME    RMSE      MAE        MPE   MAPE      MASE
## Training set 0.7908517 35.6602 27.38912 -0.7366844 9.1474 0.5292639
##                   ACF1
## Training set 0.1197292
#model chosen is ANA

# f

summary(fit.car)
## 
## Forecast method: STL +  ETS(A,Ad,N)
## 
## Model Information:
## ETS(A,Ad,N) 
## 
## Call:
##  ets(y = x, model = etsmodel, damped = TRUE, allow.multiplicative.trend = allow.multiplicative.trend) 
## 
##   Smoothing parameters:
##     alpha = 0.5471 
##     beta  = 0.0084 
##     phi   = 0.9186 
## 
##   Initial states:
##     l = 344.3859 
##     b = -9.9111 
## 
##   sigma:  27.921
## 
##      AIC     AICc      BIC 
## 4239.296 4239.549 4262.252 
## 
## Error measures:
##                     ME     RMSE      MAE        MPE     MAPE      MASE
## Training set 0.8157753 27.71434 21.31396 -0.4473582 7.037153 0.4118683
##                    ACF1
## Training set 0.08939321
## 
## Forecasts:
##          Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## Apr 2005       424.4868 388.7046 460.2690 369.7626 479.2110
## May 2005       380.4428 339.5215 421.3641 317.8591 443.0265
## Jun 2005       418.7239 373.1289 464.3188 348.9924 488.4553
## Jul 2005       437.9453 388.0184 487.8722 361.5886 514.3019
## Aug 2005       431.1240 377.1307 485.1173 348.5484 513.6996
## Sep 2005       359.3053 301.4607 417.1499 270.8397 447.7710
## Oct 2005       411.9577 350.4413 473.4741 317.8765 506.0390
## Nov 2005       431.5007 366.4658 496.5356 332.0384 530.9630
## Dec 2005       428.0502 359.6302 496.4701 323.4109 532.6894
## Jan 2006       361.0224 289.3355 432.7093 251.3867 470.6581
## Feb 2006       401.8796 327.0311 476.7280 287.4088 516.3503
## Mar 2006       433.9213 356.0068 511.8358 314.7614 553.0813
## Apr 2006       424.5222 343.6286 505.4158 300.8061 548.2383
## May 2006       380.4753 296.6825 464.2682 252.3252 508.6254
## Jun 2006       418.7537 332.1354 505.3720 286.2825 551.2250
## Jul 2006       437.9727 348.5975 527.3479 301.2851 574.6603
## Aug 2006       431.1492 339.0810 523.2174 290.3431 571.9554
## Sep 2006       359.3285 264.6272 454.0297 214.4954 504.1615
## Oct 2006       411.9790 314.7010 509.2570 263.2052 560.7528
## Nov 2006       431.5203 331.7186 531.3219 278.8869 584.1536
## Dec 2006       428.0681 325.7931 530.3431 271.6519 584.4843
## Jan 2007       361.0389 256.3380 465.7398 200.9127 521.1650
## Feb 2007       401.8947 294.8132 508.9762 238.1276 565.6618
## Mar 2007       433.9353 324.5161 543.3544 266.5931 601.2775
#RMSE = 27.71434
summary(fit.car2)
## 
## Forecast method: STL +  ETS(A,A,N)
## 
## Model Information:
## ETS(A,A,N) 
## 
## Call:
##  ets(y = x, model = etsmodel, damped = FALSE, allow.multiplicative.trend = allow.multiplicative.trend) 
## 
##   Smoothing parameters:
##     alpha = 0.5821 
##     beta  = 1e-04 
## 
##   Initial states:
##     l = 343.8939 
##     b = 0.2223 
## 
##   sigma:  27.9597
## 
##      AIC     AICc      BIC 
## 4239.248 4239.428 4258.378 
## 
## Error measures:
##                       ME     RMSE      MAE        MPE     MAPE      MASE
## Training set -0.03232586 27.79422 21.14456 -0.7721728 7.007763 0.4085948
##                    ACF1
## Training set 0.07448203
## 
## Forecasts:
##          Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## Apr 2005       424.4877 388.6560 460.3195 369.6878 479.2877
## May 2005       380.6603 339.1978 422.1228 317.2489 444.0717
## Jun 2005       419.1583 372.7414 465.5751 348.1698 490.1468
## Jul 2005       438.5969 387.7040 489.4898 360.7630 516.4308
## Aug 2005       431.9932 376.9859 487.0006 347.8667 516.1197
## Sep 2005       360.3924 301.5562 419.2286 270.4102 450.3746
## Oct 2005       413.2629 350.8309 475.6949 317.7813 508.7445
## Nov 2005       433.0242 367.1912 498.8573 332.3413 533.7071
## Dec 2005       429.7923 360.7243 498.8602 324.1620 535.4225
## Jan 2006       362.9833 290.8241 435.1424 252.6254 473.3411
## Feb 2006       404.0594 328.9351 479.1837 289.1666 518.9522
## Mar 2006       436.3203 358.3423 514.2983 317.0633 555.5773
## Apr 2006       427.1405 346.4087 507.8723 303.6718 550.6092
## May 2006       383.3130 299.9172 466.7088 255.7702 510.8559
## Jun 2006       421.8110 335.8328 507.7892 290.3186 553.3033
## Jul 2006       441.2496 352.7634 529.7359 305.9216 576.5777
## Aug 2006       434.6460 343.7199 525.5721 295.5865 573.7054
## Sep 2006       363.0451 269.7421 456.3482 220.3504 505.7398
## Oct 2006       415.9156 320.2938 511.5374 269.6747 562.1565
## Nov 2006       435.6770 337.7905 533.5635 285.9725 585.3814
## Dec 2006       432.4450 332.3442 532.5458 279.3541 585.5359
## Jan 2007       365.6360 263.3680 467.9040 209.2306 522.0414
## Feb 2007       406.7121 302.3211 511.1031 247.0599 566.3644
## Mar 2007       438.9731 332.5006 545.4455 276.1375 601.8086
#RMSE = 27.79422
summary(fit.car3)
## ETS(A,N,A) 
## 
## Call:
##  ets(y = tscars) 
## 
##   Smoothing parameters:
##     alpha = 0.4335 
##     gamma = 0.3414 
## 
##   Initial states:
##     l = 278.8164 
##     s = -13.649 -40.5044 5.5455 0.4469 -21.8558 7.5143
##            28.8245 21.8916 -6.6436 -37.109 59.3119 -3.7728
## 
##   sigma:  36.4202
## 
##      AIC     AICc      BIC 
## 4428.210 4429.696 4485.600 
## 
## Training set error measures:
##                     ME    RMSE      MAE        MPE   MAPE      MASE
## Training set 0.7908517 35.6602 27.38912 -0.7366844 9.1474 0.5292639
##                   ACF1
## Training set 0.1197292
#RMSE = 35.6602
#Addidtive damped trend has the lowest RMSE making it the best fitting model
plot(residuals(fit.car))

# 11

# a

autoplot(visitors)

#Increasing trend with multiplicative seasonality

# b

trainvisitors = ts(visitors, frequency = 12, start = c(2004,1), end = c(2005,12))
testvisitors = ts(visitors, frequency = 12, start = c(2004,1), end = c(2005,12))
visitfcast = hw(trainvisitors,seasonal="multiplicative")
autoplot(visitfcast)

# c

#Multiplicative seasonality is necessary due to the increasing magnitude of seasonality

# d

vfit1 = ets(visitors)
lambda <- BoxCox.lambda(visitors)
boxcox_visitors <- BoxCox(visitors, lambda)
vfit2 = ets(boxcox_visitors, model='AAZ')
vfit3 = snaive(visitors)
decomposed = decompose(boxcox_visitors)
seasonal_visitors = decomposed$seasonal
vfit4 <- ets(seasonal_visitors)

# e

plot((fitted(vfit1)), residuals(vfit1))

plot((fitted(vfit2)), residuals(vfit2))

plot((fitted(vfit3)), residuals(vfit3))

plot((fitted(vfit4)), residuals(vfit4))

summary(vfit1)
## ETS(M,A,M) 
## 
## Call:
##  ets(y = visitors) 
## 
##   Smoothing parameters:
##     alpha = 0.6146 
##     beta  = 2e-04 
##     gamma = 0.192 
## 
##   Initial states:
##     l = 92.9631 
##     b = 2.2221 
##     s = 0.9378 1.0666 1.0669 0.9625 1.3768 1.113
##            1.0012 0.8219 0.9317 1.0046 0.8755 0.8413
## 
##   sigma:  0.0536
## 
##      AIC     AICc      BIC 
## 2603.654 2606.411 2662.825 
## 
## Training set error measures:
##                     ME     RMSE      MAE        MPE     MAPE      MASE
## Training set -1.314437 15.89924 11.55716 -0.5970068 4.126055 0.4267949
##                    ACF1
## Training set 0.03686264
summary(vfit2)
## ETS(A,A,A) 
## 
## Call:
##  ets(y = boxcox_visitors, model = "AAZ") 
## 
##   Smoothing parameters:
##     alpha = 0.613 
##     beta  = 1e-04 
##     gamma = 0.1629 
## 
##   Initial states:
##     l = 9 
##     b = 0.029 
##     s = -0.2608 0.2417 0.2399 -0.1191 1.4225 0.5071
##            0.1414 -0.6578 -0.1895 0.0663 -0.5966 -0.7949
## 
##   sigma:  0.2493
## 
##      AIC     AICc      BIC 
## 665.9353 668.6921 725.1062 
## 
## Training set error measures:
##                        ME      RMSE      MAE         MPE     MAPE
## Training set 0.0005655299 0.2408002 0.188498 0.004614893 1.422349
##                   MASE       ACF1
## Training set 0.3852828 0.04664328
summary(vfit3)
## 
## Forecast method: Seasonal naive method
## 
## Model Information:
## Call: snaive(y = visitors) 
## 
## Residual sd: 27.0532 
## 
## Error measures:
##                    ME     RMSE      MAE      MPE     MAPE MASE      ACF1
## Training set 18.22368 32.56941 27.07895 7.011798 10.12935    1 0.6600405
## 
## Forecasts:
##          Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## May 2005          341.3 299.5606 383.0394 277.4651 405.1349
## Jun 2005          367.3 325.5606 409.0394 303.4651 431.1349
## Jul 2005          472.0 430.2606 513.7394 408.1651 535.8349
## Aug 2005          405.8 364.0606 447.5394 341.9651 469.6349
## Sep 2005          395.6 353.8606 437.3394 331.7651 459.4349
## Oct 2005          449.9 408.1606 491.6394 386.0651 513.7349
## Nov 2005          479.9 438.1606 521.6394 416.0651 543.7349
## Dec 2005          593.1 551.3606 634.8394 529.2651 656.9349
## Jan 2006          462.4 420.6606 504.1394 398.5651 526.2349
## Feb 2006          501.6 459.8606 543.3394 437.7651 565.4349
## Mar 2006          504.7 462.9606 546.4394 440.8651 568.5349
## Apr 2006          409.5 367.7606 451.2394 345.6651 473.3349
## May 2006          341.3 282.2716 400.3284 251.0239 431.5761
## Jun 2006          367.3 308.2716 426.3284 277.0239 457.5761
## Jul 2006          472.0 412.9716 531.0284 381.7239 562.2761
## Aug 2006          405.8 346.7716 464.8284 315.5239 496.0761
## Sep 2006          395.6 336.5716 454.6284 305.3239 485.8761
## Oct 2006          449.9 390.8716 508.9284 359.6239 540.1761
## Nov 2006          479.9 420.8716 538.9284 389.6239 570.1761
## Dec 2006          593.1 534.0716 652.1284 502.8239 683.3761
## Jan 2007          462.4 403.3716 521.4284 372.1239 552.6761
## Feb 2007          501.6 442.5716 560.6284 411.3239 591.8761
## Mar 2007          504.7 445.6716 563.7284 414.4239 594.9761
## Apr 2007          409.5 350.4716 468.5284 319.2239 499.7761
summary(vfit4)
## ETS(A,A,A) 
## 
## Call:
##  ets(y = seasonal_visitors) 
## 
##   Smoothing parameters:
##     alpha = 0.027 
##     beta  = 0.0018 
##     gamma = 0.1738 
## 
##   Initial states:
##     l = 0 
##     b = 0 
##     s = -0.2803 0.2683 0.4058 -0.096 1.4061 0.4407
##            0.1619 -0.4827 -0.2781 0.1974 -0.7459 -0.9973
## 
##   sigma:  0
## 
##       AIC      AICc       BIC 
## -16858.67 -16855.91 -16799.50 
## 
## Training set error measures:
##                        ME         RMSE         MAE          MPE
## Training set 3.758568e-18 3.355393e-17 2.13371e-17 3.342986e-16
##                      MAPE MASE       ACF1
## Training set 9.067089e-15  Inf -0.1765518
#The ets model has the smallest RMSE making it the best fitting model

# 12

# a

fets <- function(qcement)
forecast(ets(qcement), h = 4)
snaive(qcement, h = 4)
##         Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 2014 Q2          2.528 2.356456 2.699544 2.265646 2.790354
## 2014 Q3          2.637 2.465456 2.808544 2.374646 2.899354
## 2014 Q4          2.565 2.393456 2.736544 2.302646 2.827354
## 2015 Q1          2.229 2.057456 2.400544 1.966646 2.491354
# 13

ets(ausbeer)
## ETS(M,A,M) 
## 
## Call:
##  ets(y = ausbeer) 
## 
##   Smoothing parameters:
##     alpha = 0.2087 
##     beta  = 0.0302 
##     gamma = 0.1984 
## 
##   Initial states:
##     l = 255.892 
##     b = 0.6795 
##     s = 1.183 0.9113 0.8614 1.0444
## 
##   sigma:  0.0361
## 
##      AIC     AICc      BIC 
## 2354.249 2355.114 2384.709
snaive(ausbeer)
##         Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 2010 Q3            419 394.2329 443.7671 381.1219 456.8781
## 2010 Q4            488 463.2329 512.7671 450.1219 525.8781
## 2011 Q1            414 389.2329 438.7671 376.1219 451.8781
## 2011 Q2            374 349.2329 398.7671 336.1219 411.8781
## 2011 Q3            419 383.9740 454.0260 365.4323 472.5677
## 2011 Q4            488 452.9740 523.0260 434.4323 541.5677
## 2012 Q1            414 378.9740 449.0260 360.4323 467.5677
## 2012 Q2            374 338.9740 409.0260 320.4323 427.5677
stlf(ausbeer)
##         Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 2010 Q3       404.8736 387.5026 422.2445 378.3070 431.4401
## 2010 Q4       480.0342 461.9966 498.0719 452.4481 507.6204
## 2011 Q1       420.3933 401.4782 439.3083 391.4651 449.3214
## 2011 Q2       384.6943 364.6970 404.6916 354.1111 415.2776
## 2011 Q3       402.7549 381.4848 424.0249 370.2251 435.2846
## 2011 Q4       478.0078 455.2935 500.7221 443.2693 512.7463
## 2012 Q1       418.4551 394.1459 442.7642 381.2775 455.6327
## 2012 Q2       382.8405 356.8065 408.8745 343.0250 422.6561
ets(bricksq)
## ETS(M,A,M) 
## 
## Call:
##  ets(y = bricksq) 
## 
##   Smoothing parameters:
##     alpha = 0.973 
##     beta  = 0.0032 
##     gamma = 1e-04 
## 
##   Initial states:
##     l = 196.0437 
##     b = 4.9839 
##     s = 1.0041 1.0598 1.0269 0.9093
## 
##   sigma:  0.0514
## 
##      AIC     AICc      BIC 
## 1725.473 1726.714 1752.864
snaive(bricksq)
##         Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 1994 Q4            443 380.5765 505.4235 347.5315 538.4685
## 1995 Q1            421 358.5765 483.4235 325.5315 516.4685
## 1995 Q2            472 409.5765 534.4235 376.5315 567.4685
## 1995 Q3            494 431.5765 556.4235 398.5315 589.4685
## 1995 Q4            443 354.7199 531.2801 307.9872 578.0128
## 1996 Q1            421 332.7199 509.2801 285.9872 556.0128
## 1996 Q2            472 383.7199 560.2801 336.9872 607.0128
## 1996 Q3            494 405.7199 582.2801 358.9872 629.0128
ets(bricksq)
## ETS(M,A,M) 
## 
## Call:
##  ets(y = bricksq) 
## 
##   Smoothing parameters:
##     alpha = 0.973 
##     beta  = 0.0032 
##     gamma = 1e-04 
## 
##   Initial states:
##     l = 196.0437 
##     b = 4.9839 
##     s = 1.0041 1.0598 1.0269 0.9093
## 
##   sigma:  0.0514
## 
##      AIC     AICc      BIC 
## 1725.473 1726.714 1752.864
ets(dole)
## ETS(M,Ad,M) 
## 
## Call:
##  ets(y = dole) 
## 
##   Smoothing parameters:
##     alpha = 0.697 
##     beta  = 0.124 
##     gamma = 0.303 
##     phi   = 0.902 
## 
##   Initial states:
##     l = 2708.6621 
##     b = 836.017 
##     s = 1.0404 0.8893 0.9103 1.0301 1.0576 1.0584
##            0.9801 0.9632 1.021 0.9838 1.0145 1.0514
## 
##   sigma:  0.0935
## 
##      AIC     AICc      BIC 
## 10602.67 10604.30 10676.19
snaive(dole)
##          Point Forecast    Lo 80    Hi 80    Lo 95     Hi 95
## Aug 1992         709801 616006.4 803595.6 566354.5  853247.5
## Sep 1992         718748 624953.4 812542.6 575301.5  862194.5
## Oct 1992         720754 626959.4 814548.6 577307.5  864200.5
## Nov 1992         730105 636310.4 823899.6 586658.5  873551.5
## Dec 1992         751348 657553.4 845142.6 607901.5  894794.5
## Jan 1993         779868 686073.4 873662.6 636421.5  923314.5
## Feb 1993         816124 722329.4 909918.6 672677.5  959570.5
## Mar 1993         818102 724307.4 911896.6 674655.5  961548.5
## Apr 1993         826297 732502.4 920091.6 682850.5  969743.5
## May 1993         838390 744595.4 932184.6 694943.5  981836.5
## Jun 1993         851831 758036.4 945625.6 708384.5  995277.5
## Jul 1993         856505 762710.4 950299.6 713058.5  999951.5
## Aug 1993         709801 577155.3 842446.7 506937.0  912665.0
## Sep 1993         718748 586102.3 851393.7 515884.0  921612.0
## Oct 1993         720754 588108.3 853399.7 517890.0  923618.0
## Nov 1993         730105 597459.3 862750.7 527241.0  932969.0
## Dec 1993         751348 618702.3 883993.7 548484.0  954212.0
## Jan 1994         779868 647222.3 912513.7 577004.0  982732.0
## Feb 1994         816124 683478.3 948769.7 613260.0 1018988.0
## Mar 1994         818102 685456.3 950747.7 615238.0 1020966.0
## Apr 1994         826297 693651.3 958942.7 623433.0 1029161.0
## May 1994         838390 705744.3 971035.7 635526.0 1041254.0
## Jun 1994         851831 719185.3 984476.7 648967.0 1054695.0
## Jul 1994         856505 723859.3 989150.7 653641.0 1059369.0
stlf(dole)
##          Point Forecast    Lo 80     Hi 80    Lo 95     Hi 95
## Aug 1992       857025.6 848291.4  865759.7 843667.9  870383.3
## Sep 1992       856604.0 841967.3  871240.8 834219.1  878989.0
## Oct 1992       853169.6 832569.2  873770.1 821663.9  884675.3
## Nov 1992       855961.2 829246.0  882676.4 815103.9  896818.5
## Dec 1992       881890.2 848929.8  914850.5 831481.6  932298.7
## Jan 1993       921019.6 881720.4  960318.9 860916.6  981122.6
## Feb 1993       928400.4 882704.3  974096.5 858514.3  998286.6
## Mar 1993       914097.1 861977.1  966217.0 834386.5  993807.7
## Apr 1993       910123.1 851578.0  968668.3 820586.1  999660.2
## May 1993       915112.2 850161.8  980062.6 815779.1 1014445.3
## Jun 1993       918939.6 847620.8  990258.5 809866.8 1028012.4
## Jul 1993       920676.3 843039.6  998313.0 801941.3 1039411.4
## Aug 1993       915642.6 831749.6  999535.6 787339.3 1043945.9
## Sep 1993       910147.9 820068.6 1000227.2 772383.5 1047912.3
## Oct 1993       902079.4 805890.6  998268.3 754971.3 1049187.6
## Nov 1993       900638.0 798421.3 1002854.7 744311.1 1056965.0
## Dec 1993       922700.3 814541.2 1030859.4 757285.3 1088115.4
## Jan 1994       958297.8 844284.3 1072311.3 783929.2 1132666.3
## Feb 1994       962452.3 842674.2 1082230.4 779267.4 1145637.1
## Mar 1994       945201.8 819749.8 1070653.9 753339.4 1137064.2
## Apr 1994       938535.9 807500.9 1069570.9 738135.1 1138936.7
## May 1994       941065.9 804538.7 1077593.0 732265.6 1149866.1
## Jun 1994       942647.1 800718.1 1084576.1 725585.4 1159708.8
## Jul 1994       942332.0 795090.4 1089573.6 717145.3 1167518.6
ets(usdeaths)
## ETS(A,N,A) 
## 
## Call:
##  ets(y = usdeaths) 
## 
##   Smoothing parameters:
##     alpha = 0.5972 
##     gamma = 0.0019 
## 
##   Initial states:
##     l = 9195.6403 
##     s = -62.6129 -270.0351 263.3823 -89.4907 1005.529 1662.647
##            795.2585 333.326 -551.161 -737.5102 -1552.872 -796.4611
## 
##   sigma:  294.4663
## 
##      AIC     AICc      BIC 
## 1141.016 1149.587 1175.166
snaive(usdeaths)
##          Point Forecast    Lo 80     Hi 80    Lo 95     Hi 95
## Jan 1979           7836 7118.854  8553.146 6739.219  8932.781
## Feb 1979           6892 6174.854  7609.146 5795.219  7988.781
## Mar 1979           7791 7073.854  8508.146 6694.219  8887.781
## Apr 1979           8129 7411.854  8846.146 7032.219  9225.781
## May 1979           9115 8397.854  9832.146 8018.219 10211.781
## Jun 1979           9434 8716.854 10151.146 8337.219 10530.781
## Jul 1979          10484 9766.854 11201.146 9387.219 11580.781
## Aug 1979           9827 9109.854 10544.146 8730.219 10923.781
## Sep 1979           9110 8392.854  9827.146 8013.219 10206.781
## Oct 1979           9070 8352.854  9787.146 7973.219 10166.781
## Nov 1979           8633 7915.854  9350.146 7536.219  9729.781
## Dec 1979           9240 8522.854  9957.146 8143.219 10336.781
## Jan 1980           7836 6821.802  8850.198 6284.918  9387.082
## Feb 1980           6892 5877.802  7906.198 5340.918  8443.082
## Mar 1980           7791 6776.802  8805.198 6239.918  9342.082
## Apr 1980           8129 7114.802  9143.198 6577.918  9680.082
## May 1980           9115 8100.802 10129.198 7563.918 10666.082
## Jun 1980           9434 8419.802 10448.198 7882.918 10985.082
## Jul 1980          10484 9469.802 11498.198 8932.918 12035.082
## Aug 1980           9827 8812.802 10841.198 8275.918 11378.082
## Sep 1980           9110 8095.802 10124.198 7558.918 10661.082
## Oct 1980           9070 8055.802 10084.198 7518.918 10621.082
## Nov 1980           8633 7618.802  9647.198 7081.918 10184.082
## Dec 1980           9240 8225.802 10254.198 7688.918 10791.082
stlf(usdeaths)
##          Point Forecast     Lo 80     Hi 80    Lo 95     Hi 95
## Jan 1979       8320.755  8004.124  8637.386 7836.509  8805.000
## Feb 1979       7587.259  7218.268  7956.249 7022.936  8151.581
## Mar 1979       8358.427  7943.635  8773.220 7724.057  8992.798
## Apr 1979       8571.859  8115.842  9027.876 7874.441  9269.277
## May 1979       9456.110  8962.298  9949.922 8700.889 10211.330
## Jun 1979       9879.745  9350.832 10408.658 9070.842 10688.647
## Jul 1979      10808.484 10246.659 11370.310 9949.247 11667.722
## Aug 1979      10056.863  9463.950 10649.777 9150.080 10963.646
## Sep 1979       9016.703  8394.252  9639.154 8064.746  9968.660
## Oct 1979       9302.446  8651.797  9953.095 8307.365 10297.528
## Nov 1979       8798.123  8120.448  9475.797 7761.709  9834.536
## Dec 1979       9129.860  8426.197  9833.523 8053.701 10206.019
## Jan 1980       8320.755  7592.030  9049.480 7206.266  9435.244
## Feb 1980       7587.259  6834.305  8340.212 6435.716  8738.802
## Mar 1980       8358.427  7582.001  9134.854 7170.986  9545.869
## Apr 1980       8571.859  7772.649  9371.069 7349.573  9794.145
## May 1980       9456.110  8634.748 10277.471 8199.945 10712.274
## Jun 1980       9879.745  9036.813 10722.676 8590.592 11168.897
## Jul 1980      10808.484  9944.521 11672.448 9487.166 12129.802
## Aug 1980      10056.863  9172.368 10941.358 8704.145 11409.581
## Sep 1980       9016.703  8112.142  9921.264 7633.297 10400.109
## Oct 1980       9302.446  8378.255 10226.637 7889.018 10715.874
## Nov 1980       8798.123  7854.710  9741.535 7355.297 10240.948
## Dec 1980       9129.860  8167.609 10092.111 7658.225 10601.495
ets(lynx)
## ETS(M,N,N) 
## 
## Call:
##  ets(y = lynx) 
## 
##   Smoothing parameters:
##     alpha = 0.9999 
## 
##   Initial states:
##     l = 2372.8047 
## 
##   sigma:  0.9594
## 
##      AIC     AICc      BIC 
## 2058.138 2058.356 2066.346
snaive(lynx)
##      Point Forecast    Lo 80    Hi 80     Lo 95    Hi 95
## 1935           3396 1874.391 4917.609 1068.8996 5723.100
## 1936           3396 1244.120 5547.880  104.9831 6687.017
ets(ibmclose)
## ETS(A,N,N) 
## 
## Call:
##  ets(y = ibmclose) 
## 
##   Smoothing parameters:
##     alpha = 0.9999 
## 
##   Initial states:
##     l = 459.9339 
## 
##   sigma:  7.2637
## 
##      AIC     AICc      BIC 
## 3648.450 3648.515 3660.182
snaive(ibmclose)
##     Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 370            357 347.7039 366.2961 342.7829 371.2171
## 371            357 343.8534 370.1466 336.8940 377.1060
ets(eggs)
## ETS(M,N,N) 
## 
## Call:
##  ets(y = eggs) 
## 
##   Smoothing parameters:
##     alpha = 0.8198 
## 
##   Initial states:
##     l = 278.8889 
## 
##   sigma:  0.1355
## 
##      AIC     AICc      BIC 
## 1043.286 1043.553 1050.916
snaive(eggs)
##      Point Forecast    Lo 80     Hi 80      Lo 95    Hi 95
## 1994          62.27 27.70454  96.83546   9.406697 115.1333
## 1995          62.27 13.38706 111.15294 -12.490000 137.0300
#The STLF models continually provided the best forecasts

# 14


autoplot(forecast(ets(bicoal)))

#Not useful as it produces a straight line 
autoplot(forecast(ets(chicken)))

#Not useful as it produces a straight line
autoplot(forecast(ets(dole)))

#Produces good forecast capturing increasing trend and the seasonality component
autoplot(forecast(ets(usdeaths)))

#Produces a good forecast that captures trend and seasonality
autoplot(forecast(ets(lynx)))

#Not Useful as forecast produces a straight line
autoplot(forecast(ets(ibmclose)))

#Not useful as it produces a straight line 
autoplot(forecast(ets(eggs)))

#Not useful as it produces a straight line

# b

#ETS does not seem to produce good forecasts for cyclical data

# CHAPTER 8

# 1

# a 

#All of these plots indicate that the data is white noise as nothing goes beyond the critical value points

# b

#The critical value is partially determine d by the sample size, so CV will change as the sample size changes. 

# 2

plot(ibmclose)

plot(acf(ibmclose))

plot(pacf(ibmclose))

#Autocorrelation is significantly expemplified in the ACF plot as the CV is broken throughout the data.  The PACF only shows autocorrelation once in the beginning of the data

#3

library(urca)
ndiffs(usnetelec)
## [1] 1
#1 difference
ndiffs(usgdp)
## [1] 2
#2 differences
ndiffs(mcopper)
## [1] 1
#1 difference
ndiffs(enplanements)
## [1] 1
#1 difference
ndiffs(visitors)
## [1] 1
#1 difference


# 5 
#retailarima = auto.arima(retailts)
#retailarima
#One order of difference is necessary to create stationary data

# 6

# a
y <- ts(numeric(100))
e <- rnorm(100)
for(i in 2:100)
  y[i] <- 0.6*y[i-1] + e[i]
plot(y)

plot(y[i])

# b

ar1 <- function(phi1){
  y <- ts(numeric(100))
  e <- rnorm(100)
  for(i in 2:100){
    y[i] <- phi1*y[i-1] + e[i]
  }
  return(y)
}

autoplot(ar1(0.3), series = "0.3") +
  geom_line(size = 1, colour = "red") +
  autolayer(y, series = "0.6", size = 1) +
  autolayer(ar1(0.9), size = 1, series = "0.9") +
  ylab("AR(1) models") +
  guides(colour = guide_legend(title = "Phi1"))

#The variation in y increases as phi increases

# c

ma1 <- function(theta1){
  y <- ts(numeric(100))
  e <- rnorm(100)
  for(i in 2:100){
    y[i] <- theta1*e[i-1] + e[i]
  }
  return(y)
}

# d

autoplot(ma1(0.3), series = "0.3") +
  geom_line(size = 1, colour = "red") +
  autolayer(y, series = "0.6", size = 1) +
  autolayer(ma1(0.9), size = 1, series = "0.9") +
  ylab("MA(1) models") +
  guides(colour = guide_legend(title = "Theta1"))

#Similarly, as theta increases, so does the variation of y

# e

MYarima11 <- ts(numeric(50))
e <- rnorm(50)
for(i in 2:50){
  MYarima11[i] <- 0.6*MYarima11[i-1] + 0.6*e[i-1] + e[i]
}
# f

MYarima2 <- ts(numeric(50))
e <- rnorm(50)
for(i in 3:50){
  MYarima2[i] <- -0.8*MYarima2[i-1] + 0.3*MYarima2[i-2] + e[i]
}

# g

autoplot(MYarima11, series = "ARMA(1, 1)") +
  autolayer(MYarima2, series = "AR(2)") +
  ylab("y") +
  guides(colour = guide_legend(title = "ARIMA Method"))

#AR(2) reflects non stationary data while ARMA(1,1) produces stationary data

# 7

View(wmurders)
# a

wmurderarima = auto.arima(wmurders)
#this data will need a model with a differencing of 2

# c

#(1 - B)^2*yt = (1 + theta1*B + theta2*B^2)*et

# d

checkresiduals(wmurderarima)

## 
##  Ljung-Box test
## 
## data:  Residuals from ARIMA(1,2,1)
## Q* = 12.419, df = 8, p-value = 0.1335
## 
## Model df: 2.   Total lags used: 10
#Model is satisfactory as residuals are white noise

# e

fcast_wmurderarima <- forecast(wmurderarima, h = 3)
fcast_wmurderarima$mean
## Time Series:
## Start = 2005 
## End = 2007 
## Frequency = 1 
## [1] 2.470660 2.363106 2.252833
# f
plot(fcast_wmurderarima)

# 8

# a

austaarima = auto.arima(austa)
#ARIMA(0,1,1) with drift was selected
checkresiduals(auto.arima(austa))

## 
##  Ljung-Box test
## 
## data:  Residuals from ARIMA(0,1,1) with drift
## Q* = 2.297, df = 5.2, p-value = 0.8266
## 
## Model df: 2.   Total lags used: 7.2
#residuals are white noise as they do not surpass CV 

# b 
austa_arima011 = Arima(austa, order = c(0, 1, 1))
checkresiduals(austa_arima011)

## 
##  Ljung-Box test
## 
## data:  Residuals from ARIMA(0,1,1)
## Q* = 3.8403, df = 6.2, p-value = 0.7204
## 
## Model df: 1.   Total lags used: 7.2
plot(forecast(austaarima, h = 10))

plot(forecast(austa_arima011, h = 10))

# the ARIMA with no drift forecasts as a naive model would

# c
fcast_austaarima213drift <- forecast(
  Arima(austa, order = c(2, 1, 3), include.drift = TRUE),
  h = 10
)
plot(fcast_austaarima213drift)

#this forecasts an increasing trend that tapers off

# d

fcast_austaarima001constant <- forecast(
  Arima(
    austa, order = c(0, 0, 1), include.constant = TRUE
  ),
  h = 10
)
plot(fcast_austaarima001constant)

#forecast is significantly less than the current trend

# e

fcast_austaarima021 <- forecast(
  Arima(austa, order = c(0, 2, 1)),
  h = 10
)
plot(fcast_austaarima021)

#forecast follows the trend of the current data

# 9 

auto.arima(usgdp)
## Series: usgdp 
## ARIMA(2,2,2) 
## 
## Coefficients:
##           ar1     ar2      ma1      ma2
##       -0.1228  0.3106  -0.5835  -0.3669
## s.e.   0.2869  0.0872   0.3004   0.2862
## 
## sigma^2 estimated as 1604:  log likelihood=-1199.57
## AIC=2409.13   AICc=2409.39   BIC=2426.43
ets(usgdp)
## ETS(A,A,N) 
## 
## Call:
##  ets(y = usgdp) 
## 
##   Smoothing parameters:
##     alpha = 0.9999 
##     beta  = 0.278 
## 
##   Initial states:
##     l = 1557.4589 
##     b = 18.6862 
## 
##   sigma:  41.8895
## 
##      AIC     AICc      BIC 
## 3072.303 3072.562 3089.643
# The auto.arima model is a better fit than the automated ETS model as it has a lesser AICc

# 10 

plot(austourists)

#increasing trend with seasonality

ggAcf(austourists)

#autocorrelations are more frequent in the beginning of the data but are decreasing over time

ggPacf((austourists))

#5 major spikes in the dataset

ggtsdisplay(diff(austourists, lag = 4))

auto.arima(austourists)
## Series: austourists 
## ARIMA(1,0,0)(1,1,0)[4] with drift 
## 
## Coefficients:
##          ar1     sar1   drift
##       0.4705  -0.5305  0.5489
## s.e.  0.1154   0.1122  0.0864
## 
## sigma^2 estimated as 5.15:  log likelihood=-142.48
## AIC=292.97   AICc=293.65   BIC=301.6
#auto.arima chose ARIMA(1,0,0)(1,1,0)[4] with drift
fcast_austourists_autoarima <- forecast(
  auto.arima(austourists)
)
fcast_austourists_autoarima$model
## Series: austourists 
## ARIMA(1,0,0)(1,1,0)[4] with drift 
## 
## Coefficients:
##          ar1     sar1   drift
##       0.4705  -0.5305  0.5489
## s.e.  0.1154   0.1122  0.0864
## 
## sigma^2 estimated as 5.15:  log likelihood=-142.48
## AIC=292.97   AICc=293.65   BIC=301.6
# (1 - phi1*B)(1 - phis1*B)(1 - B^4)(yt - c*t) = et
# c = drift*(1 - phi1)(1 - phis1)*m^D = 1.7793

# 11

usmelec_ma <- ma(usmelec, order = 12, centre = TRUE)
autoplot(usmelec_ma)

#trend increases until about 2009
lambda_usmelec <- BoxCox.lambda(usmelec)
ndiffs(usmelec)
## [1] 1
nsdiffs(usmelec)
## [1] 1
#data needs a differencing of 1
auto.arima(usmelec)
## Series: usmelec 
## ARIMA(1,0,2)(0,1,1)[12] with drift 
## 
## Coefficients:
##          ar1      ma1      ma2     sma1   drift
##       0.9717  -0.4374  -0.2774  -0.7061  0.3834
## s.e.  0.0163   0.0483   0.0493   0.0310  0.0868
## 
## sigma^2 estimated as 57.67:  log likelihood=-1635.13
## AIC=3282.26   AICc=3282.44   BIC=3307.22
#best arima is ARIMA(1,0,2)(0,1,1)[12] with drift
checkresiduals(auto.arima(usmelec))

## 
##  Ljung-Box test
## 
## data:  Residuals from ARIMA(1,0,2)(0,1,1)[12] with drift
## Q* = 42.725, df = 19, p-value = 0.001413
## 
## Model df: 5.   Total lags used: 24
#normal distribution in the the residuals indicates white noise
fcast_usmelec_arima <- forecast(
  auto.arima(usmelec),
  h = 12*15
)
plot(fcast_usmelec_arima)

# 12

auto.arima(mcopper)
## Series: mcopper 
## ARIMA(0,1,1) 
## 
## Coefficients:
##          ma1
##       0.2900
## s.e.  0.0419
## 
## sigma^2 estimated as 6026:  log likelihood=-3248.53
## AIC=6501.07   AICc=6501.09   BIC=6509.73
#suitable model is ARIMA(0,1,1)
fcast_arima_mcopper = forecast(auto.arima(mcopper), h = 100)
plot(fcast_arima_mcopper)

#fcast produces results similar to a naive forecast
#this does not seem like a suitable model
ets_mcopper = ets(mcopper)
plot(forecast(ets_mcopper, h = 100))

#forecast produces similar naive looking model

# 13

auto.arima(auscafe)
## Series: auscafe 
## ARIMA(0,1,1)(0,1,1)[12] 
## 
## Coefficients:
##           ma1     sma1
##       -0.3673  -0.5991
## s.e.   0.0443   0.0348
## 
## sigma^2 estimated as 0.001673:  log likelihood=732.46
## AIC=-1458.92   AICc=-1458.87   BIC=-1446.85
#best model is ARIMA(0,1,1)(0,1,1)[12]
checkresiduals(auto.arima(auscafe))

## 
##  Ljung-Box test
## 
## data:  Residuals from ARIMA(0,1,1)(0,1,1)[12]
## Q* = 64.68, df = 22, p-value = 4.421e-06
## 
## Model df: 2.   Total lags used: 24
#normal distribution in residuals suggests white noise
fcast_arima_auscafe = forecast(auto.arima(auscafe), h = 24)
plot(fcast_arima_auscafe)

#fcast follows trend and seasonality of the data
fcast_ets_auscafe = forecast(ets(auscafe), h = 24)
plot(fcast_ets_auscafe)

#MAM ets forecast produces a similar forecast but with significantly larger confidence intervals

# 14

plot(forecast(stlf(auscafe, method = "arima"), h = 24))

#Stlf produces more confident intervals with a lower MSRE

# 16

autoplot(sheep)

#ARIMA(3, 1, 0) model.
ggtsdisplay(diff(sheep))

#we see decreasing auto correlation and no lag beyon 3, making this the best model
fcast_sheep_arima.3.1.0 = forecast(
  Arima(sheep, order = c(3, 1, 0)),
  h = 3
)
plot(fcast_sheep_arima.3.1.0)
plot(forecast(auto.arima(sheep), h = 3))

#my forecast is the same as the automated arima model.

# 17

autoplot(bicoal)

#ARIMA model = 4,0,0
ggAcf(bicoal)

ggPacf(bicoal)

#decreasing autocorrelation and no lag beyond 4 indicates this as the best fitting model
fcast_bicoal_arima400 <- forecast(ar(bicoal, 4), h = 3)
plot(fcast_bicoal_arima400)

plot(forecast(auto.arima(bicoal), h = 3))

#Automated forecast is identical to the one i produced

# 18

library(rdatamarket)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
#oil.NA <- ts(rdatamarket::dmseries("http://data.is/1qk5Uvf")[,1], start=1965, frequency=1)
#URL NOT WORKING, but I understand the process of this question as it is reptitive throughout the homework