0

这是对这个问题的扩展,基于 Hyndman 的在线教科书的代码。

我试图在澳大利亚国内旅游活动中添加一个外部回归器,但是当这种情况发生时,协调功能似乎存在问题。

rm(list=ls())
library(tidyverse)
library(fable)
library(lubridate)
library(feasts)
library(dplyr)
library(tsibble)

     tourism <- tsibble::tourism %>% mutate(State = recode(State,
                        `New South Wales` = "NSW",
                        `Northern Territory` = "NT",
                        `Queensland` = "QLD",
                        `South Australia` = "SA",
                        `Tasmania` = "TAS",
                        `Victoria` = "VIC",
                        `Western Australia` = "WA"))  

tourism_hts <- tourism %>%
  aggregate_key(State / Region, Trips = sum(Trips)) %>% 
  mutate(my_xreg = rnorm(nrow(.)))

fit <- tourism_hts %>%
  filter(year(Quarter) <= 2015) %>%
  model(base = ARIMA(Trips ~ my_xreg)) %>%
  reconcile(
    bu = bottom_up(base),
    mo = middle_out(base),
    ols = min_trace(base, method = "ols"),
    mint = min_trace(base, method = "mint_shrink"),
  )

tourism_hts_future <- new_data(tourism_hts,8) %>% mutate(my_xreg = mean(tourism_hts$my_xreg))
fc <- fit %>% forecast(new_data=tourism_hts_future)

这是返回的内容:

Error: Problem with `mutate()` input `mo`.
x number of items to replace is not a multiple of replacement length
i Input `mo` is `(function (object, ...) ...`.
Run `rlang::last_error()` to see where the error occurred.
In addition: Warning messages:
1: Problem with `mutate()` input `bu`.
i longer argument not a multiple of length of shorter
i Input `bu` is `(function (object, ...) ...`. 
2: In mapply(FUN = .f, ..., MoreArgs = MoreArgs, SIMPLIFY = SIMPLIFY) :
  longer argument not a multiple of length of shorter
3: Problem with `mutate()` input `bu`.
i number of items to replace is not a multiple of replacement length
i Input `bu` is `(function (object, ...) ...`. 
4: In fc[btm] <- NextMethod() :
  number of items to replace is not a multiple of replacement length
5: Problem with `mutate()` input `mo`.
i longer argument not a multiple of length of shorter
i Input `mo` is `(function (object, ...) ...`. 
6: In mapply(FUN = .f, ..., MoreArgs = MoreArgs, SIMPLIFY = SIMPLIFY) :
  longer argument not a multiple of length of shorter
4

0 回答 0