这不是最直观的错误消息,但我以前使用此功能曾经历过。你实际上必须传递Debt
给这两个参数。我相信错误消息.mean
是由于内部函数引发的错误而引用的。
library(tsibbledata)
library(tsibble)
library(fable)
library(fabletools)
aus <- tsibbledata::hh_budget
fit <- fabletools::model(aus, ARIMA = ARIMA(Debt))
fc_tsibble <- fit %>%
fabletools::forecast(., h = 2) %>%
as_tibble(.) %>%
tsibble::as_tsibble(., key = c(Country, .model), index = Year)
fc_tsibble
#> # A tsibble: 8 x 5 [1Y]
#> # Key: Country, .model [4]
#> Country .model Year Debt .mean
#> <chr> <chr> <dbl> <dist> <dbl>
#> 1 Australia ARIMA 2017 N(215, 21) 215.
#> 2 Australia ARIMA 2018 N(221, 63) 221.
#> 3 Canada ARIMA 2017 N(188, 7) 188.
#> 4 Canada ARIMA 2018 N(192, 21) 192.
#> 5 Japan ARIMA 2017 N(106, 3.8) 106.
#> 6 Japan ARIMA 2018 N(106, 7.6) 106.
#> 7 USA ARIMA 2017 N(109, 11) 109.
#> 8 USA ARIMA 2018 N(110, 29) 110.
fbl <- as_fable(fc_tsibble, response = "Debt", distribution = "Debt")
fbl
#> # A fable: 8 x 5 [1Y]
#> # Key: Country, .model [4]
#> Country .model Year Debt .mean
#> <chr> <chr> <dbl> <dist> <dbl>
#> 1 Australia ARIMA 2017 N(215, 21) 215.
#> 2 Australia ARIMA 2018 N(221, 63) 221.
#> 3 Canada ARIMA 2017 N(188, 7) 188.
#> 4 Canada ARIMA 2018 N(192, 21) 192.
#> 5 Japan ARIMA 2017 N(106, 3.8) 106.
#> 6 Japan ARIMA 2018 N(106, 7.6) 106.
#> 7 USA ARIMA 2017 N(109, 11) 109.
#> 8 USA ARIMA 2018 N(110, 29) 110.
由reprex 包(v0.3.0)于 2020 年 9 月 28 日创建
如果您不引用分布变量,它也可以工作。
as_fable(fc_tsibble, response = "Debt", distribution = Debt)
#> # A fable: 8 x 5 [1Y]
#> # Key: Country, .model [4]
#> Country .model Year Debt .mean
#> <chr> <chr> <dbl> <dist> <dbl>
#> 1 Australia ARIMA 2017 N(215, 21) 215.
#> 2 Australia ARIMA 2018 N(221, 63) 221.
#> 3 Canada ARIMA 2017 N(188, 7) 188.
#> 4 Canada ARIMA 2018 N(192, 21) 192.
#> 5 Japan ARIMA 2017 N(106, 3.8) 106.
#> 6 Japan ARIMA 2018 N(106, 7.6) 106.
#> 7 USA ARIMA 2017 N(109, 11) 109.
#> 8 USA ARIMA 2018 N(110, 29) 110.
请注意,在文档中它指定response
参数应该是字符向量:
response
响应变量的特征向量。
但是,如果你这样做,你仍然会得到一个错误:
as_fable(fc_tsibble, response = ".mean", distribution = Debt)
#> Error: `fbl[[chr_dist]]` must be a vector with type <distribution>.
#> Instead, it has type <distribution>.
该错误消息也是不直观且有些矛盾的。这是我了解到您实际上想要将分布列传递给两个参数的地方:
as_fable(fc_tsibble, response = "Debt", distribution = Debt)
#> # A fable: 8 x 5 [1Y]
#> # Key: Country, .model [4]
#> Country .model Year Debt .mean
#> <chr> <chr> <dbl> <dist> <dbl>
#> 1 Australia ARIMA 2017 N(215, 21) 215.
#> 2 Australia ARIMA 2018 N(221, 63) 221.
#> 3 Canada ARIMA 2017 N(188, 7) 188.
#> 4 Canada ARIMA 2018 N(192, 21) 192.
#> 5 Japan ARIMA 2017 N(106, 3.8) 106.
#> 6 Japan ARIMA 2018 N(106, 7.6) 106.
#> 7 USA ARIMA 2017 N(109, 11) 109.
#> 8 USA ARIMA 2018 N(110, 29) 110.
as_fable(fc_tsibble, response = "Debt", distribution = "Debt")
#> # A fable: 8 x 5 [1Y]
#> # Key: Country, .model [4]
#> Country .model Year Debt .mean
#> <chr> <chr> <dbl> <dist> <dbl>
#> 1 Australia ARIMA 2017 N(215, 21) 215.
#> 2 Australia ARIMA 2018 N(221, 63) 221.
#> 3 Canada ARIMA 2017 N(188, 7) 188.
#> 4 Canada ARIMA 2018 N(192, 21) 192.
#> 5 Japan ARIMA 2017 N(106, 3.8) 106.
#> 6 Japan ARIMA 2018 N(106, 7.6) 106.
#> 7 USA ARIMA 2017 N(109, 11) 109.
#> 8 USA ARIMA 2018 N(110, 29) 110.