【问题标题】:Forecasting in R: UseMethod model function errorR中的预测:UseMethod模型函数错误
【发布时间】:2021-12-09 01:45:19
【问题描述】:

我正在尝试在每月 tsibble 数据集上运行不同的预测建模方法。它的 head() 看起来像:

# A tsibble: 6 x 2 [1M]
     month total
     <mth> <dbl>
1 2000 Jan  104.
2 2000 Feb  618.
3 2000 Mar 1005.
4 2000 Apr  523.
5 2000 May 1908.
6 2000 Jun 1062.

结构如下:

tsibble [212 x 2] (S3: tbl_ts/tbl_df/tbl/data.frame)
 $ month: mth [1:212] 2000 Jan, 2000 Feb, 2000 Mar, 2000 Apr, 2000 May, 2000 Jun, 2000 Jul, 2000 Aug, 2000 Sep, 2000 Oct, 2000 Nov...
 $ total: num [1:212] 104 618 1005 523 1908 ...
 - attr(*, "key")= tibble [1 x 1] (S3: tbl_df/tbl/data.frame)
  ..$ .rows: list<int> [1:1] 
  .. ..$ : int [1:212] 1 2 3 4 5 6 7 8 9 10 ...
  .. ..@ ptype: int(0) 
 - attr(*, "index")= chr "month"
  ..- attr(*, "ordered")= logi TRUE
 - attr(*, "index2")= chr "month"
 - attr(*, "interval")= interval [1:1] 1M
  ..@ .regular: logi TRUE

数据集是从 2000/01 到 2017/08 的月度数据,没有缺失值或时间段。我正在尝试运行一个模型,例如:

df %>%
  model(STL(total ~ season(window=9),robust=T)) %>%
  components() %>% autoplot()

fit <- df %>%
  model(ANN =ETS(total ~ error("A") + trend("A") + season()))

但是对于我尝试运行的任何类型的模型,我每次都会得到完全相同的错误。我正在寻找更正 tsibble 结构以允许这些模型函数工作的建议。

Error in UseMethod("model") : 
  no applicable method for 'model' applied to an object of class "c('tbl_ts', 'tbl_df', 'tbl', 'data.frame')"

编辑:包括可重现的示例:

a = c(sample(1:1000,212))
df.ts <- ts(a, start=c(2000,1),end=c(2017,8),frequency=12)
df <- df.ts %>% as_tsibble()

【问题讨论】:

  • 请提供一个可重现的例子。
  • @RobHyndman 我已经用一个例子更新了这个问题。
  • 我无法重现该数据集的问题。
  • @RobHyndman 澄清一下,您在尝试诸如 fit &lt;- df %&gt;% model(trend_model = TSLM(value ~ trend())) 之类的模型时是否没有收到错误,或者您的意思是该示例仍然不足以继续进行?
  • 使用该代码生成的数据然后运行您的问题中的代码,我没有收到错误。

标签: r forecasting forecast


【解决方案1】:

感谢您的示例,我能够让它运行而没有任何错误,如下所示:

library(tidyverse)
library(fpp3)

a = c(sample(1:1000,212))
df.ts <- ts(a, start=c(2000,1),end=c(2017,8),frequency=12)
df <- df.ts %>% as_tsibble()

df %>%
  model(STL(a ~ season(window=9),robust=T)) %>%
  components() %>% autoplot()

fit <- df %>%
  model(ANN =ETS(a ~ error("A") + trend("A") + season()))
report(fit)

下面是分解的样子:

这是模型的报告:

【讨论】:

    【解决方案2】:

    Russ Conte 和 Rob Hyndman 都发现所使用的示例代码本质上没有任何问题。

    我认为两个软件包之间存在重叠问题,因为我的问题在删除并重新安装预测软件包后得到解决。

    【讨论】:

      猜你喜欢
      • 2015-08-16
      • 1970-01-01
      • 2019-05-24
      • 1970-01-01
      • 2015-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-08
      相关资源
      最近更新 更多