I’m using the same data set as last discussion’s data set
dis2data <- read.csv("~/Documents/bc/forecasting/dis2/dis2data.csv")
library(forecast)
## Warning: package 'forecast' was built under R version 3.4.4
mydata<-dis2data
myts<-ts(mydata[,2],frequency=12)
str(myts)
## Time-Series [1:77] from 1 to 7.33: 154 96 73 49 36 59 95 169 219 278 ...
train=ts(myts[1:60],frequency = 12)
test=ts(myts[61:77],frequency=12)
myarima=auto.arima(train)
myarima
## Series: train
## ARIMA(1,1,0)(0,1,0)[12]
##
## Coefficients:
## ar1
## -0.5484
## s.e. 0.1202
##
## sigma^2 estimated as 2032: log likelihood=-245.36
## AIC=494.72 AICc=494.99 BIC=498.42
Since it requires to build two Arima model, I’m going to try antoher one with (1,1,0)(0,1,1)[12]
myarima2=arima(train,order=c(1,1,1), seasonal=c(0,1,0))
myarima2
##
## Call:
## arima(x = train, order = c(1, 1, 1), seasonal = c(0, 1, 0))
##
## Coefficients:
## ar1 ma1
## -0.7461 0.2950
## s.e. 0.1674 0.2454
##
## sigma^2 estimated as 1939: log likelihood = -244.78, aic = 495.56
Just by comparing the aic, myarima AIC< myarima 2 AIC, so auto.arima is the best Arima Model
f1=forecast(myarima,12)
acc1=accuracy(f1,test[1:12])
plot(f1)
mye=ets(train,model="ZZZ")
mye
## ETS(M,N,M)
##
## Call:
## ets(y = train, model = "ZZZ")
##
## Smoothing parameters:
## alpha = 0.5675
## gamma = 1e-04
##
## Initial states:
## l = 173.9233
## s=1.2686 1.7926 1.7704 1.3514 1.0016 0.7249
## 0.4926 0.4843 0.4442 0.6365 0.8313 1.2015
##
## sigma: 0.213
##
## AIC AICc BIC
## 710.6951 721.6042 742.1102
mye2=ets(train,model="MAM")
mye2
## ETS(M,A,M)
##
## Call:
## ets(y = train, model = "MAM")
##
## Smoothing parameters:
## alpha = 0.341
## beta = 1e-04
## gamma = 0.0013
##
## Initial states:
## l = 106.6754
## b = 5.5695
## s=1.3398 1.742 1.8086 1.3795 0.9632 0.7054
## 0.459 0.5098 0.4416 0.6285 0.7967 1.2261
##
## sigma: 0.1973
##
## AIC AICc BIC
## 707.6150 722.1865 743.2189
Since model MAM aic< model ZZZ aic, so I choose MAM and I’m going to continue to use this model for forecasting
f2=forecast(mye2,12)#12 here i want to forecast for the next 12 month
acc2=accuracy(f2,test[1:12])
acc2
## ME RMSE MAE MPE MAPE MASE
## Training set -0.02513019 39.56000 30.66490 -3.638508 14.47064 0.4670183
## Test set 28.85524028 56.07996 42.26627 5.826222 10.95152 0.6437041
## ACF1
## Training set 0.372519
## Test set NA
plot(f2)
acc1
## ME RMSE MAE MPE MAPE MASE
## Training set 2.170204 39.47170 27.03341 -1.926934 12.08717 0.4117118
## Test set -43.707248 87.17862 75.84093 -17.706821 21.85138 1.1550374
## ACF1
## Training set 0.06643286
## Test set NA
acc2
## ME RMSE MAE MPE MAPE MASE
## Training set -0.02513019 39.56000 30.66490 -3.638508 14.47064 0.4670183
## Test set 28.85524028 56.07996 42.26627 5.826222 10.95152 0.6437041
## ACF1
## Training set 0.372519
## Test set NA
Conclustion: By comparing aic, bic, Arima model has the lower value than ETS, Arima model is better. When forecasting, by comparing RMSE, MAE, ME, MAPE, MASE, ETS has lower values and it will get better result due to higher accuracy.