Describe a situation or problem from your job, everyday life, current events, etc., for which exponential smoothing would be appropriate. What data would you need? Would you expect the value of α (the first smoothing parameter) to be closer to 0 or 1, and why?
I would use exponential smoothing method for stock market time series data. I would need daily closing price of a stock or index. Value of the alpha depends on the randomness (fluctuation) of daily closing stock prices. If too much of fluctuations in the historical data, I would choose alpha closer to 0. i.e I would trust previous estimate more than the current observation.
If daily closing stock prices are relatively stable, I would choose alpha closer to 1. i.e I trust what is see today because of less randomness it is more likely real change in the stock price.
temps <- read.table('temps.txt', header = TRUE)
head(temps)
I have transformed the year-wise temperatur data into time series long format (wide to long) using gather function from tidyverse package. I have set the frequency to 123 so that each year’s data is taken as one cycle.
Note: It maybe well true that each year’s 4 month data also have seasonal factors but I chose to interpret it as one summer cycle.
First I have implemented simple exponential smoothing (single smoothing - no trend and seasonal factors take into account)
I have also predicted forecasts 10 points into the future and the results can be found below.
## Seasonal Holt-Winters
temp_long <- gather(temps, year, temp, X1996:X2015)
temp.ts <- ts(temp_long[,c(1,3)], frequency = 123)
m <- HoltWinters(temp.ts[,2], beta=FALSE, gamma = FALSE)
plot(m)
m
## Holt-Winters exponential smoothing without trend and without seasonal component.
##
## Call:
## HoltWinters(x = temp.ts[, 2], beta = FALSE, gamma = FALSE)
##
## Smoothing parameters:
## alpha: 0.8388021
## beta : FALSE
## gamma: FALSE
##
## Coefficients:
## [,1]
## a 63.30952
plot(fitted(m))
pred <- predict(m, n.ahead = 10, prediction.interval = TRUE)
pred
## Time Series:
## Start = c(21, 1)
## End = c(21, 10)
## Frequency = 123
## fit upr lwr
## 21.00000 63.30952 72.68115 53.93789
## 21.00813 63.30952 75.54153 51.07752
## 21.01626 63.30952 77.84969 48.76936
## 21.02439 63.30952 79.83861 46.78043
## 21.03252 63.30952 81.61267 45.00637
## 21.04065 63.30952 83.22936 43.38969
## 21.04878 63.30952 84.72434 41.89471
## 21.05691 63.30952 86.12155 40.49749
## 21.06504 63.30952 87.43799 39.18105
## 21.07317 63.30952 88.68624 37.93281
I have also implemented double exponential smoothing with trend factor taken into account
Also predicted 10 forecasts into the future
## Seasonal Holt-Winters
m <- HoltWinters(temps, gamma = FALSE)
#plot(m)
m
## Holt-Winters exponential smoothing with trend and without seasonal component.
##
## Call:
## HoltWinters(x = temps, gamma = FALSE)
##
## Smoothing parameters:
## alpha: 0.9583203
## beta : 0.09266336
## gamma: FALSE
##
## Coefficients:
## [,1]
## a 62.3230346
## b -0.9404959
plot(fitted(m))
pred <- predict(m, n.ahead = 10, prediction.interval = TRUE)
## Warning in cbind(fit = fit, upr = if (prediction.interval) fit + int, lwr =
## if (prediction.interval) fit - : number of rows of result is not a multiple of
## vector length (arg 1)
I have also implemented triple exponential smoothing by including trend and seasonal factors.
## Seasonal Holt-Winters
temp_long <- gather(temps, year, temp, X1996:X2015 )
temp.ts <- ts(temp_long[,c(1,3)], frequency = 123)
m <- HoltWinters(temp.ts[,2], seasonal = 'mult')
plot(m)
m
## Holt-Winters exponential smoothing with trend and multiplicative seasonal component.
##
## Call:
## HoltWinters(x = temp.ts[, 2], seasonal = "mult")
##
## Smoothing parameters:
## alpha: 0.615003
## beta : 0
## gamma: 0.5495256
##
## Coefficients:
## [,1]
## a 73.679517064
## b -0.004362918
## s1 1.239022317
## s2 1.234344062
## s3 1.159509551
## s4 1.175247483
## s5 1.171344196
## s6 1.151038408
## s7 1.139383104
## s8 1.130484528
## s9 1.110487514
## s10 1.076242879
## s11 1.041044609
## s12 1.058139281
## s13 1.032496529
## s14 1.036257448
## s15 1.019348815
## s16 1.026754142
## s17 1.071170378
## s18 1.054819556
## s19 1.084397734
## s20 1.064605879
## s21 1.109827336
## s22 1.112670130
## s23 1.103970506
## s24 1.102771209
## s25 1.091264692
## s26 1.084518342
## s27 1.077914660
## s28 1.077696145
## s29 1.053788854
## s30 1.079454300
## s31 1.053481186
## s32 1.054023885
## s33 1.078221405
## s34 1.070145761
## s35 1.054891375
## s36 1.044587771
## s37 1.023285461
## s38 1.025836722
## s39 1.031075732
## s40 1.031419152
## s41 1.021827552
## s42 0.998177248
## s43 0.996049257
## s44 0.981570825
## s45 0.976510542
## s46 0.967977608
## s47 0.985788411
## s48 1.004748195
## s49 1.050965934
## s50 1.072515008
## s51 1.086532279
## s52 1.098357400
## s53 1.097158461
## s54 1.054827180
## s55 1.022866587
## s56 0.987259326
## s57 1.016923524
## s58 1.016604903
## s59 1.004320951
## s60 1.019102781
## s61 0.983848662
## s62 1.055888360
## s63 1.056122844
## s64 1.043478958
## s65 1.039475693
## s66 0.991019224
## s67 1.001437488
## s68 1.002221759
## s69 1.003949213
## s70 0.999566344
## s71 1.018636837
## s72 1.026490773
## s73 1.042507768
## s74 1.022500795
## s75 1.002503740
## s76 1.004560984
## s77 1.025536556
## s78 1.015357769
## s79 0.992176558
## s80 0.979377825
## s81 0.998058079
## s82 1.002553395
## s83 0.955429116
## s84 0.970970220
## s85 0.975543504
## s86 0.931515830
## s87 0.926764603
## s88 0.958565273
## s89 0.963250387
## s90 0.951644060
## s91 0.937362688
## s92 0.954257999
## s93 0.892485444
## s94 0.879537700
## s95 0.879946892
## s96 0.890633648
## s97 0.917134959
## s98 0.925991769
## s99 0.884247686
## s100 0.846648167
## s101 0.833696369
## s102 0.800001437
## s103 0.807934782
## s104 0.819343668
## s105 0.828571029
## s106 0.795608740
## s107 0.796609993
## s108 0.815503509
## s109 0.830111282
## s110 0.829086181
## s111 0.818367239
## s112 0.863958784
## s113 0.912057203
## s114 0.898308248
## s115 0.878723779
## s116 0.848971946
## s117 0.813891909
## s118 0.846821392
## s119 0.819121827
## s120 0.851036184
## s121 0.820416491
## s122 0.851581233
## s123 0.874038407
plot(fitted(m))
I have implemented CUSUM method in Excel to find out if there is a delay in the onset of the winter as moving from 1996 to 2015.