Exponential Smoothing

load("workspace.RData")

Here we assume there is no trend or seasonality here. We use it for forecasting sales of a well established product in a stable market.

Complaints to a motoring Organisation

Period: 1996 to 1999 Data: values Any Transformation in the Data: number Type: Number of Complaints Unit: Number Frequency: Monthly Start of Frequency: Jan End of Frequency: Dec

We read the table,convert to time series and plot

Motor.dat <- read.table("ts/motororg.dat", header = T)
Comp.ts <- ts(Motor.dat$complaints, start = c(1996, 1), freq = 12)
plot(Comp.ts, xlab = "Time / months", ylab = "Complaints")

So there is no evidence of trend or season, so we can apply exponential smoothing.Now we Use HoltWinters method with beta and gamma equal to 0.

Comp.hw1 <- HoltWinters(Comp.ts, beta = FALSE, gamma = FALSE)
plot(Comp.hw1)

Comp.hw1
## Holt-Winters exponential smoothing without trend and without seasonal component.
## 
## Call:
## HoltWinters(x = Comp.ts, beta = FALSE, gamma = FALSE)
## 
## Smoothing parameters:
##  alpha: 0.1429622
##  beta : FALSE
##  gamma: FALSE
## 
## Coefficients:
##       [,1]
## a 17.70343

a is the value of level component. Level is the average value in the series. b is the value of trend component.C is the value of seasonal components. The estimated value of mean number of letters of complaints per month at the end of 1999 is 18. Let us see the SS1PE ( Sum of Squared one Step Ahead Prediction error)

Comp.hw1$SSE
## [1] 2502.028
str(Comp.hw1)
## List of 9
##  $ fitted      : Time-Series [1:47, 1:2] from 1996 to 2000: 27 28 28.4 27.8 26.4 ...
##   ..- attr(*, "dimnames")=List of 2
##   .. ..$ : NULL
##   .. ..$ : chr [1:2] "xhat" "level"
##  $ x           : Time-Series [1:48] from 1996 to 2000: 27 34 31 24 18 19 17 12 26 14 ...
##  $ alpha       : num 0.143
##  $ beta        : logi FALSE
##  $ gamma       : logi FALSE
##  $ coefficients: Named num 17.7
##   ..- attr(*, "names")= chr "a"
##  $ seasonal    : chr "additive"
##  $ SSE         : num 2502
##  $ call        : language HoltWinters(x = Comp.ts, beta = FALSE, gamma = FALSE)
##  - attr(*, "class")= chr "HoltWinters"
summary(Comp.hw1)
##              Length Class  Mode     
## fitted       94     mts    numeric  
## x            48     ts     numeric  
## alpha         1     -none- numeric  
## beta          1     -none- logical  
## gamma         1     -none- logical  
## coefficients  1     -none- numeric  
## seasonal      1     -none- character
## SSE           1     -none- numeric  
## call          4     -none- call

Let us see if we specify the value of alpha as 0.2

Comp.hw2 <- HoltWinters(Comp.ts, alpha = 0.2, beta=FALSE, gamma=FALSE)
Comp.hw2$SSE
## [1] 2526.39

This is more than 2502 as was earlier.

Comp.hw2
## Holt-Winters exponential smoothing without trend and without seasonal component.
## 
## Call:
## HoltWinters(x = Comp.ts, alpha = 0.2, beta = FALSE, gamma = FALSE)
## 
## Smoothing parameters:
##  alpha: 0.2
##  beta : FALSE
##  gamma: FALSE
## 
## Coefficients:
##       [,1]
## a 17.97913

The estimated value is increased slightly.

Holt- Winters method

Sale of Australian Wine

Period: Jan 1980 to July 1995 Data: values Any Transformation in the Data:No Type: Sale of Australian Wine by Category- Select “Sweet White Wine” Unit: Thousands of Liter Frequency: Monthly Start of Frequency: Jan End of Frequency: July

We read the table,convert to time series and plot

wine.dat <- read.table("ts/wine.dat", header = T)
sweetw.ts <- ts(wine.dat$sweetw, start = c(1980, 1), freq = 12)
plot(sweetw.ts, xlab = "Time / months", ylab = "Sales ( 1000 liters")

Applying Holt-Winters method

sweetw.hw <- HoltWinters(sweetw.ts,seasonal="mult")
sweetw.hw;
## Holt-Winters exponential smoothing with trend and multiplicative seasonal component.
## 
## Call:
## HoltWinters(x = sweetw.ts, seasonal = "mult")
## 
## Smoothing parameters:
##  alpha: 0.4086698
##  beta : 0
##  gamma: 0.4929402
## 
## Coefficients:
##            [,1]
## a   285.6890314
## b     1.3509615
## s1    0.9498541
## s2    0.9767623
## s3    1.0275900
## s4    1.1991924
## s5    1.5463100
## s6    0.6730235
## s7    0.8925981
## s8    0.7557814
## s9    0.8227500
## s10   0.7241711
## s11   0.7434861
## s12   0.9472648
sweetw.hw$coef;
##           a           b          s1          s2          s3          s4 
## 285.6890314   1.3509615   0.9498541   0.9767623   1.0275900   1.1991924 
##          s5          s6          s7          s8          s9         s10 
##   1.5463100   0.6730235   0.8925981   0.7557814   0.8227500   0.7241711 
##         s11         s12 
##   0.7434861   0.9472648
sweetw.hw$SSE
## [1] 477693.9

Lets plot the fitted value (decomposed)

plot(sweetw.hw$fitted)

Lets plot the predicted value along with the actual values

plot(sweetw.hw)  

Four year Forcast of the Air passenger data

AP.hw <- HoltWinters(AP,seasonal="mult")
plot(AP.hw)

Now Predict for next 4 years

AP.predict <- predict(AP.hw,n.ahead=4*12)
ts.plot(AP,AP.predict,lty=1:2)

Lets print the values

print(AP.predict)
##           Jan      Feb      Mar      Apr      May      Jun      Jul
## 1961 447.0559 419.7123 464.8671 496.0839 507.5326 575.4509 666.5923
## 1962 481.3732 451.7258 500.1008 533.4477 545.5202 618.2550 715.8704
## 1963 515.6904 483.7392 535.3345 570.8114 583.5078 661.0591 765.1485
## 1964 550.0076 515.7527 570.5682 608.1751 621.4954 703.8632 814.4265
##           Aug      Sep      Oct      Nov      Dec
## 1961 657.9137 550.3088 492.9853 420.2073 465.6345
## 1962 706.2524 590.4954 528.7681 450.5242 499.0281
## 1963 754.5912 630.6820 564.5509 480.8411 532.4217
## 1964 802.9299 670.8687 600.3337 511.1580 565.8153

We can also estimate the model Parameters

AP.hw$alpha;
##     alpha 
## 0.2755925
AP.hw$beta;
##       beta 
## 0.03269295
AP.hw$gamma
##     gamma 
## 0.8707292
save.image("workspace.Rdata")