Hanyue Kuang
I use the data of monthly traffic fatalities in Ontario from 1960 to 1974
traffic <- read.csv("C:/Users/Kuang/Downloads/monthly-traffic-fatalities-in-on.csv")
str(traffic)
## 'data.frame': 180 obs. of 2 variables:
## $ Month : Factor w/ 180 levels "1960-01","1960-02",..: 1 2 3 4 5 6 7 8 9 10 ...
## $ Monthly.traffic.fatalities.in.Ontario.1960.1974: int 61 65 55 56 91 80 135 129 129 130 ...
traffic$Month <- NULL
traffic.ts <- ts(traffic,star = c(1960),frequency=12)
str(traffic.ts)
## Time-Series [1:180, 1] from 1960 to 1975: 61 65 55 56 91 80 135 129 129 130 ...
## - attr(*, "dimnames")=List of 2
## ..$ : NULL
## ..$ : chr "Monthly.traffic.fatalities.in.Ontario.1960.1974"
head(traffic.ts)
## Jan Feb Mar Apr May Jun
## 1960 61 65 55 56 91 80
autoplot(traffic.ts) +
xlab ("time") +
ylab ("number") +
ggtitle("monthly traffic fatalities in Ontario from 1960 to 1974")
There is obvious seasonalnality and I would use the data of the most recent five years. I would fit 3 models: simple exponential smoothing, Holt- Winter and ETS.
SES
ft_ses <- ses(traffic.ts, h =60)
summary(ft_ses)
##
## Forecast method: Simple exponential smoothing
##
## Model Information:
## Simple exponential smoothing
##
## Call:
## ses(y = traffic.ts, h = 60)
##
## Smoothing parameters:
## alpha = 0.9289
##
## Initial states:
## l = 61.2728
##
## sigma: 28.0957
##
## AIC AICc BIC
## 2139.543 2139.680 2149.122
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.3911206 27.9392 22.4127 -2.358933 18.28222 1.239412
## ACF1
## Training set -0.01177359
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 1975 126.6719 90.6657584 162.6780 71.6052675 181.7385
## Feb 1975 126.6719 77.5273895 175.8164 51.5118662 201.8319
## Mar 1975 126.6719 67.2250877 186.1187 35.7558552 217.5879
## Apr 1975 126.6719 58.4614608 194.8823 22.3530444 230.9907
## May 1975 126.6719 50.7021395 202.6416 10.4861865 242.8576
## Jun 1975 126.6719 43.6650028 209.6788 -0.2761853 253.6200
## Jul 1975 126.6719 37.1795236 216.1642 -10.1948698 263.5386
## Aug 1975 126.6719 31.1332906 222.2105 -19.4417851 272.7856
## Sep 1975 126.6719 25.4475635 227.8962 -28.1373544 281.4811
## Oct 1975 126.6719 20.0646455 233.2791 -36.3698171 289.7136
## Nov 1975 126.6719 14.9407623 238.4030 -44.2061201 297.5499
## Dec 1975 126.6719 10.0417687 243.3020 -51.6984843 305.0423
## Jan 1976 126.6719 5.3404205 248.0033 -58.8885759 312.2323
## Feb 1976 126.6719 0.8145669 252.5292 -65.8102718 319.1540
## Mar 1976 126.6719 -3.5540908 256.8979 -72.4915571 325.8353
## Apr 1976 126.6719 -7.7808763 261.1246 -78.9558677 332.2996
## May 1976 126.6719 -11.8787746 265.2225 -85.2230623 338.5668
## Jun 1976 126.6719 -15.8589030 269.2027 -91.3101434 344.6539
## Jul 1976 126.6719 -19.7308669 273.0746 -97.2318012 350.5756
## Aug 1976 126.6719 -23.5030330 276.8468 -103.0008315 356.3446
## Sep 1976 126.6719 -27.1827420 280.5265 -108.6284607 361.9722
## Oct 1976 126.6719 -30.7764764 284.1202 -114.1246032 367.4684
## Nov 1976 126.6719 -34.2899948 287.6338 -119.4980659 372.8418
## Dec 1976 126.6719 -37.7284404 291.0722 -124.7567146 378.1005
## Jan 1977 126.6719 -41.0964292 294.4402 -129.9076089 383.2514
## Feb 1977 126.6719 -44.3981225 297.7419 -134.9571132 388.3009
## Mar 1977 126.6719 -47.6372878 300.9811 -139.9109890 393.2548
## Apr 1977 126.6719 -50.8173484 304.1611 -144.7744720 398.1182
## May 1977 126.6719 -53.9414263 307.2852 -149.5523368 402.8961
## Jun 1977 126.6719 -57.0123780 310.3561 -154.2489521 407.5927
## Jul 1977 126.6719 -60.0328249 313.3766 -158.8683271 412.2121
## Aug 1977 126.6719 -63.0051799 316.3489 -163.4141517 416.7579
## Sep 1977 126.6719 -65.9316695 319.2754 -167.8898313 421.2336
## Oct 1977 126.6719 -68.8143535 322.1581 -172.2985161 425.6423
## Nov 1977 126.6719 -71.6551421 324.9989 -176.6431273 429.9869
## Dec 1977 126.6719 -74.4558106 327.7996 -180.9263801 434.2701
## Jan 1978 126.6719 -77.2180122 330.5618 -185.1508029 438.4946
## Feb 1978 126.6719 -79.9432897 333.2871 -189.3187552 442.6625
## Mar 1978 126.6719 -82.6330854 335.9769 -193.4324428 446.7762
## Apr 1978 126.6719 -85.2887502 338.6325 -197.4939317 450.8377
## May 1978 126.6719 -87.9115513 341.2553 -201.5051597 454.8489
## Jun 1978 126.6719 -90.5026793 343.8464 -205.4679480 458.8117
## Jul 1978 126.6719 -93.0632547 346.4070 -209.3840102 462.7278
## Aug 1978 126.6719 -95.5943334 348.9381 -213.2549611 466.5987
## Sep 1978 126.6719 -98.0969120 351.4407 -217.0823247 470.4261
## Oct 1978 126.6719 -100.5719319 353.9157 -220.8675411 474.2113
## Nov 1978 126.6719 -103.0202842 356.3641 -224.6119727 477.9557
## Dec 1978 126.6719 -105.4428126 358.7866 -228.3169101 481.6607
## Jan 1979 126.6719 -107.8403174 361.1841 -231.9835773 485.3273
## Feb 1979 126.6719 -110.2135584 363.5573 -235.6131363 488.9569
## Mar 1979 126.6719 -112.5632578 365.9070 -239.2066914 492.5505
## Apr 1979 126.6719 -114.8901025 368.2339 -242.7652932 496.1091
## May 1979 126.6719 -117.1947466 370.5385 -246.2899423 499.6337
## Jun 1979 126.6719 -119.4778139 372.8216 -249.7815924 503.1254
## Jul 1979 126.6719 -121.7398992 375.0837 -253.2411532 506.5849
## Aug 1979 126.6719 -123.9815705 377.3253 -256.6694937 510.0133
## Sep 1979 126.6719 -126.2033708 379.5471 -260.0674440 513.4112
## Oct 1979 126.6719 -128.4058193 381.7496 -263.4357983 516.7796
## Nov 1979 126.6719 -130.5894130 383.9332 -266.7753168 520.1191
## Dec 1979 126.6719 -132.7546281 386.0984 -270.0867275 523.4305
autoplot(ft_ses) +
autolayer(fitted(ft_ses)) +
xlab ("time") +
ylab ("number") +
ggtitle("simple exponential smoothing")
HW
traf <- window(traffic.ts, start = 1970)
ft_hw1 <- hw(traf,seasonal = "additive")
ft_hw2 <- hw(traf,seasonal="multiplicative")
summary(ft_hw1)
##
## Forecast method: Holt-Winters' additive method
##
## Model Information:
## Holt-Winters' additive method
##
## Call:
## hw(y = traf, seasonal = "additive")
##
## Smoothing parameters:
## alpha = 0.346
## beta = 2e-04
## gamma = 6e-04
##
## Initial states:
## l = 132.5107
## b = 0.141
## s = -0.036 11.5511 34.2654 43.1948 58.7268 38.0405
## 16.9287 -7.8324 -40.5813 -45.12 -66.2986 -42.8391
##
## sigma: 18.7633
##
## AIC AICc BIC
## 612.8796 627.4510 648.4834
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.05894426 16.06791 13.01744 -0.4705442 9.244721 0.6048763
## ACF1
## Training set 0.04298654
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 1975 97.38640 73.34029 121.43251 60.61105 134.1617
## Feb 1975 74.08308 48.63707 99.52909 35.16677 112.9994
## Mar 1975 95.40027 68.62625 122.17429 54.45294 136.3476
## Apr 1975 100.07523 72.03488 128.11558 57.19122 142.9592
## May 1975 132.95526 103.70224 162.20827 88.21663 177.6939
## Jun 1975 157.83262 127.41419 188.25106 111.31164 204.3536
## Jul 1975 179.11244 147.57059 210.65429 130.87334 227.3515
## Aug 1975 199.93924 167.31165 232.56684 150.03965 249.8388
## Sep 1975 184.53088 150.85157 218.21020 133.02282 236.0389
## Oct 1975 175.75143 141.05133 210.45153 122.68220 228.8207
## Nov 1975 153.19690 117.50428 188.88952 98.60975 207.7841
## Dec 1975 141.72046 105.06131 178.37961 85.65512 197.7858
## Jan 1976 99.07118 61.46623 136.67612 41.55938 156.5830
## Feb 1976 75.76786 37.24265 114.29307 16.84863 134.6871
## Mar 1976 97.08505 57.66022 136.50988 36.78998 157.3801
## Apr 1976 101.76001 61.45483 142.06518 40.11856 163.4015
## May 1976 134.64003 93.47254 175.80752 71.67979 197.6003
## Jun 1976 159.51740 117.50452 201.53028 95.26425 223.7706
## Jul 1976 180.79722 137.95486 223.63957 115.27549 246.3189
## Aug 1976 201.62402 157.96721 245.28083 134.85669 268.3913
## Sep 1976 186.21566 141.75858 230.67274 118.22442 254.2069
## Oct 1976 177.43621 132.19229 222.68013 108.24161 246.6308
## Nov 1976 154.88168 108.86367 200.89969 84.50320 225.2602
## Dec 1976 143.40524 96.62524 190.18523 71.86141 214.9491
summary(ft_hw2)
##
## Forecast method: Holt-Winters' multiplicative method
##
## Model Information:
## Holt-Winters' multiplicative method
##
## Call:
## hw(y = traf, seasonal = "multiplicative")
##
## Smoothing parameters:
## alpha = 0.3212
## beta = 0.0105
## gamma = 1e-04
##
## Initial states:
## l = 134.9769
## b = 1.9389
## s = 0.9603 1.0845 1.1853 1.2626 1.3835 1.261
## 1.0796 0.976 0.7714 0.7429 0.5946 0.6981
##
## sigma: 0.1149
##
## AIC AICc BIC
## 599.6460 614.2175 635.2499
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -2.550047 15.46011 12.13759 -2.942856 8.474423 0.5639924
## ACF1
## Training set 0.02311535
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## Jan 1975 100.18499 85.43563 114.93435 77.62779 122.7422
## Feb 1975 85.33335 72.08862 98.57807 65.07729 105.5894
## Mar 1975 106.63574 89.22248 124.04900 80.00445 133.2670
## Apr 1975 110.71948 91.73348 129.70548 81.68289 139.7561
## May 1975 140.10237 114.91780 165.28694 101.58589 178.6189
## Jun 1975 154.98854 125.82936 184.14772 110.39343 199.5837
## Jul 1975 181.04057 145.44489 216.63626 126.60167 235.4795
## Aug 1975 198.63676 157.87696 239.39656 136.30003 260.9735
## Sep 1975 181.28940 142.51530 220.06349 121.98953 240.5893
## Oct 1975 170.20216 132.30440 208.09993 112.24253 228.1618
## Nov 1975 155.73344 119.67352 191.79336 100.58455 210.8823
## Dec 1975 137.90727 104.73548 171.07907 87.17539 188.6392
## Jan 1976 100.25086 75.22503 125.27668 61.97717 138.5245
## Feb 1976 85.38945 63.28858 107.49031 51.58909 119.1898
## Mar 1976 106.70584 78.09598 135.31569 62.95084 150.4608
## Apr 1976 110.79226 80.04567 141.53885 63.76940 157.8151
## May 1976 140.19446 99.95660 180.43232 78.65597 201.7330
## Jun 1976 155.09041 109.08820 201.09263 84.73609 225.4447
## Jul 1976 181.15956 125.66709 236.65203 96.29115 266.0280
## Aug 1976 198.76731 135.93246 261.60215 102.66970 294.8649
## Sep 1976 181.40853 122.26416 240.55291 90.95501 271.8621
## Oct 1976 170.31401 113.08237 227.54565 82.78577 257.8423
## Nov 1976 155.83577 101.89405 209.77748 73.33903 238.3325
## Dec 1976 137.99789 88.82174 187.17403 62.78946 213.2063
autoplot(traf) +
autolayer(ft_hw1, series="HW additive forecasts", PI=FALSE) +
autolayer(ft_hw2, series="HW multiplicative forecasts",PI=FALSE) +
xlab("Year") +
ylab("Number") +
ggtitle("Holt-Winters' seasonal method")
The reason I use HW instead of Holt is the obvious seasonality in my data
ETS
ft_ets <- ets(traf, model = "ZZZ", damped = TRUE)
summary(ft_ets)
## ETS(M,Ad,M)
##
## Call:
## ets(y = traf, model = "ZZZ", damped = TRUE)
##
## Smoothing parameters:
## alpha = 0.267
## beta = 0.0048
## gamma = 1e-04
## phi = 0.9307
##
## Initial states:
## l = 129.4913
## b = 1.6794
## s = 0.9737 1.0995 1.2244 1.2562 1.3927 1.2576
## 1.0906 0.956 0.7542 0.7199 0.5775 0.6978
##
## sigma: 0.1147
##
## AIC AICc BIC
## 598.1907 614.8736 635.8889
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.7069355 15.23801 12.10671 -1.294796 8.312573 0.5625576
## ACF1
## Training set 0.07959148
fc_ets <- forecast(ft_ets, h=24)
autoplot(fc_ets) +
autolayer(fitted(fc_ets), series = "Fitted") +
xlab("Time") +
ylab("Number") +
ggtitle("ETS")
The model ETS choosed is MAM. It has the least AIC. I will choose ETS.