## Reading in Daily Demand Forecasting Order Data Set
## Source: https://archive.ics.uci.edu/ml/datasets/Daily+Demand+Forecasting+Orders
## Abstract: The dataset was collected during 60 days, this is a real database of a brazilian logistics company.
## Added column called DayTotal to capture total number of days [=(Week-1)*7+Day]
library(readr)
bank <- read_csv("C:/Users/bryce_anderson/Desktop/Boston College/Predictive Analytics and Forecasting/Week 2 (PA&F)/Daily_Demand_Forecasting_OrdersFinal.csv")
## R Packages Utilized
library(ggplot2)
library(forecast)
## Creating a time series of the data set
bankTS <- ts(bank)
## Plotting the Targer Orders demand data
library(ggplot2)
attach(bank)
plot(Target~DayTotal, data=bank, xlab="Total Number of Days", ylab="Target (Total Orders)", main="Target (Total Orders) over Number of Days", col="DodgerBlue")
abline(lm(Target~DayTotal), col="orange")
## Plotting the Traffic Controller Orders demand data
plot(TrafficControllerOrders~DayTotal, data=bank, xlab="Total Number of Days", ylab="Traffic Controller Orders", main="Traffic Controller Orders over Number of Days", col="DodgerBlue")
abline(lm(TrafficControllerOrders~DayTotal), col="orange")
## Plotting the Urgent Orders demand data
plot(UrgentOrder~DayTotal, data=bank, xlab="Total Number of Days", ylab="Urgent Orders", main="Urgent Orders over Number of Days", col="DodgerBlue")
abline(lm(UrgentOrder~DayTotal), col="orange")
## Creating a time series of the data
bankTS <- ts(bank)
## Base ETS forecast for 10 values of Target Orders
bankFTarget <- (bankTS[,"Target"])
targetF <- bankFTarget %>% forecast(h=10) %>%
autoplot() + ylab("Daily Target Order demamd")
targetF
## ETS Model Creation
## Rather than producing a forecast, the ets() function estimates the model parameters and returns information about the model
## Here we will use AIC, AICc, and BIC as the criteria in selecting the most appropriate model
## Model 1
bankFTarget <- (bankTS[,"Target"])
## Autoselection is used in the model argument using "Z" values
model1 <- ets(bankFTarget, model="ZZZ", damped=NULL, alpha=NULL, beta=NULL,
gamma=NULL, phi=NULL, lambda=NULL, biasadj=FALSE,
additive.only=FALSE, restrict=TRUE,
allow.multiplicative.trend=FALSE)
model1
## ETS(A,N,N)
##
## Call:
## ets(y = bankFTarget, model = "ZZZ", damped = NULL, alpha = NULL,
##
## Call:
## beta = NULL, gamma = NULL, phi = NULL, additive.only = FALSE,
##
## Call:
## lambda = NULL, biasadj = FALSE, restrict = TRUE, allow.multiplicative.trend = FALSE)
##
## Smoothing parameters:
## alpha = 1e-04
##
## Initial states:
## l = 300.8709
##
## sigma: 90.3757
##
## AIC AICc BIC
## 790.1036 790.5322 796.3866
autoplot(model1)
## Producing residual plots
cbind('Residuals' = residuals(model1),
'Forecast errors' = residuals(model1,type='response')) %>%
autoplot(facet=TRUE) + xlab("Year") + ylab("")
## Model 2
TCFTarget <- (bankTS[,"TrafficControllerOrders"])
model2 <- ets(TCFTarget, model="ZZZ", damped=NULL, alpha=NULL, beta=NULL,
gamma=NULL, phi=NULL, lambda=NULL, biasadj=FALSE,
additive.only=FALSE, restrict=TRUE,
allow.multiplicative.trend=FALSE)
model2
## ETS(M,N,N)
##
## Call:
## ets(y = TCFTarget, model = "ZZZ", damped = NULL, alpha = NULL,
##
## Call:
## beta = NULL, gamma = NULL, phi = NULL, additive.only = FALSE,
##
## Call:
## lambda = NULL, biasadj = FALSE, restrict = TRUE, allow.multiplicative.trend = FALSE)
##
## Smoothing parameters:
## alpha = 0.1291
##
## Initial states:
## l = 51655.6005
##
## sigma: 0.2519
##
## AIC AICc BIC
## 1373.179 1373.607 1379.462
autoplot(model2)
## Producing residual plots
cbind('Residuals' = residuals(model2),
'Forecast errors' = residuals(model2,type='response')) %>%
autoplot(facet=TRUE) + xlab("Year") + ylab("")
## Model 3
UFTarget <- (bankTS[,"UrgentOrder"])
model3 <- ets(UFTarget, model="ZZZ", damped=NULL, alpha=NULL, beta=NULL,
gamma=NULL, phi=NULL, lambda=NULL, biasadj=FALSE,
additive.only=FALSE, restrict=TRUE,
allow.multiplicative.trend=FALSE)
model3
## ETS(A,N,N)
##
## Call:
## ets(y = UFTarget, model = "ZZZ", damped = NULL, alpha = NULL,
##
## Call:
## beta = NULL, gamma = NULL, phi = NULL, additive.only = FALSE,
##
## Call:
## lambda = NULL, biasadj = FALSE, restrict = TRUE, allow.multiplicative.trend = FALSE)
##
## Smoothing parameters:
## alpha = 1e-04
##
## Initial states:
## l = 118.8052
##
## sigma: 27.4058
##
## AIC AICc BIC
## 646.9171 647.3456 653.2001
autoplot(model3)
## Producing residual plots
cbind('Residuals' = residuals(model3),
'Forecast errors' = residuals(model3,type='response')) %>%
autoplot(facet=TRUE) + xlab("Year") + ylab("")
In evaluating the ETS models produced, the AIC, AICc, and BIC is used as the criteria for selecting the most appropriate model. In this case, Model 3 which forecasts the Urgent Orders variable is shown as the most effective based on having the lowest values in these three criteria. It produces an AIC value of 646, an AICc value of 647, and a BIC value of 653. Model 2, which forecasts Traffic Controller orders, shows significantly worse results than the over two models with AIC, AICc, and BIC values of 1373, 1373, 1379 respectively. While Model 3 shows lower values than Model 1, the difference is not as significant as Model 2. In this case, we choose Model 3 as the best but could run additional tests in future research to identify other comparitive factors between Models 1 and 3.