我的印象是 R 包 fabletools 中的预测功能自动反向转换预测:“如果模型公式中已转换响应变量,则转换将自动反向转换”。它对 log 转换这样做,但不是 box_cox。我错过了一些明显的东西吗?
library(fpp3)
#> ── Attaching packages ──────────────────────────────────────────── fpp3 0.4.0 ──
#> ✓ tibble 3.1.6 ✓ tsibble 1.1.0
#> ✓ dplyr 1.0.7 ✓ tsibbledata 0.3.0
#> ✓ tidyr 1.1.4 ✓ feasts 0.2.2
#> ✓ lubridate 1.8.0 ✓ fable 0.3.1
#> ✓ ggplot2 3.3.5
#> ── Conflicts ───────────────────────────────────────────────── fpp3_conflicts ──
#> x lubridate::date() masks base::date()
#> x dplyr::filter() masks stats::filter()
#> x tsibble::intersect() masks base::intersect()
#> x tsibble::interval() masks lubridate::interval()
#> x dplyr::lag() masks stats::lag()
#> x tsibble::setdiff() masks base::setdiff()
#> x tsibble::union() masks base::union()
library(dplyr)
lambda <- us_employment %>%
features(Employed, features = guerrero)%>%
filter(!is.na(lambda_guerrero))%>%
head(n = 2)
#> Warning: 126 errors (1 unique) encountered for feature 1
#> [126] missing value where TRUE/FALSE needed
with_lambda <- left_join(lambda, us_employment)%>%
as_tsibble(key = Series_ID, index = Month)
#> Joining, by = "Series_ID"
box_fit <- with_lambda %>%
model(box_model = ARIMA(box_cox(Employed, lambda_guerrero)))
box_fcast <- box_fit %>%
forecast(h = "3 years")
log_fit <- with_lambda %>%
model(log_model = ARIMA(log(Employed)))
log_fcast <- log_fit %>%
forecast(h = "3 years")
autoplot(filter(us_employment, Series_ID=="CEU0500000001"))+
autolayer(filter(box_fcast, Series_ID=="CEU0500000001"))+
autolayer(filter(log_fcast, Series_ID=="CEU0500000001"))
#> Plot variable not specified, automatically selected `.vars = Employed`
由reprex 包于 2022-01-03 创建(v2.0.1)