Fitting ARIMAX Modells with rolling_origin rsample and furrr

Hallo,

I have been trying for a long time to write a function that take rsplit Objects as Parameters, fits
ARIMAX Modells and gives predictions.
I would like to use future_map then.
Unfortunately, I can not achieve that.

My code so far is

grim_1<- read_excel(path, sheet= "2019")
head(grim_1)
grim_1 <- as.data.table(grim_1)
lg_id <- rep("GRIM_1", 8761)
grim_1 <- cbind(grim_1, lg_id)
head(grim_1)
tail(grim_1)


#---as_tsibble
my_data_tsbl <- as_tsibble(grim_1, key = lg_id, index = Datum_ab)
my_data_tsbl
#---rolling_origin

roll_eem_sliding <-rsample::rolling_origin(data=my_data_tsbl, initial = 365, assess= 120, skip = 120, cumulative = FALSE)

holdout_results_1 <- function(splits, ...) {

  analysis_set <- analysis(splits)
  
  mod <- analysis_set%>% 
    fable::ARIMA(Summe ~ Temp_Ist +
                   pdq(6,0,7) + PDQ(0,1,1, period= "day") )
  
  # Get predictions on the other data 
  res <- broom::augment(mod, newdata = holdout)
  res
}


ex<-holdout_results_1(roll_eem_sliding$splits[[1]])
#Error in match.arg(ic) : 'arg' must be NULL or a character vector

mod_form_1 <- as.formula(Summe ~ Temp_Ist + pdq(6,0,7) + PDQ(0,1,1, period= "day"))

ff_rolling_flex <- function(split, formula) {

  split_for_data <- analysis(split)

  ff_model <-split_for_data%>% 
    as_tsibble() %>%
    fable::ARIMA(formula)

  holdout <- assessment(split)

  out <- broom::augment(ff_model, newdata = holdout)%>%
    # calculate residuals for future use
    mutate(.resid = Summe - .fitted)
  
  # Return the test data set with the additional columns
  out
}

ff_rolling_flex(roll_eem_sliding$splits[[1]], mod_form_1) 
#Error in match.arg(ic) : 'arg' must be NULL or a character vector

I would like to kindl ask for help.

Best regards,

Kateryna

Hi @Shylina,
Welcome to the RStudio Community Forum.

It is hard for us to test your code without the matching data. Can you post at least a subset of the data for testing? Use, for example:

dput(head(grim_1, n=50))

Then paste that code into a reply.
HTH

Hi DavoWW,

my MWE is


library(tidyverse)
library(tsibble)
library(lubridate)
library(fable)
library(dplyr)
library(magrittr)
library(readxl)
library(data.table)
library(rsample)


grim_1<-data.frame(
          Datum_ab = seq(from=as.POSIXct("2000-01-01 00:00"),to= as.POSIXct("2000-12-31 00:00"), by = "hour"),
          Temp_Ist=rnorm(n = 8761, mean = 15, sd = 5),
           Summe = rnorm(n = 8761, mean = 200, sd = 10) )


lg_id <- rep("GRIM_1", 8761)
grim_1 <- cbind(grim_1, lg_id)
my_data_tsbl <- as_tsibble(grim_1, key = lg_id, index = Datum_ab)


roll_eem_sliding <-rsample::rolling_origin(data=my_data_tsbl, initial = 365, assess= 120, skip = 120, cumulative = FALSE)
mod_form_1 <- as.formula(Summe ~ Temp_Ist + pdq(6,0,7) + PDQ(0,1,1, period= "day"))


ff_rolling_flex <- function(split, formula) {
  
  split_for_data <- analysis(split)
  
  ff_model <-split_for_data%>% 
    as_tsibble() %>%
    fable::ARIMA(formula)
  
  holdout <- assessment(split)
  
  out <- broom::augment(ff_model, newdata = holdout)%>%
    # calculate residuals for future use
    mutate(.resid = Summe - .fitted)
  
  # Return the test data set with the additional columns
  out
}

ff_rolling_flex(roll_eem_sliding$splits[[1]], mod_form_1)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.