【问题标题】:handle errors with try on fable通过尝试寓言处理错误
【发布时间】:2019-10-09 12:05:06
【问题描述】:

这段代码可以正常工作

require(fable)   
it <-  tsibbledata::global_economy %>%
    filter(Country == "Italy")
fm0 <-  model(.data = it, 
    ARIMA(log(GDP) ~ Population), 
    ETS(log(GDP)))

下一个预计不会工作

fm1 <-  model(.data = it, 
    ARIMA(log(GDP) ~ Population + pdq(3,1,7) +PDQ(5,1,1)),
    ETS(log(GDP)))

显然,由于 ARIMA 模型,它不起作用。 ETS 运行良好

我能做到:

fm2 <-  try(
    model(.data = it, 
    ARIMA(log(GDP) ~ Population + pdq(3,1,7) +PDQ(5,1,1)), 
    ETS(log(GDP))))

但这会使两个模型都失败

我想要类似的东西

fm3 <-  try(
    model(.data = it, 
    try(ARIMA(log(GDP) ~ Population + pdq(3,1,7) +PDQ(5,1,1))), 
    ETS(log(GDP))))

这样 fm3 包含 ETS 的正确结果和 ARIMA 的“try-error”类对象

可能修改 fablelite:::estimate 以便它可以处理错误可能是一种解决方案?

任何帮助将不胜感激

【问题讨论】:

    标签: r fable-r


    【解决方案1】:

    很好的建议,这是我们已经考虑了一段时间的功能 (https://github.com/tidyverts/fable/issues/74)。

    我在model() 参数中添加了一个.safely 参数,它将返回格式化警告并返回null_model() 而不是错误(https://github.com/tidyverts/fablelite/commit/1c7dccd7e48211125cf566bcce9ba8c9fc4e47ce)。

    null_model() 是一个没有估计的模型,所有模型方法(forecast()accuracy() 等)都会给出适当结构化的 NA 值。

    我已将.safely=TRUE 设置为默认值,所以上面的代码现在给出:

    library(fable)
    library(tidyverse)
    it <-  tsibbledata::global_economy %>%
      filter(Country == "Italy")
    fm1 <-  model(.data = it, 
                  ARIMA(log(GDP) ~ Population + pdq(3,1,7) +PDQ(5,1,1)),
                  ETS(log(GDP)))
    #> Warning: 1 error encountered for ARIMA(log(GDP) ~ Population + pdq(3, 1, 7) + PDQ(5, 1, 1))
    #> [1] There are no ARIMA models to choose from after imposing the `order_constraint`, please consider allowing more models.
    fm1
    #> # A mable: 1 x 3
    #> # Key:     Country [1]
    #>   Country `ARIMA(log(GDP) ~ Population + pdq(3, 1, 7) + PD… `ETS(log(GDP))`
    #>   <fct>   <model>                                           <model>        
    #> 1 Italy   <NULL model>                                      <ETS(M,Ad,N)>
    

    reprex package (v0.2.1) 于 2019 年 5 月 30 日创建

    【讨论】:

      猜你喜欢
      • 2022-01-15
      • 1970-01-01
      • 1970-01-01
      • 2020-07-19
      • 2016-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多