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:
-
Set counter to
cnt <- 0
-
Run
x <- arima.sim(n=60, model = list(ar=0.6, order = c(1, 0, 0)), sd = 1)
-
Test if the order of
x
is (1, 0, 0) -
If x order is (1, 0, 0) stop and make
cnt + 1
; if otherwise makecnt + 1
and return to step 2. -
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