I used sea ice data for the artic and antartica. For spelling reasons I went with the arctic to investigate. Data is from 1990 to 2011 and measures the sea ice each month.
library(readxl)
seaice<-read_excel("Documents/Data Analysis and econometrics/seaice.xlsx",skip=1)
library(forecast)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
t=c(1:255)
icets<-ts(seaice$Arctic,t,frequency = 12)
icetrain=window(icets,end=c(t=250))
## Warning in window.default(x, ...): 'end' value not changed
ice<-icetrain
I don’t know how it happened, but I just stumbled across formatting data in the correct form. The date was like 1990Mo1 for January 1990 and I couldn’t reformat it so I had t as vector 1:250. Then when I tried to split up the data in training and test I ended up creating a time series with teh correct month as a fluke.
str(seaice)
## Classes 'tbl_df', 'tbl' and 'data.frame': 255 obs. of 3 variables:
## $ Time : chr "1990M01" "1990M02" "1990M03" "1990M04" ...
## $ Arctic : num 12.7 13.3 13.4 12.2 10.8 ...
## $ Antarctica: num 3.27 2.15 2.71 5.1 7.37 ...
str(icetrain)
## Time-Series [1:255] from 1.08 to 22.2: 12.7 13.3 13.4 12.2 10.8 ...
head(icetrain)
## Feb Mar Apr May Jun Jul
## 1 12.72 13.33 13.44 12.16 10.84 9.12
plot(ice)
The Plot shows that there is seasonal data as expecetd occuring each year and there is a slight downward trend.
library(seasonal)
ggseasonplot(ice)
The seasonal plots shows peaks of seaice in the arctic around mid march and valleys around October. There is also a clear color change with the pick color representing later years underneath the earlier years.
decice1<-decompose(ice,type="additive")
plot(decice1)
decice2<-decompose(ice,type="multiplicative")
plot(decice2)
Seasonal varaition seems to relatively constant so I will stay with teh additive model. The decompositions show a very clear downward trend in volume of sea ice.
etsm1<-ets(ice,model="ZZZ")
etsm1fc<-forecast(etsm1)
plot(etsm1fc)
Forecast looks pretty consistent with the model.
etsm2<-ets(ice,model="ANN")
etsm2fc<-forecast(etsm2)
plot(etsm2fc)
This model obviosuly doesn’t look very good.
etsm3<-HoltWinters(ice)
etsm3fc<-forecast(etsm3)
plot(etsm3fc)
This model forecast looks very similar to the first model forecast.
checkresiduals(etsm1fc)
##
## Ljung-Box test
##
## data: Residuals from ETS(A,N,A)
## Q* = 42.948, df = 10, p-value = 5.081e-06
##
## Model df: 14. Total lags used: 24
checkresiduals(etsm3fc)
## Warning in modeldf.default(object): Could not find appropriate degrees of
## freedom for this model.
The residuals look very similar. Some autocorrelation issues with model one, but the Ljung score isn’t working for model 3.
summary(etsm1fc)
##
## Forecast method: ETS(A,N,A)
##
## Model Information:
## ETS(A,N,A)
##
## Call:
## ets(y = ice, model = "ZZZ")
##
## Smoothing parameters:
## alpha = 0.8558
## gamma = 0.0717
##
## Initial states:
## l = 10.128
## s = 1.5667 -0.4119 -2.8943 -5.182 -4.8481 -3.1822
## -0.377 1.6298 3.1236 3.878 3.7794 2.9181
##
## sigma: 0.2885
##
## AIC AICc BIC
## 794.6248 796.6332 847.7437
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.007374582 0.2804479 0.2071677 -0.2885499 2.667098 0.5986652
## ACF1
## Training set 0.02572337
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## May 22 11.663516 11.293815 12.033216 11.098108 12.228923
## Jun 22 10.185446 9.698836 10.672056 9.441240 10.929652
## Jul 22 8.095034 7.514602 8.675465 7.207341 8.982727
## Aug 22 5.337462 4.676393 5.998530 4.326445 6.348479
## Sep 22 3.637463 2.904576 4.370349 2.516609 4.758316
## Oct 22 3.358789 2.560519 4.157058 2.137941 4.579636
## Nov 22 5.437538 4.578850 6.296226 4.124288 6.750788
## Dec 22 8.203300 7.288174 9.118426 6.803735 9.602865
## Jan 23 10.071333 9.103052 11.039613 8.590476 11.552190
## Feb 23 11.436281 10.417616 12.454946 9.878367 12.994194
## Mar 23 12.257284 11.190611 13.323956 10.625949 13.888618
## Apr 23 12.404522 11.284085 13.524958 10.690962 14.118082
## May 23 11.663516 10.499261 12.827771 9.882941 13.444090
## Jun 23 10.185446 8.978963 11.391928 8.340290 12.030602
## Jul 23 8.095034 6.847752 9.342315 6.187481 10.002587
## Aug 23 5.337462 4.050674 6.624250 3.369490 7.305434
## Sep 23 3.637463 2.312346 4.962579 1.610872 5.664054
## Oct 23 3.358789 1.996421 4.721156 1.275227 5.442350
## Nov 23 5.437538 4.038911 6.836164 3.298523 7.576553
## Dec 23 8.203300 6.769331 9.637269 6.010234 10.396366
## Jan 24 10.071333 8.602872 11.539794 7.825515 12.317151
## Feb 24 11.436281 9.934119 12.938442 9.138923 13.733639
## Mar 24 12.257284 10.722161 13.792406 9.909517 14.605051
## Apr 24 12.404522 10.831566 13.977477 9.998894 14.810150
summary(etsm2fc)
##
## Forecast method: ETS(A,N,N)
##
## Model Information:
## ETS(A,N,N)
##
## Call:
## ets(y = ice, model = "ANN")
##
## Smoothing parameters:
## alpha = 0.9999
##
## Initial states:
## l = 12.7043
##
## sigma: 1.724
##
## AIC AICc BIC
## 1694.779 1694.875 1705.403
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.001193473 1.717209 1.480981 -2.833666 19.21844 4.279682
## ACF1
## Training set 0.7928522
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## May 22 12.39999 10.190618 14.60937 9.0210465 15.77894
## Jun 22 12.39999 9.275622 15.52436 7.6216804 17.17830
## Jul 22 12.39999 8.573500 16.22648 6.5478770 18.25211
## Aug 22 12.39999 7.981576 16.81841 5.6426079 19.15738
## Sep 22 12.39999 7.460078 17.33991 4.8450447 19.95494
## Oct 22 12.39999 6.988605 17.81138 4.1239895 20.67599
## Nov 22 12.39999 6.555040 18.24494 3.4609089 21.33908
## Dec 22 12.39999 6.151486 18.64850 2.8437273 21.95626
## Jan 23 12.39999 5.772460 19.02752 2.2640567 22.53593
## Feb 23 12.39999 5.413968 19.38602 1.7157900 23.08419
## Mar 23 12.39999 5.072995 19.72699 1.1943166 23.60567
## Apr 23 12.39999 4.747199 20.05279 0.6960546 24.10393
## May 23 12.39999 4.434717 20.36527 0.2181556 24.58183
## Jun 23 12.39999 4.134040 20.66594 -0.2416902 25.04167
## Jul 23 12.39999 3.843923 20.95606 -0.6853860 25.48537
## Aug 23 12.39999 3.563326 21.23666 -1.1145226 25.91451
## Sep 23 12.39999 3.291368 21.50862 -1.5304457 26.33043
## Oct 23 12.39999 3.027299 21.77269 -1.9343054 26.73429
## Nov 23 12.39999 2.770468 22.02952 -2.3270943 27.12708
## Dec 23 12.39999 2.520311 22.27967 -2.7096758 27.50966
## Jan 24 12.39999 2.276334 22.52365 -3.0828065 27.88279
## Feb 24 12.39999 2.038100 22.76188 -3.4471541 28.24714
## Mar 24 12.39999 1.805222 22.99476 -3.8033110 28.60329
## Apr 24 12.39999 1.577353 23.22263 -4.1518060 28.95179
summary(etsm3fc)
##
## Forecast method: HoltWinters
##
## Model Information:
## Holt-Winters exponential smoothing with trend and additive seasonal component.
##
## Call:
## HoltWinters(x = ice)
##
## Smoothing parameters:
## alpha: 0.682639
## beta : 0.005483708
## gamma: 0.7668086
##
## Coefficients:
## [,1]
## a 8.452755252
## b 0.001475716
## s1 3.190524180
## s2 1.552277723
## s3 -0.689096050
## s4 -3.473405187
## s5 -5.212829947
## s6 -5.487588817
## s7 -3.420518142
## s8 -0.303108537
## s9 1.666222516
## s10 2.994450600
## s11 3.799719236
## s12 3.953312646
##
## Error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -0.0241825 0.2989783 0.2226134 -0.7663256 2.936057 0.6432996
## ACF1
## Training set 0.1426731
##
## Forecasts:
## Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
## May 22 11.644755 11.262066 12.027444 11.059483 12.230027
## Jun 22 10.007984 9.543822 10.472147 9.298109 10.717860
## Jul 22 7.768086 7.234047 8.302125 6.951344 8.584828
## Aug 22 4.985253 4.388841 5.581665 4.073120 5.897386
## Sep 22 3.247304 2.593867 3.900740 2.247959 4.246649
## Oct 22 2.974021 2.267608 3.680433 1.893656 4.054385
## Nov 22 5.042567 4.286374 5.798761 3.886069 6.199065
## Dec 22 8.161452 7.358076 8.964829 6.932794 9.390111
## Jan 23 10.132259 9.283862 10.980657 8.834747 11.429772
## Feb 23 11.461963 10.570376 12.353550 10.098399 12.825527
## Mar 23 12.268707 11.335507 13.201907 10.841501 13.695914
## Apr 23 12.423776 11.450335 13.397218 10.935025 13.912527
## May 23 11.662464 10.620521 12.704407 10.068950 13.255978
## Jun 23 10.025693 8.946820 11.104566 8.375699 11.675687
## Jul 23 7.785795 6.670854 8.900736 6.080640 9.490950
## Aug 23 5.002962 3.852732 6.153191 3.243837 6.762086
## Sep 23 3.265012 2.080202 4.449822 1.453002 5.077023
## Oct 23 2.991729 1.772985 4.210474 1.127821 4.855638
## Nov 23 5.060276 3.808189 6.312362 3.145375 6.975177
## Dec 23 8.179161 6.894277 9.464045 6.214100 10.144222
## Jan 24 10.149968 8.832788 11.467148 8.135514 12.164421
## Feb 24 11.479672 10.130660 12.828683 9.416536 13.542807
## Mar 24 12.286416 10.906004 13.666828 10.175258 14.397574
## Apr 24 12.441485 11.030073 13.852897 10.282917 14.600053
So the ZZZ clearly trumps the ANN model reagrding the AIc and BIC. The same metrics are not available for the Holt Winters but the RSME is just slightly smaller with the ZZZ.