robjhyndman / forecast

Forecasting Functions for Time Series and Linear Models
http://pkg.robjhyndman.com/forecast
1.12k stars 342 forks source link

InvBoxCox not being applied when using one-step and Arima models with BoxCox transformation #605

Closed alepmaros closed 6 years ago

alepmaros commented 6 years ago

When calculating one-step forecast and using a model with Box Cox transformation, the fitted values returned are not being applied with the inverse box cox transformation.

Example:

require(fpp)
require(forecast)

a10.tre <- window(a10, end=2006)
a10.tes <- window(a10, start=2007)

lambda <- BoxCox.lambda(a10.tre)
fit1 <- auto.arima(a10.tre, lambda=lambda)
fit2 <- Arima(a10.tes, model=fit1)

fit2$fitted returns:

          Jan      Feb      Mar      Apr
2007 4.961065 3.934413 4.253066 3.896343 ...

When it should return InvBoxCox(fitted(fit2), lambda=lambda):

          Jan      Feb      Mar      Apr
2007 28.00986 16.75399 19.77845 16.41818 ...

Apparently, the problem comes when calling arima2 with the already transformed data. The function calls Arima again with the transformed values and does not pass the lambda value, thus not applying the InvBoxCox.

robjhyndman commented 6 years ago

Thanks for spotting the problem. Now fixed in https://github.com/robjhyndman/forecast/commit/4cb3201e78330365f75c7d9accd28e30b3b80228