[R] predict.HoltWinters source misunderstanding.

rkevinburton at charter.net rkevinburton at charter.net
Thu Aug 20 16:50:32 CEST 2009

If I look in the stats package for the 'R' source code for predict.HoltWinters I see the following lines:

    vars <- function(h) {
        psi <- function(j) object$alpha * (1 + j * object$beta) + 
            (j%%f == 0) * object$gamma * (1 - object$alpha)
        var(residuals(object)) * if (object$seasonal == "additive") 
            sum(1, (h > 1) * sapply(1L:(h - 1), function(j) crossprod(psi(j))))

There is more source code but my question is on the call to crossprod(psi(j)). Looking at the psi function I could see no elements that are vectors (or matrices) or that result in such. In fact if I replace the call to crossprod with:

            sum(1, (h > 1) * sapply(1L:(h - 1), function(j) {
                                                              r <- psi(j)
                                                            } ))

I get the same results. If I further augment my test by printing out the length of the return value from 'psi' I can see no case where 'psi' would return anything but a single number. So my question is, why the call to crossprod when simply squaring the number will do. Am I missing a case when the members of the HoltWinters fit would be vectors and then crossprod would be appropriate or is this just an oversight?

Thank you.


More information about the R-help mailing list