future::plan(future::multisession)
n_cores <- parallel::detectCores()
cl <- parallel::makeCluster(n_cores)
doParallel::registerDoParallel(cores = n_cores)
auto_ar1 <- function(i, n, ar){
set.seed(i)
ar1 <- arima.sim(n, model = list(ar, order = c(1, 0, 0)), sd = 1)
ar2 <- auto.arima(ar1, ic = "aicc")
(cf <- ar2$coef)
if (length(cf) == 0) {
rep(NA, 2)
}
else if (all(grepl(c("ar1|intercept"), names(cf))) &
substr(cf["ar1"], 1, 4) %in% "0.80") {
c(cf, seed = I)
}
else {
rep(NA, 2)
}
foreach::foreach(i, .packages = c('foreach', 'forecast')) %dopar% I
}
auto_ar1(i = 289800:289805, n=10, ar=0.8)
#Error in arima.sim(n, model = list(ar, order = c(1, 0, 0)), sd = 1) :
#inconsistent specification of 'ar' order