2

(Using Orange dataset from library(Ecdat) for reproducibility.)

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. I am following RJH tutorials from here (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.

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))
Vaibhav Singh
  • 1,159
  • 1
  • 10
  • 25

2 Answers2

1

arima is from the stats package. I believe you want ARIMA from fable.

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]>
Paul
  • 8,734
  • 1
  • 26
  • 36
  • Thanks thats correct, can you also confirm if its same as mean forecasting which is what I am confused with – Vaibhav Singh Oct 21 '20 at 09:10
  • Also, any idea why do I get a null model ? – Vaibhav Singh Oct 21 '20 at 11:06
  • I'm not familiar with definition of `mean forecast model`. I'm not sure why you're getting a null model - I don't get a null model when I run it. Perhaps try restarting R and running again? – Paul Oct 21 '20 at 11:19
0

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.
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

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). Otherwise all observations are used.

o_ts %>%
  filter(key == "priceoj") %>% 
  model(mean = MEAN(value ~ window(size = 3)))
Martin Gal
  • 16,640
  • 5
  • 21
  • 39