TITLE PAGE

TITLE: ADM 4307 - FORECASTING PROJECT

AUTHOR: GABRIEL TORRES STELLUTO

DATE: DECEMBER 13TH, 2023

EXECUTIVE SUMMARY

OBJECTIVE: The purpose of this forecasting project in R is to analyze a data set of the total energy consumption in the United States from 1973 to 2023. The data set was divided into 2 xlxs. files that contained the total energy consumption of different sectors. Since the goal of this project was to apply what was taught during lectures to a forecasting project, our group decided to focus on creating one time series data set with the objective of analyze the total energy consumed by the residential sector in that period. In this project, we have applied different forecasting techniques with the goal of identifying insights into the residential sector consumption patters and trends. Additionally, we have analyzed four different forecasting models to determine which model provides the most accurate predictions.

This data set was chosen because it gives us a clear insight on the patterns and trend of the residential energy consumption in the United States over the years. This is an important data when it comes to strategic planning and decision making for future infrastructure projects.

SCOPE: Total Energy Consumption by the Residential Sector in the United States from 1973 to 2023

METHODOLOGY: The models used in this forecasting project were: Seasonal Naive model; Exponential Smoothing model; Arima model; Holt Winters.

LOAD LIBRARIES

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.3     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(readxl)
library(dplyr)
library(ggplot2)
library(stringr)
library(tsibble)
## 
## Attaching package: 'tsibble'
## 
## The following object is masked from 'package:lubridate':
## 
##     interval
## 
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, union
library(forecast)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
library(tseries)
library(reshape2)
## 
## Attaching package: 'reshape2'
## 
## The following object is masked from 'package:tidyr':
## 
##     smiths
library(zoo)
## 
## Attaching package: 'zoo'
## 
## The following object is masked from 'package:tsibble':
## 
##     index
## 
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(fpp3)
## ── Attaching packages ────────────────────────────────────────────── fpp3 0.5 ──
## ✔ tsibbledata 0.4.1     ✔ fable       0.3.3
## ✔ feasts      0.3.1     ✔ fabletools  0.3.4
## ── Conflicts ───────────────────────────────────────────────── fpp3_conflicts ──
## ✖ lubridate::date()    masks base::date()
## ✖ dplyr::filter()      masks stats::filter()
## ✖ zoo::index()         masks tsibble::index()
## ✖ tsibble::intersect() masks base::intersect()
## ✖ tsibble::interval()  masks lubridate::interval()
## ✖ dplyr::lag()         masks stats::lag()
## ✖ tsibble::setdiff()   masks base::setdiff()
## ✖ tsibble::union()     masks base::union()
library(xts)
## 
## ######################### Warning from 'xts' package ##########################
## #                                                                             #
## # The dplyr lag() function breaks how base R's lag() function is supposed to  #
## # work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or       #
## # source() into this session won't work correctly.                            #
## #                                                                             #
## # Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
## # conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop           #
## # dplyr from breaking base R's lag() function.                                #
## #                                                                             #
## # Code in packages is not affected. It's protected by R's namespace mechanism #
## # Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning.  #
## #                                                                             #
## ###############################################################################
## 
## Attaching package: 'xts'
## 
## The following objects are masked from 'package:dplyr':
## 
##     first, last

DATA SET INTRODUCTION

Data_1 <- read_xlsx("/Users/gabriel/Downloads/Table_2.1a__Energy_Consumption__Residential_-_Commercial_-_and_Industrial_Sectors.xlsx")
Data_2 <- read_xlsx("/Users/gabriel/Downloads/Table_2.1b__Energy_Consumption__Transportation_Sector_-_Total_End-Use_Sectors_-_and_Electric_Power_Sector.xlsx")

The data set used in this forecasting method can be found on: https://www.eia.gov/totalenergy/data/annual/

This data contains the total energy consumption in the United States per sector from 1973 to 2023. It was downloaded as an xlxs. file and it was modified on excel, before being imputed into R Studio.

The data set named “Data_1” contains 608 observations with 16 variables. The data set named “Data_2” contains 608 observations with 13 variables.

The only data set used was “Data_1”, but both data sets were imputed to R Studio to avoid any missing information.

PRE-PROCESSING

PRE-PROCESSING: CLEANING

Some pre-processing was done on the xlxs. file because the dates on the “Month” variable would not correctly load on R studio, so I fixed it on excel by formatting the type of value to custom date.

Additionally, I decided to delete a few rows that were not useful and changed the column headers. This was done in excel. However, here is how it can be done it R studio:

  1. Remove rows that are not important:

Data_1 <- Data_1[-c(1:9), ]

Data_1 <- Data_1[-c(2), ]

  1. Rename the columns to be the equal to values in row 1

colnames(Data_1) <- Data_1[1, ]

  1. Remove first row values. This is because they became column headers

Data_1 <- Data_1[-c(1), ]

PRE-PROCESSING: TRANSFORMING DATA INTO TIME SERIES

This step involves creating a time series for each sector. However, the only sector analyzed was the residential sector.

# Create the time series for each sector
# Residential Sector
Total_Res_ts <- ts(Data_1$`Total Energy Consumed by the Residential Sector`, start = c(1973, 1),
                   end = c(2022, 12),
                   frequency = 12)

# Commercial Sector
Total_Com_ts <- ts(Data_1$`Total Energy Consumed by the Commercial Sector`, start = c(1973, 1),
                   end = c(2022, 12),
                   frequency = 12)

# Industrial Sector
Total_Ind_ts <- ts(Data_1$`Total Energy Consumed by the Industrial Sector`, start = c(1973, 1),
                   end = c(2022, 12),
                   frequency = 12)

# Transportation Sector
Total_Transp_ts <- ts(Data_2$`Total Energy Consumed by the Transportation Sector`, start = c(1973, 1),
                   end = c(2022, 12),
                   frequency = 12)

# End-Use-Sectors Sector
Total_EUS_ts <- ts(Data_2$`Total Energy Consumed by the End-Use-Sectors`, start = c(1973, 1),
                      end = c(2022, 12),
                      frequency = 12)

ANALYSIS PART

First, we created a time plot graph to analyze the time series.

autoplot(Total_Res_ts) +
  ggtitle("Time Plot - Total Energy Consumed by the Residential Sector per Month") +
  xlab("Time") +
  ylab("Trillions of QTU")

Differentiate data

Since it was clear that the data has showed both trend and seanonal patters, we decided to differentiate the data.

# Since we can see a slight uptrend, we should differetiate the data and plot it again
Diff_Res <- diff(Total_Res_ts)

autoplot(Diff_Res) +
  ggtitle("Diff Time Plot - Total Energy Consumed by the Residential Sector per Month") +
  xlab("Time") +
  ylab("Trillions of QTU")

# Now, let's focus on the seasonality
ggseasonplot(Diff_Res) +
  ggtitle("Diff Seasonal Plot - Montlhy Change in Monthly Energy Consumption by the Residential Sector") +
  xlab("Time") +
  ylab("Trillions of QTU")

# To undertand the average changes per month
ggsubseriesplot(Diff_Res) +
  xlab("Month") +
  ylab("Trillions of QTU")

# The analysis of the ggseasonplot and the ggsubseriesplot confirms that we do have seasonality and that during the month of February there is a big drop in energy consumption, which also happens in December. Moreover, from the months of May to June and October to December there is a significant increase in total energy consumption.

FORECASTING PART - RESIDENTIAL SECTOR

Residential Sector - 1st Method: Seasonal Naive (SNAIVE)
#This is the simplest method for this data series because the dataset is seasonal. We use the differentiate dataset because it has no trend.
Snaive_Res <- snaive(Diff_Res, h = 60)
Snaive_forecast <- forecast(Snaive_Res, h =60)
autoplot(Snaive_forecast, include = 120)

print(summary(Snaive_Res))
## 
## Forecast method: Seasonal naive method
## 
## Model Information:
## Call: snaive(y = Diff_Res, h = 60) 
## 
## Residual sd: 130.3775 
## 
## Error measures:
##                     ME     RMSE      MAE       MPE    MAPE MASE       ACF1
## Training set 0.7687802 130.3775 93.10696 -12.16012 161.285    1 -0.2624987
## 
## Forecasts:
##          Point Forecast      Lo 80       Hi 80       Lo 95       Hi 95
## Jan 2023        567.572  400.48649  734.657507  312.036769  823.107231
## Feb 2023       -381.101 -548.18651 -214.015493 -636.636231 -125.565769
## Mar 2023       -376.281 -543.36651 -209.195493 -631.816231 -120.745769
## Apr 2023       -365.893 -532.97851 -198.807493 -621.428231 -110.357769
## May 2023        -49.515 -216.60051  117.570507 -305.050231  206.020231
## Jun 2023        147.564  -19.52151  314.649507 -107.971231  403.099231
## Jul 2023        248.784   81.69849  415.869507   -6.751231  504.319231
## Aug 2023        -79.084 -246.16951   88.001507 -334.619231  176.451231
## Sep 2023       -290.683 -457.76851 -123.597493 -546.218231  -35.147769
## Oct 2023        -80.226 -247.31151   86.859507 -335.761231  175.309231
## Nov 2023        354.404  187.31849  521.489507   98.868769  609.939231
## Dec 2023        636.533  469.44749  803.618507  380.997769  892.068231
## Jan 2024        567.572  331.27741  803.866589  206.190611  928.953389
## Feb 2024       -381.101 -617.39559 -144.806411 -742.482389  -19.719611
## Mar 2024       -376.281 -612.57559 -139.986411 -737.662389  -14.899611
## Apr 2024       -365.893 -602.18759 -129.598411 -727.274389   -4.511611
## May 2024        -49.515 -285.80959  186.779589 -410.896389  311.866389
## Jun 2024        147.564  -88.73059  383.858589 -213.817389  508.945389
## Jul 2024        248.784   12.48941  485.078589 -112.597389  610.165389
## Aug 2024        -79.084 -315.37859  157.210589 -440.465389  282.297389
## Sep 2024       -290.683 -526.97759  -54.388411 -652.064389   70.698389
## Oct 2024        -80.226 -316.52059  156.068589 -441.607389  281.155389
## Nov 2024        354.404  118.10941  590.698589   -6.977389  715.785389
## Dec 2024        636.533  400.23841  872.827589  275.151611  997.914389
## Jan 2025        567.572  278.17141  856.972587  124.971997 1010.172003
## Feb 2025       -381.101 -670.50159  -91.700413 -823.701003   61.499003
## Mar 2025       -376.281 -665.68159  -86.880413 -818.881003   66.319003
## Apr 2025       -365.893 -655.29359  -76.492413 -808.493003   76.707003
## May 2025        -49.515 -338.91559  239.885587 -492.115003  393.085003
## Jun 2025        147.564 -141.83659  436.964587 -295.036003  590.164003
## Jul 2025        248.784  -40.61659  538.184587 -193.816003  691.384003
## Aug 2025        -79.084 -368.48459  210.316587 -521.684003  363.516003
## Sep 2025       -290.683 -580.08359   -1.282413 -733.283003  151.917003
## Oct 2025        -80.226 -369.62659  209.174587 -522.826003  362.374003
## Nov 2025        354.404   65.00341  643.804587  -88.196003  797.004003
## Dec 2025        636.533  347.13241  925.933587  193.932997 1079.133003
## Jan 2026        567.572  233.40099  901.743013   56.501538 1078.642462
## Feb 2026       -381.101 -715.27201  -46.929987 -892.171462  129.969462
## Mar 2026       -376.281 -710.45201  -42.109987 -887.351462  134.789462
## Apr 2026       -365.893 -700.06401  -31.721987 -876.963462  145.177462
## May 2026        -49.515 -383.68601  284.656013 -560.585462  461.555462
## Jun 2026        147.564 -186.60701  481.735013 -363.506462  658.634462
## Jul 2026        248.784  -85.38701  582.955013 -262.286462  759.854462
## Aug 2026        -79.084 -413.25501  255.087013 -590.154462  431.986462
## Sep 2026       -290.683 -624.85401   43.488013 -801.753462  220.387462
## Oct 2026        -80.226 -414.39701  253.945013 -591.296462  430.844462
## Nov 2026        354.404   20.23299  688.575013 -156.666462  865.474462
## Dec 2026        636.533  302.36199  970.704013  125.462538 1147.603462
## Jan 2027        567.572  193.95745  941.186551   -3.822147 1138.966147
## Feb 2027       -381.101 -754.71555   -7.486449 -952.495147  190.293147
## Mar 2027       -376.281 -749.89555   -2.666449 -947.675147  195.113147
## Apr 2027       -365.893 -739.50755    7.721551 -937.287147  205.501147
## May 2027        -49.515 -423.12955  324.099551 -620.909147  521.879147
## Jun 2027        147.564 -226.05055  521.178551 -423.830147  718.958147
## Jul 2027        248.784 -124.83055  622.398551 -322.610147  820.178147
## Aug 2027        -79.084 -452.69855  294.530551 -650.478147  492.310147
## Sep 2027       -290.683 -664.29755   82.931551 -862.077147  280.711147
## Oct 2027        -80.226 -453.84055  293.388551 -651.620147  491.168147
## Nov 2027        354.404  -19.21055  728.018551 -216.990147  925.798147
## Dec 2027        636.533  262.91845 1010.147551   65.138853 1207.927147
checkresiduals(Snaive_Res)

## 
##  Ljung-Box test
## 
## data:  Residuals from Seasonal naive method
## Q* = 211.91, df = 24, p-value < 2.2e-16
## 
## Model df: 0.   Total lags used: 24
accuracy(Snaive_forecast)
##                     ME     RMSE      MAE       MPE    MAPE MASE       ACF1
## Training set 0.7687802 130.3775 93.10696 -12.16012 161.285    1 -0.2624987
# SD RESIDUAL = 130.3775

# As we can see from both the forecasted plot and ACF plot, this is not the best forecasting method.

Residential Sector - 2nd Method: EST method (EST)

# I decided to use the original time series dataset because the data has seasonality and this forecasting technique can be used with datasets that have seasonality.
# The fuction below will allow us to find the best ETS model
ETS_res <- ets(Total_Res_ts)
ETS_forecast <- forecast(ETS_res, h = 60)
autoplot(ETS_forecast, include = 120)

print(summary(ETS_res))
## ETS(M,A,M) 
## 
## Call:
##  ets(y = Total_Res_ts) 
## 
##   Smoothing parameters:
##     alpha = 0.2871 
##     beta  = 7e-04 
##     gamma = 0.2405 
## 
##   Initial states:
##     l = 1218.2982 
##     b = 3.9197 
##     s = 1.3065 0.9439 0.7739 0.7286 0.7858 0.7858
##            0.7355 0.8029 0.9714 1.2036 1.3835 1.5786
## 
##   sigma:  0.0566
## 
##      AIC     AICc      BIC 
## 9137.424 9138.475 9212.172 
## 
## Training set error measures:
##                     ME     RMSE      MAE        MPE     MAPE      MASE
## Training set -7.635111 94.10162 68.65798 -0.6676478 4.429665 0.7897967
##                   ACF1
## Training set 0.2269772
checkresiduals(ETS_res)

## 
##  Ljung-Box test
## 
## data:  Residuals from ETS(M,A,M)
## Q* = 131.1, df = 24, p-value < 2.2e-16
## 
## Model df: 0.   Total lags used: 24
accuracy(ETS_forecast)
##                     ME     RMSE      MAE        MPE     MAPE      MASE
## Training set -7.635111 94.10162 68.65798 -0.6676478 4.429665 0.7897967
##                   ACF1
## Training set 0.2269772
# SD RESIDUAL = 0.0566


# As we can see from both the forecasted plot and ACF plot, this is not the best forecasting method.

Residential Sector - 3rd Method: Arima method (ARIMA)

# This method needs the data to be stationary
Arima_res <- auto.arima(Diff_Res, stepwise = FALSE, approximation = FALSE, trace = TRUE)
## 
##  ARIMA(0,0,0)(0,1,0)[12]                    : 7385.73
##  ARIMA(0,0,0)(0,1,0)[12] with drift         : 7387.724
##  ARIMA(0,0,0)(0,1,1)[12]                    : 7121.013
##  ARIMA(0,0,0)(0,1,1)[12] with drift         : 7123.032
##  ARIMA(0,0,0)(0,1,2)[12]                    : 7119.619
##  ARIMA(0,0,0)(0,1,2)[12] with drift         : 7121.644
##  ARIMA(0,0,0)(1,1,0)[12]                    : 7292.075
##  ARIMA(0,0,0)(1,1,0)[12] with drift         : 7294.08
##  ARIMA(0,0,0)(1,1,1)[12]                    : 7120.667
##  ARIMA(0,0,0)(1,1,1)[12] with drift         : 7122.692
##  ARIMA(0,0,0)(1,1,2)[12]                    : 7116.778
##  ARIMA(0,0,0)(1,1,2)[12] with drift         : 7118.81
##  ARIMA(0,0,0)(2,1,0)[12]                    : 7204.613
##  ARIMA(0,0,0)(2,1,0)[12] with drift         : 7206.63
##  ARIMA(0,0,0)(2,1,1)[12]                    : 7110.03
##  ARIMA(0,0,0)(2,1,1)[12] with drift         : 7112.063
##  ARIMA(0,0,0)(2,1,2)[12]                    : 7110.988
##  ARIMA(0,0,0)(2,1,2)[12] with drift         : 7113.031
##  ARIMA(0,0,1)(0,1,0)[12]                    : 7294.627
##  ARIMA(0,0,1)(0,1,0)[12] with drift         : 7296.607
##  ARIMA(0,0,1)(0,1,1)[12]                    : 7044.348
##  ARIMA(0,0,1)(0,1,1)[12] with drift         : 7046.375
##  ARIMA(0,0,1)(0,1,2)[12]                    : 7041.783
##  ARIMA(0,0,1)(0,1,2)[12] with drift         : 7043.817
##  ARIMA(0,0,1)(1,1,0)[12]                    : 7213.048
##  ARIMA(0,0,1)(1,1,0)[12] with drift         : 7215.044
##  ARIMA(0,0,1)(1,1,1)[12]                    : 7043.515
##  ARIMA(0,0,1)(1,1,1)[12] with drift         : 7045.549
##  ARIMA(0,0,1)(1,1,2)[12]                    : 7039.006
##  ARIMA(0,0,1)(1,1,2)[12] with drift         : 7041.047
##  ARIMA(0,0,1)(2,1,0)[12]                    : 7127.533
##  ARIMA(0,0,1)(2,1,0)[12] with drift         : 7129.55
##  ARIMA(0,0,1)(2,1,1)[12]                    : 7024.811
##  ARIMA(0,0,1)(2,1,1)[12] with drift         : 7026.852
##  ARIMA(0,0,1)(2,1,2)[12]                    : 7017.82
##  ARIMA(0,0,1)(2,1,2)[12] with drift         : 7019.868
##  ARIMA(0,0,2)(0,1,0)[12]                    : Inf
##  ARIMA(0,0,2)(0,1,0)[12] with drift         : Inf
##  ARIMA(0,0,2)(0,1,1)[12]                    : 6964.499
##  ARIMA(0,0,2)(0,1,1)[12] with drift         : 6966.305
##  ARIMA(0,0,2)(0,1,2)[12]                    : 6963.555
##  ARIMA(0,0,2)(0,1,2)[12] with drift         : 6965.333
##  ARIMA(0,0,2)(1,1,0)[12]                    : Inf
##  ARIMA(0,0,2)(1,1,0)[12] with drift         : Inf
##  ARIMA(0,0,2)(1,1,1)[12]                    : 6964.585
##  ARIMA(0,0,2)(1,1,1)[12] with drift         : 6966.375
##  ARIMA(0,0,2)(1,1,2)[12]                    : 6961.124
##  ARIMA(0,0,2)(1,1,2)[12] with drift         : 6962.915
##  ARIMA(0,0,2)(2,1,0)[12]                    : 7050.15
##  ARIMA(0,0,2)(2,1,0)[12] with drift         : 7052.025
##  ARIMA(0,0,2)(2,1,1)[12]                    : 6950.119
##  ARIMA(0,0,2)(2,1,1)[12] with drift         : 6951.963
##  ARIMA(0,0,3)(0,1,0)[12]                    : Inf
##  ARIMA(0,0,3)(0,1,0)[12] with drift         : Inf
##  ARIMA(0,0,3)(0,1,1)[12]                    : 6959.477
##  ARIMA(0,0,3)(0,1,1)[12] with drift         : 6961.19
##  ARIMA(0,0,3)(0,1,2)[12]                    : 6958.511
##  ARIMA(0,0,3)(0,1,2)[12] with drift         : 6960.184
##  ARIMA(0,0,3)(1,1,0)[12]                    : Inf
##  ARIMA(0,0,3)(1,1,0)[12] with drift         : Inf
##  ARIMA(0,0,3)(1,1,1)[12]                    : 6959.529
##  ARIMA(0,0,3)(1,1,1)[12] with drift         : 6961.216
##  ARIMA(0,0,3)(2,1,0)[12]                    : 7043.553
##  ARIMA(0,0,3)(2,1,0)[12] with drift         : 7045.319
##  ARIMA(0,0,4)(0,1,0)[12]                    : Inf
##  ARIMA(0,0,4)(0,1,0)[12] with drift         : Inf
##  ARIMA(0,0,4)(0,1,1)[12]                    : 6959.71
##  ARIMA(0,0,4)(0,1,1)[12] with drift         : 6961.401
##  ARIMA(0,0,4)(1,1,0)[12]                    : Inf
##  ARIMA(0,0,4)(1,1,0)[12] with drift         : Inf
##  ARIMA(0,0,5)(0,1,0)[12]                    : Inf
##  ARIMA(0,0,5)(0,1,0)[12] with drift         : Inf
##  ARIMA(1,0,0)(0,1,0)[12]                    : 7345.575
##  ARIMA(1,0,0)(0,1,0)[12] with drift         : 7347.568
##  ARIMA(1,0,0)(0,1,1)[12]                    : 7089.256
##  ARIMA(1,0,0)(0,1,1)[12] with drift         : 7091.282
##  ARIMA(1,0,0)(0,1,2)[12]                    : 7087.584
##  ARIMA(1,0,0)(0,1,2)[12] with drift         : 7089.615
##  ARIMA(1,0,0)(1,1,0)[12]                    : 7255.937
##  ARIMA(1,0,0)(1,1,0)[12] with drift         : 7257.942
##  ARIMA(1,0,0)(1,1,1)[12]                    : 7088.797
##  ARIMA(1,0,0)(1,1,1)[12] with drift         : 7090.829
##  ARIMA(1,0,0)(1,1,2)[12]                    : 7084.869
##  ARIMA(1,0,0)(1,1,2)[12] with drift         : 7086.907
##  ARIMA(1,0,0)(2,1,0)[12]                    : 7171.453
##  ARIMA(1,0,0)(2,1,0)[12] with drift         : 7173.473
##  ARIMA(1,0,0)(2,1,1)[12]                    : 7076.072
##  ARIMA(1,0,0)(2,1,1)[12] with drift         : 7078.112
##  ARIMA(1,0,0)(2,1,2)[12]                    : 7073.318
##  ARIMA(1,0,0)(2,1,2)[12] with drift         : 7075.366
##  ARIMA(1,0,1)(0,1,0)[12]                    : Inf
##  ARIMA(1,0,1)(0,1,0)[12] with drift         : Inf
##  ARIMA(1,0,1)(0,1,1)[12]                    : 6958.274
##  ARIMA(1,0,1)(0,1,1)[12] with drift         : 6959.93
##  ARIMA(1,0,1)(0,1,2)[12]                    : 6956.858
##  ARIMA(1,0,1)(0,1,2)[12] with drift         : 6958.468
##  ARIMA(1,0,1)(1,1,0)[12]                    : Inf
##  ARIMA(1,0,1)(1,1,0)[12] with drift         : Inf
##  ARIMA(1,0,1)(1,1,1)[12]                    : 6958.013
##  ARIMA(1,0,1)(1,1,1)[12] with drift         : 6959.636
##  ARIMA(1,0,1)(1,1,2)[12]                    : 6954.397
##  ARIMA(1,0,1)(1,1,2)[12] with drift         : 6956.029
##  ARIMA(1,0,1)(2,1,0)[12]                    : 7037.779
##  ARIMA(1,0,1)(2,1,0)[12] with drift         : Inf
##  ARIMA(1,0,1)(2,1,1)[12]                    : 6944.647
##  ARIMA(1,0,1)(2,1,1)[12] with drift         : 6946.378
##  ARIMA(1,0,2)(0,1,0)[12]                    : Inf
##  ARIMA(1,0,2)(0,1,0)[12] with drift         : Inf
##  ARIMA(1,0,2)(0,1,1)[12]                    : 6958.058
##  ARIMA(1,0,2)(0,1,1)[12] with drift         : 6959.739
##  ARIMA(1,0,2)(0,1,2)[12]                    : 6956.806
##  ARIMA(1,0,2)(0,1,2)[12] with drift         : 6958.44
##  ARIMA(1,0,2)(1,1,0)[12]                    : Inf
##  ARIMA(1,0,2)(1,1,0)[12] with drift         : Inf
##  ARIMA(1,0,2)(1,1,1)[12]                    : 6957.905
##  ARIMA(1,0,2)(1,1,1)[12] with drift         : 6959.553
##  ARIMA(1,0,2)(2,1,0)[12]                    : 7038.93
##  ARIMA(1,0,2)(2,1,0)[12] with drift         : Inf
##  ARIMA(1,0,3)(0,1,0)[12]                    : Inf
##  ARIMA(1,0,3)(0,1,0)[12] with drift         : Inf
##  ARIMA(1,0,3)(0,1,1)[12]                    : 6960.077
##  ARIMA(1,0,3)(0,1,1)[12] with drift         : 6961.764
##  ARIMA(1,0,3)(1,1,0)[12]                    : Inf
##  ARIMA(1,0,3)(1,1,0)[12] with drift         : Inf
##  ARIMA(1,0,4)(0,1,0)[12]                    : Inf
##  ARIMA(1,0,4)(0,1,0)[12] with drift         : Inf
##  ARIMA(2,0,0)(0,1,0)[12]                    : 7301.613
##  ARIMA(2,0,0)(0,1,0)[12] with drift         : 7303.607
##  ARIMA(2,0,0)(0,1,1)[12]                    : 7054.287
##  ARIMA(2,0,0)(0,1,1)[12] with drift         : 7056.321
##  ARIMA(2,0,0)(0,1,2)[12]                    : 7051.506
##  ARIMA(2,0,0)(0,1,2)[12] with drift         : 7053.545
##  ARIMA(2,0,0)(1,1,0)[12]                    : 7217.445
##  ARIMA(2,0,0)(1,1,0)[12] with drift         : 7219.453
##  ARIMA(2,0,0)(1,1,1)[12]                    : 7053.148
##  ARIMA(2,0,0)(1,1,1)[12] with drift         : 7055.187
##  ARIMA(2,0,0)(1,1,2)[12]                    : 7048.786
##  ARIMA(2,0,0)(1,1,2)[12] with drift         : 7050.832
##  ARIMA(2,0,0)(2,1,0)[12]                    : 7130.853
##  ARIMA(2,0,0)(2,1,0)[12] with drift         : 7132.879
##  ARIMA(2,0,0)(2,1,1)[12]                    : 7038.864
##  ARIMA(2,0,0)(2,1,1)[12] with drift         : 7040.912
##  ARIMA(2,0,1)(0,1,0)[12]                    : Inf
##  ARIMA(2,0,1)(0,1,0)[12] with drift         : Inf
##  ARIMA(2,0,1)(0,1,1)[12]                    : 6958.133
##  ARIMA(2,0,1)(0,1,1)[12] with drift         : 6959.816
##  ARIMA(2,0,1)(0,1,2)[12]                    : 6956.947
##  ARIMA(2,0,1)(0,1,2)[12] with drift         : 6958.582
##  ARIMA(2,0,1)(1,1,0)[12]                    : Inf
##  ARIMA(2,0,1)(1,1,0)[12] with drift         : Inf
##  ARIMA(2,0,1)(1,1,1)[12]                    : 6958.026
##  ARIMA(2,0,1)(1,1,1)[12] with drift         : 6959.676
##  ARIMA(2,0,1)(2,1,0)[12]                    : 7039.154
##  ARIMA(2,0,1)(2,1,0)[12] with drift         : Inf
##  ARIMA(2,0,2)(0,1,0)[12]                    : Inf
##  ARIMA(2,0,2)(0,1,0)[12] with drift         : Inf
##  ARIMA(2,0,2)(0,1,1)[12]                    : Inf
##  ARIMA(2,0,2)(0,1,1)[12] with drift         : 6961.928
##  ARIMA(2,0,2)(1,1,0)[12]                    : Inf
##  ARIMA(2,0,2)(1,1,0)[12] with drift         : Inf
##  ARIMA(2,0,3)(0,1,0)[12]                    : Inf
##  ARIMA(2,0,3)(0,1,0)[12] with drift         : Inf
##  ARIMA(3,0,0)(0,1,0)[12]                    : 7294.831
##  ARIMA(3,0,0)(0,1,0)[12] with drift         : 7296.831
##  ARIMA(3,0,0)(0,1,1)[12]                    : 7041.707
##  ARIMA(3,0,0)(0,1,1)[12] with drift         : 7043.748
##  ARIMA(3,0,0)(0,1,2)[12]                    : 7039.295
##  ARIMA(3,0,0)(0,1,2)[12] with drift         : 7041.342
##  ARIMA(3,0,0)(1,1,0)[12]                    : 7211.673
##  ARIMA(3,0,0)(1,1,0)[12] with drift         : 7213.688
##  ARIMA(3,0,0)(1,1,1)[12]                    : 7040.898
##  ARIMA(3,0,0)(1,1,1)[12] with drift         : 7042.945
##  ARIMA(3,0,0)(2,1,0)[12]                    : 7122.847
##  ARIMA(3,0,0)(2,1,0)[12] with drift         : 7124.88
##  ARIMA(3,0,1)(0,1,0)[12]                    : Inf
##  ARIMA(3,0,1)(0,1,0)[12] with drift         : Inf
##  ARIMA(3,0,1)(0,1,1)[12]                    : 6960.155
##  ARIMA(3,0,1)(0,1,1)[12] with drift         : 6961.843
##  ARIMA(3,0,1)(1,1,0)[12]                    : Inf
##  ARIMA(3,0,1)(1,1,0)[12] with drift         : Inf
##  ARIMA(3,0,2)(0,1,0)[12]                    : Inf
##  ARIMA(3,0,2)(0,1,0)[12] with drift         : Inf
##  ARIMA(4,0,0)(0,1,0)[12]                    : 7284.442
##  ARIMA(4,0,0)(0,1,0)[12] with drift         : 7286.447
##  ARIMA(4,0,0)(0,1,1)[12]                    : 7026.362
##  ARIMA(4,0,0)(0,1,1)[12] with drift         : 7028.411
##  ARIMA(4,0,0)(1,1,0)[12]                    : 7201.027
##  ARIMA(4,0,0)(1,1,0)[12] with drift         : 7203.049
##  ARIMA(4,0,1)(0,1,0)[12]                    : Inf
##  ARIMA(4,0,1)(0,1,0)[12] with drift         : Inf
##  ARIMA(5,0,0)(0,1,0)[12]                    : 7274.652
##  ARIMA(5,0,0)(0,1,0)[12] with drift         : 7276.663
## 
## 
## 
##  Best model: ARIMA(1,0,1)(2,1,1)[12]
Arima_forecast <- forecast(Arima_res, h = 60)
autoplot(Arima_forecast, include = 120)

print(summary(Arima_res))
## Series: Diff_Res 
## ARIMA(1,0,1)(2,1,1)[12] 
## 
## Coefficients:
##          ar1      ma1    sar1     sar2     sma1
##       0.4277  -0.9572  0.0232  -0.1870  -0.7838
## s.e.  0.0408   0.0127  0.0495   0.0464   0.0336
## 
## sigma^2 = 7715:  log likelihood = -3466.25
## AIC=6944.5   AICc=6944.65   BIC=6970.75
## 
## Training set error measures:
##                     ME     RMSE      MAE      MPE     MAPE      MASE       ACF1
## Training set -1.161222 86.58053 62.94708 43.37635 115.1095 0.6760727 0.02235114
checkresiduals(Arima_res)

## 
##  Ljung-Box test
## 
## data:  Residuals from ARIMA(1,0,1)(2,1,1)[12]
## Q* = 21.05, df = 19, p-value = 0.334
## 
## Model df: 5.   Total lags used: 24
accuracy(Arima_forecast)
##                     ME     RMSE      MAE      MPE     MAPE      MASE       ACF1
## Training set -1.161222 86.58053 62.94708 43.37635 115.1095 0.6760727 0.02235114
# SD RESIDUAL = 87.83507

# As we can see from both the forecasted plot and ACF plot, this is the best method for forecasting this time series.

Residential Sector - 4th Method: Additive Holt Winters model

AHW_res <- HoltWinters(Total_Res_ts, seasonal = "additive")
AHW_res_forecast <- forecast(AHW_res, h = 48)
plot(AHW_res_forecast, include = 120)

print(summary(AHW_res))
##              Length Class  Mode     
## fitted       2352   mts    numeric  
## x             600   ts     numeric  
## alpha           1   -none- numeric  
## beta            1   -none- numeric  
## gamma           1   -none- numeric  
## coefficients   14   -none- numeric  
## seasonal        1   -none- character
## SSE             1   -none- numeric  
## call            3   -none- call
checkresiduals(AHW_res)

## 
##  Ljung-Box test
## 
## data:  Residuals from HoltWinters
## Q* = 130.07, df = 24, p-value < 2.2e-16
## 
## Model df: 0.   Total lags used: 24
accuracy(AHW_res_forecast)
##                   ME     RMSE      MAE        MPE     MAPE      MASE      ACF1
## Training set 4.46806 96.98172 73.08302 0.01703382 4.767152 0.8406995 0.2586488
# As we can see from both the forecasted plot and ACF plot, this is not the best forecasting method.

FORECASTING METHODS & GRAPHS - EXPLANATION

FORECASTING METHODS

These forecasting techniques were the chosen techniques for the following reasons.

  • AHW and SNAIVE methods: These techniques were chosen because they are suited for data with seasonality. This is important because the time series is seasonal, as showed earlier.
  • ARIMA and ETS: These techniques were chosen because once we differentiate the time series to remove any trends, these techniques could automatically select the best models based on the the time series data set. Additionally, since the data was stationary, these techniques proved to be the best techniques for this data. This was very useful and facilitate the analysis of which models are the best models for forecasting this time series.

FORECASTING GRAPHS

The graphs chosen for the analysis of the forecasting models were the same for each model. These graphs were chosen because they allow for a clear comparison of the forecasted values against the actual values, to see if the residuals are normally distributed which is an indicator if the model is appropriate, to analyze seasonality in the data, to see if there is significant autocorrelation and thus decided the if the model is capturing all relevant information.

COMPARISONS

#Model Comparisons
Model_Accuracy_Comparison <- list(
  Snaive = accuracy(Snaive_forecast),
  ETS = accuracy(ETS_forecast),
  Arima = accuracy(Arima_forecast),
  AHW = accuracy(AHW_res_forecast)
)

print(Model_Accuracy_Comparison)
## $Snaive
##                     ME     RMSE      MAE       MPE    MAPE MASE       ACF1
## Training set 0.7687802 130.3775 93.10696 -12.16012 161.285    1 -0.2624987
## 
## $ETS
##                     ME     RMSE      MAE        MPE     MAPE      MASE
## Training set -7.635111 94.10162 68.65798 -0.6676478 4.429665 0.7897967
##                   ACF1
## Training set 0.2269772
## 
## $Arima
##                     ME     RMSE      MAE      MPE     MAPE      MASE       ACF1
## Training set -1.161222 86.58053 62.94708 43.37635 115.1095 0.6760727 0.02235114
## 
## $AHW
##                   ME     RMSE      MAE        MPE     MAPE      MASE      ACF1
## Training set 4.46806 96.98172 73.08302 0.01703382 4.767152 0.8406995 0.2586488
# When looking at the results of this comparison, we can see that the ARIMA model has the lowest RMSE, which is generally a indicator of model performance. Lower RMSEs are better.

CONCLUSION

The result of this comprehensive forecasting project is that the ARIMA model is the best fit for this time series.

Although other forecasting models indicate that similar insights when analyzing the residuals, it is clear that when it comes to a comparison of the forecasted values against the actual values, they did not perform as well as the ARIMA model.

Our understanding is that the best forecasting technique is the ARIMA model, but that it can be refined with the addition of other factors. Additionally, the forecasting model indicates that the time series data should continue to follow a pattern and an upward trend.

In terms of future trends, it is not clear the impact of external factors in this time series data. With that being said, with the future incorporation of other variables and a comparison with other sectors, new insights into the data set might evolve and thus a better understanding of what influences this data.