簡體   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