Modelling and forecasting using exponential smoothing technique

Introduction:

The main objective of this project was to implement the various forecasting techniques on the data set provided to us. The forecasting techniques used in the project are ARIMA models, simple exponential smoothing, holt’s method, and holt’s winters. The data provided to me was on the import and export of oil and non-oil products for a period of 26 years, this data was in a monthly format.

Loading the required data

loading data from the clipboard

Investment income <- read.delim('clipboard', header = FALSE)

Investment Income

 

       Qtr1  Qtr2 Qtr3 Qtr4

2000  264  146  262   76

2001  164  222   39  173

2002  232   49  168  225

2003   46  183  247   51

2004  193  234   23  191

2005  255   54  150  223

2006   52  188  252   53

2007  195  230   18  176

2008  253   62  186  221

2009   19  178  238   45

2010  194  220   14  175

2011  107   87  206  211

2012   11  184  229   27

2013  198  259   47  197

2014   93   64  192  242

2015   36  210  248   22

2016  208  101   68  231

2017  136    4  238  256

2018    3  224  115   81

2019   88  126   83  260

2020  123   79  105  127

2021   63  254  121   77

 

Loading needed libraries

Since we had to deal with functions related to time series, first we initialized a set of libraries used for time series. We used the following libraries for this project.

 library(tseries)

 library(fUnitRoots)

 library(tidyverse)

 library(fpp2)

 library(readxl)

 library(forecast)

 library(urca)


Convert into vector and display

vec <- as.vector(t(Investmentincome))

[1] "A.2.c.1) Investment Income" "2373"                     

  [3] "9963"                       "-7590"                    

  [5] "3004"                       "7281"                     

  [7] "-4277"                      "3226"                     

  [9] "7949"                       "-4723"                    

 [11] "3087"                       "7692"                     

 [13] "-4605"                      "4005"                     

 [15] "8883"                       "-4878"                    

 [17] "4522"                       "7980"                     

 [19] "-3458"                      "4424"                     

 [21] "9456"                       "-5032"                    

 [23] "2536"                       "7511"                     

 [25] "-4975"                      "4230"                     

 [27] "9249"                       "-5019"                    

 [29] "4777"                       "7819"                     

 [31] "-3042"                      "3441"                     

 [33] "9318"                       "-5877"                    

 [35] "4036"                       "7261"                     

 [37] "-3225"                      "3741"                     

 [39] "8343"                       "-4602"                    

 [41] "4568"                       "7098"                     

 [43] "-2530"                      "3381"                     

 [45] "13313"                      "-9932"                    

 [47] "5624"                       "5832"                     

 [49] "-208"                       "4018"                     

 [51] "7781"                       "-3763"                    

 [53] "5018"                       "9661"                     

 [55] "-4643"                      "5000"                     

 [57] "10912"                      "-5912"                    

 [59] "4502"                       "8593"                     

 [61] "-4091"                      "5717"                     

 [63] "8969"                       "-3252"                    

 [65] "5697"                       "12046"                    

 [67] "-6349"                      "7876"                     

 [69] "20559"                      "-12683"                   

 [71] "8343"                       "9538"                     

 [73] "-1195"                      "7544"                     

 [75] "15737"                      "-8193"                    


Converting to Time Series

data_ts <- ts(Investmentincome, start = c(2000,1), end= c(2021,4) ,frequency = 4)

data_ts


Removing NA Values in TimeSeries Data

data_ts< na.omit(data_ts)

data_ts


Plotting the TimeSeries Data

plot(data_ts)



To forecast any series, we need to check if a series is stationary or not. For this we need to identify the trend of the series and also the seasonality. To know the trend of the data, we need to decompose it. To do this, we use the decompose function.

Decomposition of time series data

ot_holtsWinter <- decompose(data_ts, "additive")

autoplot(ot_holtsWinter)



From the above graph, it is very much evident that there is a trend in the series and it is also seasonal. But in order to forecast, the series needs to be stationary and also there should be no trend in the data. Hence, to make the series stationary we need to do a log differentiation of the series.  We observe seasonality in the data; hence we need to differentiate the data to make it stationary.

data_ts %>% log() %>% diff -> nived_dif

autoplot(nived_diff)



We observe that the series is stationary around the mean, so we can infer that that series is stationary, but to conclusively prove that it is stationary we perform the dickey-fuller test. On performing the DFT, we get the following output.

 

Augmented Dickey-Fuller Test

adfTest(nived_dif)

 

Modeling and forecasting the given time series using the ARIMA method

ot_arima <- auto.arima(data_ts, trace = TRUE)

ot_arima

Series: data_ts

ARIMA(2,1,1)(0,0,2)[4]

Coefficients:

          ar1      ar2      ma1     sma1    sma2

      -0.7548  -0.6591  -0.8795  -0.4349  0.5220

s.e.   0.0869   0.0938   0.0695   0.1278  0.1456

 sigma^2 = 2582:  log likelihood = -466.4

 

 Using exponential smoothing technique to model and forecast the demand deposit data.

ot_ses <-ses(data_ts, h=100)

ot_ses #Printing the forecast

plot ot_ses


summary(ot_ses[["model"]])

Simple exponential smoothing

Call:

 ses(y = data_ts, h = 100)

  Smoothing parameters:

    alpha = 1e-04

  Initial states:

    l = 146.3566

  sigma:  82.8743

     AIC     AICc      BIC

1175.432 1175.718 1182.864

 Training set error measures:

                      ME     RMSE      MAE       MPE     MAPE     MASE       ACF1

Training set -0.02204478 81.92717 74.08973 -176.2574 209.0476 0.607708 -0.4141746

 

Using Holt's Method

ot_holt <- holt(data_ts, h=100, PI=FALSE)

ot_holt #Printing the forecast

summary(ot_holt[["model"]])

autoplot(ot_holt)

Holt's method

 Call:

 holt(y = data_ts, h = 100, PI = FALSE)

  Smoothing parameters:

    alpha = 0.0362

    beta  = 1e-04

  Initial states:

    l = 221.8823

    b = -0.9145

 sigma:  86.7855

   AIC     AICc      BIC

1185.477 1186.209 1197.864

 Training set error measures:

                    ME     RMSE      MAE       MPE     MAPE      MASE       ACF1

Training set -6.344895 84.79012 71.89083 -172.9506 201.9319 0.5896719 -0.3640745

 

Holt's Winter Seasonal Method

fit1 <- hw(data_ts, seasonal = "additive")

fit2 <- hw(data_ts, seasonal = "multiplicative")

autoplot(fit1)


 autoplot(fit1)


autoplot(fit2)

 


Summary of Holt's Winter Method

summary(ot_forecast_holtWinter[["model"]]) #Summary of Holt's Winter Method

ETS(A,Ad,A)

Call:

 ets(y = data_ts, model = "AAA")

  Smoothing parameters:

    alpha = 0.0111

    beta  = 0.0111

    gamma = 1e-04

    phi   = 0.9099

  Initial states:

    l = 228.5563

    b = -2.7262

    s = 8.9232 2.0928 7.3283 -18.3443

   sigma:  87.8253

     AIC     AICc      BIC

1192.173 1195.030 1216.946

 Training set error measures:

                    ME     RMSE      MAE       MPE     MAPE      MASE       ACF1

Training set -7.594767 83.21316 72.68103 -176.1857 204.9611 0.5961533 -0.3769768


This blog is part of the assignments submitted for the course, Time series Analysis and Forecasting/one of the Business Analytics Electives Courses at Amrita.


By

Mr. Nived Devadas

CB.BU.P2MBA21083,

5th trimester, MBA,

Amrita School of Business,

Amrita Vishwa Vidyapeetham, 

Coimbatore.


References

https://www.rstudio.com/resources/books/

https://otexts.com/fpp2/

https://datascienceplus.com/time-series-analysis-using-arima-model-in-r/

  

Comments