繁体   English   中英

使用 R 中的 tsibble、fable 拟合均值预测模型

[英]Fit a Mean forecasting model using tsibble, fable in R

(使用library(Ecdat)橙色数据集进行再现。)

我正在尝试使用 R 中的 tsibble、fable 包在 R 中拟合平均预测模型。 下面的代码非常简单,但是我收到Error in NCOL(x) : object 'value' not found的错误Error in NCOL(x) : object 'value' not found当我尝试运行时Error in NCOL(x) : object 'value' not found最后一个模型部分(即使valueo_ts的列名),不知道为什么会这样。 我正在关注这里的 RJH 教程( https://robjhyndman.com/hyndsight/fable/ )。

如果 arima 和均值预测模型是否相同,我也将不胜感激,如果不是,我应该使用什么函数来代替 Arima。

library(Ecdat)
library(tsibble)
library(feasts)
library(tidyverse)
library(fable)

o<- Orange 

o_ts <- o %>% as_tsibble()

o_ts %>%
  filter(key=="priceoj") %>% 
  model(
    arima=arima(value))

arima来自stats包。 我相信你想要fable ARIMA

o_ts %>%
  filter(key == "priceoj") %>% 
  model(
    arima = ARIMA(value)
  )
#> # A mable: 1 x 2
#> # Key:     key [1]
#>   key                         arima
#>   <chr>                     <model>
#> 1 priceoj <ARIMA(1,1,0)(0,0,1)[12]>

如果您的平均预测模型是指取最后一个 X 观测值(移动平均)的平均值,那么您应该使用MEAN
虽然ARIMA确实指的是移动平均线(自动回归综合移动平均线),但这指的是预测误差的加权移动平均线 - 您可以在此处阅读更多信息: 9.4 预测中的移动平均线模型:原则和实践

o <- Orange 

o_ts <- o %>% as_tsibble()

o_ts %>%
  filter(key == "priceoj") %>% 
  model(mean = MEAN(value))

如果要指定要取平均值的观测值数量,则需要添加特殊的~window(size = X) 否则将使用所有观察值。

o_ts %>%
  filter(key == "priceoj") %>% 
  model(mean = MEAN(value ~ window(size = 3)))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM