library(ggplot2)
library(seasonal)
library(forecast)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
### U.S. Exports of Goods by F.A.S. Basis to Mainland China In this exercise, I analyzed the U.S. Exports of Goods by F.A.S. Basis to Mainland China from February 2010 to 2021. The data set is cited below.
U.S. Census Bureau and U.S. Bureau of Economic Analysis, U.S. Exports of Goods by F.A.S. Basis to Mainland China [EXPCH], retrieved from FRED, Federal Reserve Bank of St. Louis; https://fred.stlouisfed.org/series/EXPCH, April 14, 2021.
Exports = read.csv("/Users/austin/Desktop/Graduate\ School\ /Boston\ College/Spring\ Semster\ 2021/Predictive\ Analytics/Discussions/Week\ 3/EXPCH.csv")
#Transform data into time series
ts.Exports = ts(Exports$EXPCH, start=2010,frequency=12)
#Data plot
autoplot(ts.Exports) + ggtitle("U.S. Exports of Goods by F.A.S. Basis to Mainland China 2010-Present")
I then split the data into a training and a testing sety at approximately a 20/80 ratio.
#Split data into a training and testing set - approximately 20/80
train = ts(ts.Exports[1:107], start=2010, frequency=12)
test = ts(ts.Exports[108:133],start=2019, frequency=12)
#ETS ANN Model - Simple Exponential Smoothing Additive
ETS_Model1 = ets(train, model="ANN")
#Analyze model performance
summary(ETS_Model1)
## ETS(A,N,N)
##
## Call:
## ets(y = train, model = "ANN")
##
## Smoothing parameters:
## alpha = 0.7949
##
## Initial states:
## l = 6918.9832
##
## sigma: 1116.753
##
## AIC AICc BIC
## 2005.864 2006.097 2013.883
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 25.9072 1106.267 734.7242 -0.3658869 7.399219 0.764487 0.03390779
autoplot(ETS_Model1)
Forecst_1 = forecast(ETS_Model1, 25)
Accuracy_1 = accuracy(Forecst_1, test[1:25])
#ETS AAA Model - Additive error, Additive trend and Additive seasonality
ETS_Model2 = ets(train, model="AAA")
#Analyze model performance
summary(ETS_Model2)
## ETS(A,A,A)
##
## Call:
## ets(y = train, model = "AAA")
##
## Smoothing parameters:
## alpha = 0.7856
## beta = 1e-04
## gamma = 0.0022
##
## Initial states:
## l = 8161.5622
## b = 16.7406
## s = -569.347 1587.459 1639.443 1897.705 -521.4182 -511.0063
## -789.7723 -645.9408 -787.3465 -721.2203 269.308 -847.8631
##
## sigma: 642.0459
##
## AIC AICc BIC
## 1900.099 1906.976 1945.537
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -28.82896 592.0998 422.4454 -0.4452948 4.413586 0.4395582
## ACF1
## Training set -0.004957213
autoplot(ETS_Model2)
Forecst_2 = forecast(ETS_Model2, 25)
Accuracy_2 = accuracy(Forecst_2, test[1:25])
#ETS MNN - Simple Exponential Smoothing Multiplicative
ETS_Model3 = ets(train, model="MNN")
#Analyze model performance
summary(ETS_Model3)
## ETS(M,N,N)
##
## Call:
## ets(y = train, model = "MNN")
##
## Smoothing parameters:
## alpha = 0.8007
##
## Initial states:
## l = 6832.2834
##
## sigma: 0.1123
##
## AIC AICc BIC
## 1995.200 1995.433 2003.219
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 26.75026 1106.312 733.1161 -0.3501027 7.381873 0.7628138
## ACF1
## Training set 0.02933083
autoplot(ETS_Model3)
Forecst_3 = forecast(ETS_Model3, 25)
Accuracy_3 = accuracy(Forecst_3, test[1:25])
After generating all three models, I graphed the predications for a visual comparison.
#Plot Models
par(mfrow=c(3,1))
plot(Forecst_1, main="ANN")
plot(Forecst_2, main="AAA")
plot(Forecst_3, main="MNN")
The AAA model perfoms the best, across all metrics, out of the three models implemented. In particular, the AAA model exhibited a RMSE of 592.0998 compared to 1106.267 exhbited by the ANN model and 1106.312 generated by the MNN model.