Stroring and extracting AICs from an ARIMA model using a nested loop

Hello
I am trying to extract AICs from an ARIMA estimation with different
combinations of p & q ( p =0,1,2,3
and q=0,1.2,3). I have tried using the following code unsucessfully. Can
anyone help?

code:

storage1 <- numeric(16)
for (p in 0:3){

    for (q in 0:3){
 
    storage1[p]  <- arima(x,order=c(p,0,q), method="ML")}
}
storage1$aic

A functional approach, using tidyverse purrr package

x<- datasets::lh

permuted_inputs <- purrr::cross2(0:3,0:3)

my_results <- purrr::map(.x=permuted_inputs,
            .f= ~ arima(x,
                        order=c(.x[[1]],0,.x[[2]]),
                        method="ML")
            )

purrr::walk2(.x = my_results,
             .y = permuted_inputs,
             .f =  ~cat(
               "p: ",.y[[1]], " , " ,
               "q: ",.y[[2]], " , " ,
              "aic:",.x$aic,"\n"))
1 Like

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