4

Suppose I'm curious about the workings of the R function, say HoltWinters. I typed HoltWinters and it shows me R source for the function. On inspection, the source shows the function is a wrapper around a second function:

    final.fit <- hw(alpha, beta, gamma)

Presumably, the serious work happens in the function hw. However, I can't find this function anywhere to read its source

> hw
Error: object 'hw' not found

How can I read the source?


Edit: Ok, so now I've read hw , I see it's a wrapper around C_HoltWinters. How can I read that?

Jeffrey Bosboom
  • 13,313
  • 16
  • 79
  • 92
Colonel Panic
  • 132,665
  • 89
  • 401
  • 465

1 Answers1

6

As you successfully found, there are lines

hw <- function(alpha, beta, gamma)
    .C(C_HoltWinters,
    ....

in the source of HoltWinters function. Which means that we need to look at C files: you can find all the source code of R here, or just go straight here.

Julius Vainora
  • 47,421
  • 9
  • 90
  • 102
  • How should we implement holtwinters in R on ourselves if we just need it for `exponential smoothing` as in `lines(HoltWinters(nhtemp, gamma=F)$fitted[,2], col = "red")` ? Thanks – Mona Jalal Apr 21 '14 at 23:33
  • @MonaJalal, see details in `?HoltWinters`, there are some formulas and also it says that they minimize one-step prediction error. So decide on whether your series is seasonal, etc. and use e.g. `optim` with these formulas. I will can get back to this on Friday if you do not solve this until then. – Julius Vainora Apr 22 '14 at 01:24
  • but I don't need the whole hw implementation in R for my purpose. – Mona Jalal Apr 22 '14 at 01:57
  • @MonaJalal, actually you need most of it. Assuming that your series is not seasonal you can ignore that part, but in any case you need to do optimization to choose other coefficients. Note that the R code itself does not fully include the optimization step, see the C code given in this answer, it is the most important part. – Julius Vainora Apr 24 '14 at 20:32