tidyverts / fable

Tidy time series forecasting
https://fable.tidyverts.org
GNU General Public License v3.0
564 stars 66 forks source link

forecast and TSLM how is the mean (point forecast) calculated? #402

Closed jennahamlin closed 1 year ago

jennahamlin commented 1 year ago

Hello -

When I generate a forecast using the TSLM function from fable, the point forecasts are different than those generated using the predict function associated with linear models (see below). Adding in the approx_normal = FALSE call, as suggested in #343, resolved my issue with the prediction intervals being different between the two methods but not the point forecast (mean) values. Obviously, I am missing something but am unsure of what. Any additional information would be greatly appreciated. Thank you

Forecast values using TSLM from fable

year caseCount .mean lo 95% hi 85%
2021 t(t(27,3.2,0.74)) 32 5.472078 112.2039
2022 t(t(27,3.4,0.74)) 37.1 6.263024 131.0257
2023 t(t(27,3.5,0.75)) 43.1 7.164173 153.0928
2024 t(t(27,3.6,0.75)) 50 8.190369 178.9772
2025 t(t(27,3.8,0.76)) 58 9.358397 209.3534

code to produce fable TSLM values

 iso222 %>%
  model(time_series = fable::TSLM(log(caseCount) ~ year )) |>
  forecast(h = "10 year", approx_normal=FALSE) %>%
  hilo(level = c (95))

Forecast values using predict

year fit lwr upr
2021 24.77879 5.472078 112.2039
2022 28.64641 6.263024 131.0257
2023 33.11772 7.164173 153.0928
2024 38.28693 8.190369 178.9772
2025 44.26299 9.358397 209.3534

code to produce fable predict values

lModel <- lm(caseCount ~ year, data = isoCountLog[1:29,])
exp(predict(lModel, list(year = isoCountRate222$year),
                          interval = 'prediction'))
robjhyndman commented 1 year ago

You are using a log transformation, and the mean is not the exponential of the predicted values on the log scale. See https://otexts.com/fpp3/ftransformations.html#bias-adjustments

jennahamlin commented 1 year ago

@robjhyndman Thank you for the reminder, made the adjustment to print median instead of mean.