mercredi 26 août 2020

Count How Many Times to Run ARIMA(1, 0, 0) Until ARIMA(1, 0, 0) is Truly Obtained

I oftentimes run arima.sim() only to check through auto.arima() that the order I simulated for was not obtained.

I want to write a function to count how many times an arima.sim() is run before the simulated order is confirmed through auto.arima() function.

The algorithm of the function will be as follows:

  1. Set counter to cnt <- 0

  2. Run x <- arima.sim(n=60, model = list(ar=0.6, order = c(1, 0, 0)), sd = 1)

  3. Test if the order of x is (1, 0, 0)

  4. If x order is (1, 0, 0) stop and make cnt + 1; if otherwise make cnt + 1 and return to step 2.

  5. Print cnt

Here is my attempt

library(forecast)
y <- c()
x <- arimaorder(auto.arima(arima.sim(n=60, model = list(ar=0.6, order = c(1, 0, 0)), sd = 1)))
cnt <- 0
while (x == c(1, 0, 0)) 
{
  y<-if(all(x[!x %in% y])) # My mistake could be here
    cnt<-cnt + 1
}
cnt

Aucun commentaire:

Enregistrer un commentaire