Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract AICs from an ARIMA using a nested loop

I am trying to extract AICs & BICs 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.

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
like image 417
Leadmoore Avatar asked Mar 29 '26 22:03

Leadmoore


1 Answers

One way is to use expand.grid() to get all combinations of p and q, and apply them to your arima model, i.e.

apply(expand.grid(p, q), 1, function(i) arima(d1$cnt, order = c(i[1], 0, i[2]), method = "ML")$aic)

#[1] 47222.43 38589.14 36935.33 36118.44 42569.73 35183.35 35141.13 35143.02 39448.38 35142.96 35142.58 35142.60
like image 122
Sotos Avatar answered Apr 02 '26 12:04

Sotos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!