library(tidyr)
library(forecast)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(fma)
library(fpp2)
## ── Attaching packages ────────────────────────────────────────────── fpp2 2.4 ──
## ✓ ggplot2 3.3.5 ✓ expsmooth 2.3
##
#load data
dfhurricane<-read.csv("/Users/Luke/Documents/BC/Predictive Analytics/Discussion 2/hurricanes.csv")
dfhurricane$Date<-as.Date(dfhurricane$Date)
hts2 <- ts(dfhurricane$Storms, frequency = 12, start=c(1950))
hts2
## Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
## 1950 0 0 0 0 0 0 0 4 3 3 2 6
## 1951 3 0 2 0 0 4 0 0 1 0 0 1
## 1952 1 0 4 1 1 1 0 0 2 0 0 0
## 1953 0 2 0 1 4 0 4 2 0 2 0 0
## 1954 1 0 0 1 0 1 1 0 0 5 0 0
## 1955 2 0 0 4 0 0 2 0 0 2 0 4
## 1956 0 2 2 0 5 2 0 1 0 0 4 0
## 1957 0 3 1 0 2 0 0 3 0 0 1 0
## 1958 1 2 0 0 4 0 0 3 0 1 0 3
## 1959 4 0 4 4 1 3 1 0 5 0 0 1
## 1960 0 0 1 0 0 4 0 0 2 0 0 7
## 1961 0 1 4 0 1 0 0 4 0 4 4 0
## 1962 4 1 0 3 1 0 3 0 0 3 0 0
## 1963 7 0 0 5 0 0 3 0 0 2 0 0
## 1964 1 1 0 5 2 0 0 0 0 0 0 1
## 1965 1 4 1 0 0 0 0 0 0 2 0 4
## 1966 1 0 0 0 0 0 0 1 0 4 1 0
## 1967 0 0 0 0 1 2 2 3 2 0 0 0
## 1968 0 0 0 1 2 2 0 0 0 0 0 0
## 1969 0 0 1 6 2 2 0 0 0 0 0 0
## 1970 0 2 1 0 0 0 0 0 0 0 1 5
## 1971 2 0 0 0 0 0 0 1 1 4 1 1
## 1972 0 0 0 0 0 1 0 2 1 0 0 0
## 1973 0 0 0 1 4 4 0 1 0 0 0 0
## 1974 0 0 0 4 3 0 0 0 0 0 0 3
## 1975 0 3 1 0 0 0 0 0 0 0 1 6
## 1976 5 1 0 0 0 0 1 0 2 3 2 0
## 1977 0 0 0 0 0 0 1 6 1 1 0 0
## 1978 0 0 1 1 0 2 0 1 0 0 0 0
## 1979 0 0 2 2 2 0 0 0 0 0 0 1
## 1980 1 4 1 0 0 0 0 0 0 1 1 3
## 1981 1 0 0 0 0 0 1 0 1 2 1 0
## 1982 0 0 0 0 0 0 0 3 2 0 1 0
## 1983 0 0 0 0 1 3 3 0 0 0 0 0
## 1984 0 1 2 2 1 0 0 0 0 0 0 0
## 1985 1 5 1 2 0 0 0 0 1 1 0 4
## 1986 1 2 0 0 0 0 0 2 0 3 0 0
## 1987 0 0 0 0 0 0 0 2 0 0 0 0
## 1988 0 0 0 0 0 6 1 1 0 0 0 0
## 1989 0 0 2 3 2 1 0 0 0 0 0 2
## 1990 0 2 0 1 0 0 0 0 0 0 0 3
## 1991 1 0 0 0 0 0 0 0 0 6 1 1
## 1992 0 0 0 0 0 1 3 2 1 1 0 0
## 1993 0 0 0 0 3 2 4 0 0 0 0 0
## 1994 0 1 0 3 3 0 0 0 0 1 0 0
## 1995 0 4 1 0 0 0 0 0 0 1 0 3
## 1996 0 0 0 0 0 0 0 1 0 2 0 2
## 1997 0 0 0 0 0 1 4 3 4 0 0 0
## 1998 0 0 0 1 2 2 3 1 0 0 0 0
## 1999 1 1 3 1 2 0 0 0 0 0 0 0
## 2000 1 6 2 1 0 0 0 0 0 1 0 3
## 2001 3 1 0 0 0 0 0 0 0 7 4 0
## 2002 0 0 0 0 0 1 0 4 5 2 0 0
## 2003 0 0 0 0 1 8 0 0 0 0 0 1
## 2004 0 1 2 5 2 0 0 0 0 0 0 0
## 2005 1 4 2 1 0 0 0 0 0 2 5 5
## 2006 7 3 0 0 0 0 0 1 2 4 0 0
plot(hts2)
For the first model, I used the ets() function with no model type specified, meaning it chooses the best given the components provided. An ‘ANN’ model was chosen, meaning that it uses an additive model for error and multiplciative models for seasonality.
hets<-ets(hts2)
hets
## ETS(A,N,N)
##
## Call:
## ets(y = hts2)
##
## Smoothing parameters:
## alpha = 0.0119
##
## Initial states:
## l = 1.1011
##
## sigma: 1.4765
##
## AIC AICc BIC
## 5002.170 5002.205 5015.753
plot(hets)
hets2<-ets(hts2, 'AAA')
hets2
## ETS(A,A,A)
##
## Call:
## ets(y = hts2, model = "AAA")
##
## Smoothing parameters:
## alpha = 2e-04
## beta = 2e-04
## gamma = 1e-04
##
## Initial states:
## l = 1.3259
## b = 2e-04
## s = 0.2981 -0.2956 0.4256 -0.2877 -0.0662 -0.2344
## 0.1374 -0.0907 0.2023 -0.2249 -0.0232 0.1592
##
## sigma: 1.4743
##
## AIC AICc BIC
## 5014.004 5014.923 5090.980
plot(hets2)
hets3<-ets(hts2, 'AAN')
hets3
## ETS(A,A,N)
##
## Call:
## ets(y = hts2, model = "AAN")
##
## Smoothing parameters:
## alpha = 1e-04
## beta = 1e-04
##
## Initial states:
## l = 1.4914
## b = -0.0023
##
## sigma: 1.4766
##
## AIC AICc BIC
## 5004.242 5004.331 5026.882
plot(hets3)
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.