0

N00B question, but what is a more efficient way of doing this? I'm just trying to calculate test statistics for all 36 permutations of parameters in the model.

ARIMAP0Q<-c(BIC(arima(italy.1$gap,order=c(0,0,0))),
            BIC(arima(italy.1$gap,order=c(1,0,0))),
            BIC(arima(italy.1$gap,order=c(2,0,0))),
            BIC(arima(italy.1$gap,order=c(3,0,0))),
            BIC(arima(italy.1$gap,order=c(4,0,0))),
            BIC(arima(italy.1$gap,order=c(5,0,0))),
            BIC(arima(italy.1$gap,order=c(0,0,1))),
            BIC(arima(italy.1$gap,order=c(1,0,1))),
            BIC(arima(italy.1$gap,order=c(2,0,1))),

it feel really stupid doing it like this

slap-a-da-bias
  • 376
  • 1
  • 6
  • 25

1 Answers1

1

Use expand.grid to get all the possible orders.

Then use apply to your heart's content.

ARIMAP0Q <- apply(expand.grid(0:5, 0:2, 0:3), 1L,
                  function(rw) BIC(arima(italy.1$gap, order = rw)))
MichaelChirico
  • 33,841
  • 14
  • 113
  • 198
  • @slap-a-da-bias have `sapply` / `lapply` / `apply` in mind any time you are doing something repetitive and you'll rarely go wrong. – MichaelChirico Feb 25 '16 at 04:02
  • also definitely peruse this excellent Q&A: http://stackoverflow.com/questions/3505701/r-grouping-functions-sapply-vs-lapply-vs-apply-vs-tapply-vs-by-vs-aggrega – MichaelChirico Feb 25 '16 at 04:03