library(rmarkdown)
## Warning: package 'rmarkdown' was built under R version 4.0.5
library(forecast)
## Warning: package 'forecast' was built under R version 4.0.5
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
library(tseries)
## Warning: package 'tseries' was built under R version 4.0.5
library(timeSeries)
## Warning: package 'timeSeries' was built under R version 4.0.5
## Loading required package: timeDate
## Warning: package 'timeDate' was built under R version 4.0.5
library(xts)
## Warning: package 'xts' was built under R version 4.0.5
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 4.0.5
## 
## Attaching package: 'zoo'
## The following object is masked from 'package:timeSeries':
## 
##     time<-
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(quantmod)
## Warning: package 'quantmod' was built under R version 4.0.5
## Loading required package: TTR
## Warning: package 'TTR' was built under R version 4.0.5
library(readr)
## Warning: package 'readr' was built under R version 4.0.5
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.0.5
mydata <- read.csv("~/College Documents/Boston College/unemployment.csv")

str(mydata)
## 'data.frame':    382 obs. of  2 variables:
##  $ DATE: chr  "1990-01" "1990-02" "1990-03" "1990-04" ...
##  $ u   : num  10 10.1 10.1 10.1 10.3 ...
mydata=ts(mydata$u, frequency=12, start=c(1990,1))


plot(mydata)

train.ts<-window(mydata, end=c(2019,12))
test.ts<-window(mydata,start=c(2017,1))
plot(decompose(train.ts))

acf(train.ts)

pacf(train.ts)

fit.nn<-nnetar(train.ts)
fit.ets<-ets(train.ts)
fit.aa<-auto.arima(train.ts)


fit.nn
## Series: train.ts 
## Model:  NNAR(25,1,13)[12] 
## Call:   nnetar(y = train.ts)
## 
## Average of 20 networks, each of which is
## a 25-13-1 network with 352 weights
## options were - linear output units 
## 
## sigma^2 estimated as 0.0007581
fit.ets
## ETS(M,N,N) 
## 
## Call:
##  ets(y = train.ts) 
## 
##   Smoothing parameters:
##     alpha = 0.8921 
## 
##   Initial states:
##     l = 10.0301 
## 
##   sigma:  0.018
## 
##      AIC     AICc      BIC 
## 842.5236 842.5910 854.1819
fit.aa
## Series: train.ts 
## ARIMA(0,1,1)(1,0,2)[12] 
## 
## Coefficients:
##           ma1    sar1     sma1     sma2
##       -0.1335  0.2058  -0.3368  -0.0952
## s.e.   0.0527  0.3982   0.3985   0.0844
## 
## sigma^2 estimated as 0.02848:  log likelihood=130.99
## AIC=-251.99   AICc=-251.82   BIC=-232.57
f.nn<-forecast(fit.nn)
f.ets<-forecast(fit.ets)
f.aa<-forecast(fit.aa)
plot(f.nn)

plot(f.ets)

plot(f.aa)

acc.nn<-accuracy(f.nn, test.ts)
acc.ets<-accuracy(f.ets, test.ts)
acc.aa<-accuracy(f.aa, test.ts)
acc.nn
##                        ME       RMSE        MAE           MPE       MAPE
## Training set  0.000406133 0.02753348 0.01817281   0.001532665  0.1988821
## Test set     -1.117671454 1.24337777 1.11767145 -14.761759556 14.7617596
##                   MASE         ACF1 Theil's U
## Training set 0.0441407 -0.007520579        NA
## Test set     2.7147596  0.306751206  2.172215
acc.ets
##                        ME      RMSE       MAE          MPE     MAPE      MASE
## Training set -0.003950651 0.1703173 0.1249332  -0.06008919  1.32635 0.3034556
## Test set     -0.893255366 1.0324101 0.8979587 -11.88304818 11.93647 2.1810900
##                     ACF1 Theil's U
## Training set 0.005904945        NA
## Test set     0.261105252  1.799568
acc.aa
##                        ME      RMSE       MAE          MPE      MAPE      MASE
## Training set -0.005348857 0.1675941 0.1215799  -0.07790713  1.290701 0.2953106
## Test set     -0.920190686 1.0598057 0.9267680 -12.23296324 12.307635 2.2510661
##                      ACF1 Theil's U
## Training set -0.002900959        NA
## Test set      0.244090380  1.844597
train.ts<-window(mydata, end=c(2020,12))
test.ts<-window(mydata,start=c(2021,01))

fit.nn<-nnetar(train.ts)
fit.ets<-ets(train.ts)
fit.aa<-auto.arima(train.ts)
fit.nn
## Series: train.ts 
## Model:  NNAR(13,1,7)[12] 
## Call:   nnetar(y = train.ts)
## 
## Average of 20 networks, each of which is
## a 13-7-1 network with 106 weights
## options were - linear output units 
## 
## sigma^2 estimated as 0.01774
fit.ets
## ETS(A,N,N) 
## 
## Call:
##  ets(y = train.ts) 
## 
##   Smoothing parameters:
##     alpha = 0.8101 
## 
##   Initial states:
##     l = 10.0401 
## 
##   sigma:  0.217
## 
##      AIC     AICc      BIC 
## 1069.068 1069.133 1080.825
fit.aa
## Series: train.ts 
## ARIMA(0,1,1)(0,0,1)[12] 
## 
## Coefficients:
##           ma1     sma1
##       -0.2026  -0.1380
## s.e.   0.0553   0.0651
## 
## sigma^2 estimated as 0.04661:  log likelihood=43.16
## AIC=-80.33   AICc=-80.26   BIC=-68.58
f.nn<-forecast(fit.nn)
f.ets<-forecast(fit.ets)
f.aa<-forecast(fit.aa)
plot(f.nn)

plot(f.ets)

plot(f.aa)

acc.nn<-accuracy(f.nn, test.ts)
acc.ets<-accuracy(f.ets, test.ts)
acc.aa<-accuracy(f.aa, test.ts)
acc.nn
##                        ME      RMSE        MAE          MPE       MAPE
## Training set  0.000265229 0.1331862 0.09076487  -0.03385538  0.9900594
## Test set     -1.289512513 1.3513405 1.28951251 -16.32514288 16.3251429
##                   MASE         ACF1 Theil's U
## Training set 0.2082923 -0.007618107        NA
## Test set     2.9592453  0.494653058  7.820522
acc.ets
##                        ME      RMSE       MAE        MPE     MAPE      MASE
## Training set -0.007466718 0.2164075 0.1332672 -0.1255967 1.463752 0.3058290
## Test set      0.103714390 0.1996463 0.1475278  1.2680161 1.841490 0.3385551
##                   ACF1 Theil's U
## Training set 0.0128053        NA
## Test set     0.2125663   1.10871
acc.aa
##                        ME      RMSE       MAE        MPE     MAPE      MASE
## Training set -0.008184355 0.2150265 0.1324155 -0.1347985 1.455732 0.3038744
## Test set     -0.020051046 0.1801979 0.1534100 -0.2942470 1.932382 0.3520539
##                    ACF1 Theil's U
## Training set 0.01234188        NA
## Test set     0.13641492 0.9976622

Using RMSE as my measure, since it, being square root of the variance of the residuals indicates thehow close the predicted value was to the actual value, will give me a good idea of which model is most accurate. The lowest value meaning is was closest to the actual data was the ARIMA mode. Given the volitality between that and the ETS model are similar I believe the ARIMA model best.