# What do the “coefficients” in R's HoltWinters function represent?

I'm using the HoltWinters function in R and I'm trying to understand what the "coefficients" represent in the object that is returned by that function. They don't seem to match in any obvious way the values returned when you look at the $• Did you leave off something on the end of your question? – Glen_b -Reinstate Monica Mar 24 '13 at 22:04 ## 5 Answers +1 this is confusing. If your time series has length$N$and frequency$p$, then the so-called "coefficients" (which can be accessed as HW$coeff if HW is the object returned by HoltWinters) are exactly the values $a[N]$, $b[N]$ and $s[N-p+1]$, $s[N-p+2], \cdots s[N]$ where these are defined by the formulas in the Holt Winters help page, which can be accessed from within R with ?HoltWinters.

For the additive model, which is the default, suppose my.ts is a time series object with positive frequency $p$. The values of $a[N-1]$, $b[N-1]$ and all the earlier $s[t]$ up to $s[N-p]$ are given in the table HoltWinters(my.ts)$fitted. The values in HoltWinters(my.ts)$coeff are calculated from these using the formulas $$a[t] = α (Y[t] - s[t-p]) + (1-α) (a[t-1] + b[t-1])$$

$$b[t] = β (a[t] - a[t-1]) + (1-β) b[t-1]$$

with $t=N$ and $\alpha =$ HoltWinters(my.ts)$alpha,$\beta = $HoltWinters(my.ts)$beta, and

$$s[t] = γ (Y[t] - a[t]) + (1-γ) s[t-p]$$

with $t=N-p+1, \ldots, N$ and $\alpha =$ HoltWinters(my.ts)$alpha,$\beta = $HoltWinters(my.ts)$beta, and $\gamma =$ HoltWinters(my.ts)$gamma. This works for$a$and$b$(the level and trend) but when I do the calculation for the seasonals, I get slightly different values (within 5% or so) than are given in the output. I hope somebody can edit this answer to explain what is going on with the seasonals. Here is a link to the C code for the hw function which is called by the HoltWinters function: https://svn.r-project.org/R/trunk/src/library/stats/src/HoltWinters.c The meaning of the a, b, s, alpha, beta and gamma parameters is described in the help on the HoltWinters function (try ?HoltWinters in R), under Details. e.g. the additive model is described so: Yhat[t+h] = a[t] + h * b[t] + s[t - p + 1 + (h - 1) mod p], where a[t], b[t] and s[t] are given by a[t] = α (Y[t] - s[t-p]) + (1-α) (a[t-1] + b[t-1]) b[t] = β (a[t] - a[t-1]) + (1-β) b[t-1] s[t] = γ (Y[t] - a[t]) + (1-γ) s[t-p]  If we look at the help, one of the examples is: (m <- HoltWinters(co2)) plot(m) plot(fitted(m))  With output: Holt-Winters exponential smoothing with trend and additive seasonal component. Call: HoltWinters(x = co2) Smoothing parameters: alpha: 0.5126484 beta : 0.009497669 gamma: 0.4728868 Coefficients: [,1] a 364.7616237 b 0.1247438 s1 0.2215275 s2 0.9552801 s3 1.5984744 s4 2.8758029 s5 3.2820088 s6 2.4406990 s7 0.8969433 s8 -1.3796428 s9 -3.4112376 s10 -3.2570163 s11 -1.9134850 s12 -0.5844250  Now let's look at the output of calling coefficients: coefficients(m) a b s1 s2 s3 s4 364.7616237 0.1247438 0.2215275 0.9552801 1.5984744 2.8758029 s5 s6 s7 s8 s9 s10 3.2820088 2.4406990 0.8969433 -1.3796428 -3.4112376 -3.2570163 s11 s12 -1.9134850 -0.5844250  Which correspond exactly to the output of the same quantities generated before. Taking into account the description of a, b, s, alpha, beta and gamma on the help page, which parts are unclear to you? • Could you tell which time point are "a" and "b" representing? – Diansheng Mar 19 '18 at 16:56 I agree that there is puzzle. To see the puzzle I considered the co2 series available in R. The answer is long. May you just to the *-part that I added today I have expected that co2HWBis$coefficients


equals

co2HW$fitted[length(co2HW$fitted[,3]),3]


i.e. the coeff equals the last extimated trend. Below you can check that this is not the case. However

co2HW$fitted[length(co2HW$fitted[,3]),3]


equals coefficient you were to obtain if you drop the last value of the series as is deomestrated below. I suspect that the coefficient is somehow "written forward". I find it furthermore puzzling the matters are different if you allow beta to be estimated.

I reading the source code (http://svn.r-project.org/R/trunk/src/library/stats/R/HoltWinters.R) but I am not yet sure what goes on.

This is the complete code

    rm(list=ls())

co2HW = HoltWinters(co2, alpha = 0.2, gamma = 0.2, beta = 0.5)
# co2HW$coeff co2HW$fitted[length(co2HW$fitted[,3]),3] co2Bis = window(co2,end=c(1997,11)) co2HWBis = HoltWinters(co2Bis, alpha=0.2, gamma=0.2, beta=0.5) co2HWBis$coefficients
# co2HWBis$fitted[length(co2HWBis$fitted[,3])-1,3]

co2HW$beta*(co2HW$fitted[length(co2HW$fitted[,2]),2] - co2HW$fitted[length(co2HW$fitted[,2])-1,2]) + (1 - co2HW$beta)*co2HW$fitted[length(co2HW$fitted[,3])-1,3]

#####################

co2HW = HoltWinters(co2, alpha = 0.2, gamma = 0.2)
# co2HW$coeff co2HW$fitted[length(co2HW$fitted[,3]),3] co2Bis = window(co2,end=c(1997,11)) co2HWBis = HoltWinters(co2Bis, alpha=0.2, gamma=0.2) co2HWBis$coefficients
# co2HWBis$fitted[length(co2HWBis$fitted[,3])-1,3]

co2HW$beta*(co2HW$fitted[length(co2HW$fitted[,2]),2] - co2HW$fitted[length(co2HW$fitted[,2])-1,2]) + (1 - co2HW$beta)*co2HW$fitted[length(co2HW$fitted[,3])-1,3]


*-part

... one night later I think I can give an answer that looks like an answer. In my opinion the problem is the timing of the table co2HW$fitted. The last line is not the estimated trend level and saison of the last period in the sample. The coefficients are the estimated level, trend and saison of the last period but these value are not displayed in the table. I hope th following code is convincing rm(list=ls()) x = co2 m = HoltWinters(x) # m$fitted[length(m$fitted[,3]),3] aux1 = m$alpha*( x[length(x)] - m$fitted[length(m$fitted[,3]),4]  ) +
( 1 - m$alpha )*( m$fitted[length(m$fitted[,3]),3] + m$fitted[length(m$fitted[,3]),2] ); aux1 m$coeff

aux2 = m$beta*(aux1 - m$fitted[length(m$fitted[,3]),2] ) + (1-m$beta)*m$fitted[length(m$fitted[,3]),3]
aux2
m$coeff m$coeff
aux3 = m$gamma*(x[length(x)] - aux1) + ( 1 - m$gamma )*m$fitted[length(m$fitted[,3]),4]
aux3

• Welcome to the site, are you the original poster of the question? This doesn't appear to be an answer. – Andy W Jul 30 '13 at 11:49
• Thanks @user28623! I agree that there is something fishy about it. I also tried to read the source code but didn't make progress. – Flounderer Jul 30 '13 at 22:15
• I posted the co2 stuff and I think I figured out what is going on. First, the last value of co2HW$fitted[,3] is not the estimated trend of the last period of the sample. It is the estimated trend of one period before that last period. Second, co2HW$coeff is the trend of the last period. In my opinion the timing of the table of co2HW$fitted is misleading. – user28623 Jul 31 '13 at 20:11 • @user28623, do you mean co2HW$fitted[,1] instead of co2HW$fitted[,3]? and co2HW$fitted[,1] is supposed to be level, not trend. i think your answer is really helpful, but a bit confusing – Diansheng Mar 19 '18 at 16:31

I think the key point about the coefficients, which I couldn't see in the other answers but may have missed, is that they are the values of smoothed level and smoothed trend for the last period in the time series on which the forecast was based/made; and smoothed seasonal components for the last 12 months of that time series.

Understanding the table of fitted values for the forecast also helps. For each row corresponding to time t, the values of level and trend are the smoothed values for time t-1, and the value of season is the smoothed value for t-p. These are added to give the estimated true level for time t, Xhat.

I have only begun to use R fairly recently, so apologies if my terminology isn't fully accurate.

• I don't think the question is clearly stated . As glen_b points out it is incomplete. Since the question is unclear I don't see how an answer can be given. – Michael R. Chernick Mar 17 '18 at 23:53

This is from the HoltWinters documentation in R. I had the same question and this answers why I could not calculate the same seasonal values. The function is using a decomposition method to find all the initial values when incorporating seasonality, whereas for single and double exponential smoothing it doesn't do this.

"For seasonal models, start values for a, b and s are inferred by performing a simple decomposition in trend and seasonal component using moving averages (see function decompose) on the start.periods first periods (a simple linear regression on the trend component is used for starting level and trend). For level/trend-models (no seasonal component), start values for a and b are x and x - x, respectively. For level-only models (ordinary exponential smoothing), the start value for a is x."

Found this website that explains how to get initial values: https://robjhyndman.com/hyndsight/hw-initialization/