[Rd] stats/HoltWinters.R inverted logic in seasonal in R and C
Norbert Kuder
norbert@kuder @end|ng |rom gm@||@com
Fri Jan 3 19:06:14 CET 2025
Hello,
I have noticed a potentially confusing implementation in the HoltWinters
function regarding the seasonal parameter mapping between R and C code:
https://github.com/wch/r-source/blob/4a1ed749271c52e60a85e794e6f34b0831efb1ae/src/library/stats/R/HoltWinters.R#L98
The C code interprets a seasonal value of 1 as additive and 0 as
multiplicative.
The R seasonal can be "additive" or "multiplicative", so the R code must
invert the logic when calling C.
The proposed solution is to define a seasonalChoice variable:
hw <- function(x, alpha, beta, gamma, seasonal, start.time, f, ...) {
lenx <- length(x)
seasonalChoice <- if (seasonal == "multiplicative") 0L else 1L
.C(C_HoltWinters,
as.double(x),
lenx,
as.double(max(min(alpha, 1), 0)),
as.double(max(min(beta, 1), 0)),
as.double(max(min(gamma, 1), 0)),
as.integer(start.time),
as.integer(seasonalChoice),
as.integer(f),
as.integer(!is.logical(beta) || beta),
as.integer(!is.logical(gamma) || gamma),
...
)
}
Please check the proposed solution.
Regards,
Norbert Kuder
[[alternative HTML version deleted]]
More information about the R-devel
mailing list