inst— title: ‘Forecasting Assignment #1’ author: “Jerome Dixon” date: “September 6, 2017” output: html_document —

Develop a forecast for the call volume for products 3 and 4 using exponential smoothing. You should justify the criteria you choose for selecting your best model and the reasoning behind your model development. ###

library(readr)          # read in data table
library(tidyverse)      # data manipulation and visualization
## Loading tidyverse: ggplot2
## Loading tidyverse: tibble
## Loading tidyverse: tidyr
## Loading tidyverse: purrr
## Loading tidyverse: dplyr
## Warning: package 'purrr' was built under R version 3.4.1
## Warning: package 'dplyr' was built under R version 3.4.1
## Conflicts with tidy packages ----------------------------------------------
## filter(): dplyr, stats
## lag():    dplyr, stats
library(lubridate)      # easily work with dates and times
## Warning: package 'lubridate' was built under R version 3.4.1
## 
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
## 
##     date
library(xts)            # Overarching time series forecasting package
## Warning: package 'xts' was built under R version 3.4.1
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## Attaching package: 'xts'
## The following objects are masked from 'package:dplyr':
## 
##     first, last
library(forecast)       # forecasting package
## Warning: package 'forecast' was built under R version 3.4.1
library(TTR)            # decomposing time series trends/components
## Warning: package 'TTR' was built under R version 3.4.1
library(zoo)            # helper package for working with time series data
library(ggfortify)      # visualize time series objects with ggplot
## 
## Attaching package: 'ggfortify'
## The following object is masked from 'package:forecast':
## 
##     gglagplot
Call_Volumes_vs_Nos_Accounts <- read_csv("~/DAPT/Q3/Forecasting Methods/Call Volumes vs Nos Accounts.csv")
## Parsed with column specification:
## cols(
##   .default = col_integer(),
##   Date = col_character()
## )
## See spec(...) for full column specifications.
View(Call_Volumes_vs_Nos_Accounts)
Calls <- as.data.frame(Call_Volumes_vs_Nos_Accounts)

Index and format data into time series objects.

as.Date(as.character(Calls$DATE),format="%Y%m%d")
## [1] "Date of length 0"
z <- read.zoo(Calls, index = 20, format = "%m/%d/%Y")
x <- xts(z$CallVolProd3)
x2 <- xts(z$CallVolProd4)
View(z)
View(x)
View(x2)

Visualize data to understand what is going on.

library(ggfortify)
autoplot(x)

OBSERVATIONS:

  1. Something causes a systemic shift October 2010.
  2. By March 2011 system appears to be back at equilibrium.
  3. Variability appears constant and similar to original variability after systemic shift occurred.
  4. No Seasonality. No Multiplication. Additive step…positive.

Explore different forecasting parameters.

ses(as.numeric(x), alpha=0.2, initial="simple", h=3)
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 74       95445.72 86067.82 104823.6 81103.45 109788.0
## 75       95445.72 85882.10 105009.3 80819.42 110072.0
## 76       95445.72 85699.92 105191.5 80540.80 110350.6
fit1 <- ses(as.numeric(x), alpha=0.2, initial="simple", h=3)
fit2 <- ses(as.numeric(x), alpha=0.6, initial="simple", h=3)
fit3 <- ses(as.numeric(x), h=3)
plot(fit1,ylab="Product 3 Call Volume",
  xlab="Months", main="", fcol="white", type="o")
lines(fitted(fit1), col="blue", type="o")
lines(fitted(fit2), col="red", type="o")
lines(fitted(fit3), col="green", type="o")
lines(fit1$mean, col="blue", type="o")
lines(fit2$mean, col="red", type="o")
lines(fit3$mean, col="green", type="o")
legend("topleft",lty=1, col=c(1,"blue","red","green"), 
  c("data", expression(alpha == 0.2), expression(alpha == 0.6),
  expression(alpha == 0.89)),pch=1)

Choose best forecasting model.

fit1 <- ets(as.numeric(x), model = "ZAZ")
summary(fit1)
## ETS(M,A,N) 
## 
## Call:
##  ets(y = as.numeric(x), model = "ZAZ") 
## 
##   Smoothing parameters:
##     alpha = 0.5157 
##     beta  = 1e-04 
## 
##   Initial states:
##     l = 62944.3219 
##     b = 662.5864 
## 
##   sigma:  0.0842
## 
##      AIC     AICc      BIC 
## 1598.070 1598.965 1609.522 
## 
## Training set error measures:
##                     ME     RMSE     MAE       MPE     MAPE      MASE
## Training set -403.6885 6327.196 4645.47 -1.197042 6.410172 0.9792651
##                    ACF1
## Training set 0.08825936
options(repr.plot.width=12, repr.plot.height=7)
plot(fit1)
lines(fitted(fit1), col="red", lty=2)

plot(forecast(fit1,h=5),
  ylab="Forecasted Call Volumme: Product 3",
  xlab="Months", main="", fcol="blue", type="o")

library(ggfortify)
autoplot(x2)

OBSERVATIONS:

  1. Big spike in March 2010.
  2. After spike in March 2010 gradual decrease until January 2011.
  3. After January 2011 system appears to be at equilibrium.
  4. No Seasonality. No Multiplication. Additive step but negative.

Explore different forecasting parameters.

ses(as.numeric(x2), alpha=0.2, initial="simple", h=3)
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 74       16743.06 9724.470 23761.65 6009.052 27477.07
## 75       16743.06 9585.474 23900.65 5796.477 27689.64
## 76       16743.06 9449.127 24036.99 5587.952 27898.17
fit1 <- ses(as.numeric(x2), alpha=0.2, initial="simple", h=3)
fit2 <- ses(as.numeric(x2), alpha=0.6, initial="simple", h=3)
fit3 <- ses(as.numeric(x2), h=3)
plot(fit1,ylab="Product 4 Call Volume",
  xlab="Months", main="", fcol="white", type="o")
lines(fitted(fit1), col="blue", type="o")
lines(fitted(fit2), col="red", type="o")
lines(fitted(fit3), col="green", type="o")
lines(fit1$mean, col="blue", type="o")
lines(fit2$mean, col="red", type="o")
lines(fit3$mean, col="green", type="o")
legend("topleft",lty=1, col=c(1,"blue","red","green"), 
  c("data", expression(alpha == 0.2), expression(alpha == 0.6),
  expression(alpha == 0.89)),pch=1)

Choose best forecasting model.

fit2 <- ets(as.numeric(x2), model = "ZAZ")
summary(fit2)
## ETS(M,A,N) 
## 
## Call:
##  ets(y = as.numeric(x2), model = "ZAZ") 
## 
##   Smoothing parameters:
##     alpha = 0.699 
##     beta  = 1e-04 
## 
##   Initial states:
##     l = 44506.8433 
##     b = -51.872 
## 
##   sigma:  0.1348
## 
##      AIC     AICc      BIC 
## 1511.907 1512.802 1523.359 
## 
## Training set error measures:
##                     ME     RMSE      MAE       MPE     MAPE     MASE
## Training set -456.9208 4403.507 3027.768 -2.862957 10.99699 1.004526
##                   ACF1
## Training set 0.1718114
options(repr.plot.width=7, repr.plot.height=5)
plot(fit2)
lines(fitted(fit2), col="red", lty=2)

plot(forecast(fit2,h=8),
  ylab="Forecasted Call Volumme: Product 4",
  xlab="Months", main="", fcol="blue", type="o")