I am trying to fit some time series using the R packages tsibble
and fable
, the still-under-construction replacement for the redoubtable Rob Hyndman's forecast
package. The series are all combined into one tsibble, which I then fit with ARIMA, a function which replaces, among other things, forecast::auto.arima
.
I use map_at
, first to iterate over all the elements except the Date
, and then again to extract the model information from the models that have been fit to each series using fablelite::components
. (A lot of the fable
functions are really in fablelite
).
This fails, apparently because components expects an object of class mdl_df
and my model objects have class mdl_defn
Here is a toy example that (almost) reproduces the error:
library(tidyverse)
library(tsibble)
library(fable)
set.seed(1)
ar1 <- arima.sim(model=list(ar=.6), n=10)
ma1 <- arima.sim(model=list(ma=0.4), n=10)
Date <- c(ymd("2019-01-01"):ymd("2019-01-10"), ymd("2019-01-01"):ymd("2019-01-10"))
tb <- tibble(Date, ar1, ma1)
# Fit the whole series
tb_all <- tb %>%
map_at(.at = c("ar1", "ma1"), .f = ARIMA)
names(arima_all[2:3])<- c("ar1", "ma1")
# Extract model components
tb_components <- tb %>%
map_at(.at = c("ar1", "ma1"),
.f = fablelite::components)
Note that in this toy, like my real data, time is in 5-day weeks with missing weekends
In this toy example, the the error message says the components function rejects list elements on grounds there is no method for class ts
. In my real case, which uses longer series and more of them, but is to my eye otherwise identical, elements are rejected because they are of class mdl_defn
. Note that if I examine the 2nd and third elements of tb_all
with str( )
, they also display as of Classes 'mdl_defn'
, 'R6'
Not sure where the ts
in the error message comes from.
! I suspect that you have answered this question, but am still not entirely sure which of these outputs tells me what I want to know, which is the order of the fitted model plus the coefficients for each equation. That seems closest to the tb_all output plus the "tidy" results. But under tidy I am expecting two sets of coefficients and seeing three. Is it that the orders tell me that I should expect two coefficients for the ar model and only 1 for the ma model?– andrewH Jul 26 '19 at 05:07