-1

I once got answer to a question on how to count how many times 'auto.arima()' function truly confirm the order in 'arima.sim()' function if 'arima.sim()' functions is run 10 times as R Count How Many Time `auto.arima()` Confirm`arima.sim()` to be True

cnt <- 0
for(i in 1:10) { 
   ar1 <- arima.sim(n = 80, model=list(ar=0.8, order = c(1, 0, 0)))
   ar2 <- auto.arima(ar1)
   if(all(arimaorder(ar2) == c(1, 0, 0))) cnt <- cnt + 1}
cnt

How do I count how many times to run arima.sim(n = 80, model=list(ar=0.8, order = c(1, 0, 0))) function in a loop to know how many times the order will not be (1, 0, 0)' until it get order '(1, 0, 0)?

Daniel James
  • 1,381
  • 1
  • 10
  • 28
  • 1
    please don't post the same question again and again https://stackoverflow.com/questions/63606691/how-many-times-do-arima-sim-produces-wrong-order-before-its-first-correct-orde , https://stackoverflow.com/questions/63552562/how-to-use-if-and-else-condition-in-repeat-function-in-r-for-different-combo-of You can raise a bounty on your original question if you want more people to look at your question. – Ronak Shah Aug 27 '20 at 05:39

1 Answers1

1

You can use while loop and count the loop if it's not the order, stop if it is

count <-0
while(TRUE){
    ar1 <- arima.sim(n = 80, model=list(ar=0.8, order = c(1, 0, 0)))
    ar2 <- auto.arima(ar1)
    if(all(arimaorder(ar2)==c(1,0,0))) break
    count <- count + 1
}
count