简体   繁体   English

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

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

(Using Orange dataset from library(Ecdat) for reproducibility.) (使用library(Ecdat)橙色数据集进行再现。)

I am trying to fit a mean forecasting model in R using tsibble, fable package in R. The code below is pretty simple, however I get the error Error in NCOL(x) : object 'value' not found when I try to run the last model part (even though value is a column name in o_ts ), not sure why would that be.我正在尝试使用 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的列名),不知道为什么会这样。 I am following RJH tutorials from here ( https://robjhyndman.com/hyndsight/fable/ ).我正在关注这里的 RJH 教程( https://robjhyndman.com/hyndsight/fable/ )。

I would also appreciate any help whether arima & mean forecasting model are same, if not what is the function that I should be using instead of Arima.如果 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 is from the stats package. arima来自stats包。 I believe you want ARIMA from fable .我相信你想要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]>

If you by mean forecasting model are referring to taking the mean of the last X observation (Moving Average), then you should be using MEAN .如果您的平均预测模型是指取最后一个 X 观测值(移动平均)的平均值,那么您应该使用MEAN
While ARIMA does refer to Moving Average (Auto Regressive Integrated Moving Average), however this refers to a weighted moving average of the forecast errors - you can read more here: 9.4 Moving average models in Forecasting: Principles and Practice虽然ARIMA确实指的是移动平均线(自动回归综合移动平均线),但这指的是预测误差的加权移动平均线 - 您可以在此处阅读更多信息: 9.4 预测中的移动平均线模型:原则和实践

o <- Orange 

o_ts <- o %>% as_tsibble()

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

If you want to specify the amount of observations to take the mean of, then you need to add the special ~window(size = X) .如果要指定要取平均值的观测值数量,则需要添加特殊的~window(size = X) Otherwise all observations are used.否则将使用所有观察值。

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