lundi 24 août 2020

Count how many trials are made before the first success

I have an R script that counts how many times an `arima.sim(n, model = list(ar=\phi order =c(1, 0, 0), sd = sd)) for different combos.

Note that: I set numbers of trials to 100 in the below R script.

library(forecast)
N <- c(10, 20)
SD <- c(1, 2) ^ 2
phi <- c(0.2, 0.4)

## generate all combos
all_combos <- expand.grid(N = N, SD = SD, phi = phi)

## create function
set.seed(123)
res2 <- by(all_combos, all_combos["N"], function(DF){
  res <- mapply(function(N, SD, phi){
    cnt <- 0
    for (i in 1:100) {
      if(all(arimaorder(auto.arima(arima.sim(n=N, model = list(ar=phi, order = c(1, 0, 0)), sd = SD), ic = "aicc")) == c(1, 0, 0))) cnt <- cnt + 1
    }
    cnt
  }, DF[["N"]], DF[["SD"]], DF[["phi"]])
  names(res) <- paste("SD", DF[["SD"]], "phi", DF[["phi"]], sep = "-")
  res
})
res2

What I want I want a script not to set numbers of trials but to try each combo and continue to try and count the number of failures until ARIMA(1, 0, 0) is obtained then stop the trial for all combos.

Aucun commentaire:

Enregistrer un commentaire