x[[1]] 中的错误:下标越界

问题描述 投票:0回答:1

我正在研究书中第5.2章的示例:https://otexts.com/fpp3/simple-methods.html,在测试讲师正在使用的代码时出现错误:

  filter(!is.na(Bricks)) %>%
  model(
    Seasonal_naive = SNAIVE(Bricks),
    Naive = NAIVE(Bricks),
    Drift = RW(Bricks - drift()),
    Mean = MEAN(Bricks)
  ) ```

Here below is an extract of the error message from RStudio whenever I run the code:

> Error in x[[1]] : subscript out of bounds
rstudio forecasting
1个回答
0
投票

看起来像是一个拼写错误:

-
应该是
~
中的
RW(Bricks ~ drift())

library(fpp3)

bricks <- aus_production |>
  filter_index("1970 Q1" ~ "2004 Q4") |>
  select(Bricks)

bricks |> 
  filter(!is.na(Bricks)) |> 
  model(
    Seasonal_naive = SNAIVE(Bricks),
    Naive = NAIVE(Bricks),
    Drift = RW(Bricks ~ drift()),
    Mean = MEAN(Bricks)
  )
#> # A mable: 1 x 4
#>   Seasonal_naive   Naive         Drift    Mean
#>          <model> <model>       <model> <model>
#> 1       <SNAIVE> <NAIVE> <RW w/ drift>  <MEAN>

创建于 2024-04-13,使用 reprex v2.1.0

© www.soinside.com 2019 - 2024. All rights reserved.