HoltWinter Initial values not matching with Rob Hyndman theory
Asked Answered
D

1

7

I am following this tutorial by Rob Hyndman for initialization (additive).

Steps to calculate initial values are specified as: enter image description here

I am running above steps manually (with pen/paper) on data set provided in Rob Hydman free online text book. Values I got after first two steps are: enter image description here

I used same data set on "R", but seasonal output values in R are drastically different (screenshot below) enter image description here

Not sure what I am doing wrong. Any help would be appreciated.

Another interesting thing I have observed just now is, initial level (l(t)) in text book is 33.8, but in R output it is : 48.24, which proves that I am missing something while calculating manually.

EDIT:

Here is how I am calculating Moving Averages Smooth (Based on formula used in Section 2 of this link. )

After calculating I have de-trended, means original value - smoothed value.

Then seasonal values: Which is

S1 =Average of Q1
S2 = Average of Q2
...

enter image description here

Divulsion answered 12/3, 2014 at 19:11 Comment(6)
Can you take a picture of your pen/paper calculations and upload that as well?Retaliate
@joran: Added image of how I am calculating Moving Average Smooth.Divulsion
+1 for the pic! Do you use rolled paper for that? You might be able to get left over rolls from the local newspaper for next to nothing, put it on a dowel and endless paper... That's what I do.Heinrike
@Thell: Problem is, getting nice shot on phone, if it is full paper, I couldn't get clarity. By the way we do have few realms in office.Divulsion
@Nambari Am I wrog or you didn't add your data?Madai
@PauloCardoso: data set is the same one refereed in oText link in question.Divulsion
C
7

The first two values of your moving average are incorrect. You have assumed that the values prior to the first observation are zero. They are not zero, they are missing, which is quite different. It is impossible to compute the moving average for the first two observations for this reason.

The third and subsequent values of your moving average are only approximately correct because you have rounded the data to the first decimal point instead of using the data as provided in the fpp package in R.

The values obtained following this procedure are used as initial values in the optimization within ets(). So the output from ets() will not contain the initial values but the optimized values. The table in the book gives the optimized values. You will not be able to reproduce them using a simple procedure.

However, you can reproduce what is provided by HoltWinters because it does not do any optimization of initial values. Using HoltWinters, the initial seasonal values are given as:

> HoltWinters(y)$fitted[1:4,]
         xhat    level    trend    season
[1,] 43.73934 33.21330 1.207739  9.318302
[2,] 28.25863 35.65614 1.376490 -8.774002
[3,] 36.86581 37.57569 1.450688 -2.160566
[4,] 41.87604 38.83521 1.424568  1.616267

(The output in coefficients gives the final states not the initial states.)

The seasonal indices in the last column can be computed as follows:

       y   MAsmooth  detrend detrend.adj
 41.72746       NA        NA          NA
 24.04185       NA        NA          NA
 32.32810 34.41724 -2.089139   -2.160566
 37.32871 35.64101  1.687695    1.616267
 46.21315 36.82342  9.389730    9.318302
 29.34633 38.04890 -8.702575   -8.774002
 36.48291       NA        NA          NA
 42.97772       NA        NA          NA

The last column is the adjusted detrended data (so they add to zero).

Crat answered 19/3, 2014 at 11:40 Comment(2)
Thank you for the your time and answer. I am looking at R implementation of HoltWinters and got some clarity about ZERO and missing. Your statement about using ets() explains why HoltWinters$fitted not matching with book values Thanks!. Can you please help with me how detrend.adj calculated in answer. Thanks!Divulsion
detrend.adj = detrend - mean(detrend)Crat

© 2022 - 2024 — McMap. All rights reserved.