R 计算多少次`auto.arima()` 确认`arima.sim()` 为真 [英] R Count How Many Time `auto.arima()` Confirm`arima.sim()` to be True

查看:29
本文介绍了R 计算多少次`auto.arima()` 确认`arima.sim()` 为真的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常使用arima.sim()函数来模拟ARIMA模型,然后通过auto.arima()函数发现模拟的 ARIMA 模型与我在 arima.sim() 函数中指定的不同.

Often times I make use of arima.sim() function to simulate ARIMA model and later discover through auto.arima() function that the ARIMA model simulated is not the same with what I specified in arima.sim() function.

我进一步研究了 arima.sim() 如何通过模拟相同的 ARIMA 模型来模拟 ARIMA 模型相同的 arima.sim() 详细说明了很多次,然后使用 auto.arima() 此处.

I went further to investigate to know how does the arima.sim() fair in simulating ARIMA model by simulating same ARIMA model with the same arima.sim() detail good number of times and then check each out with auto.arima() here.

result <- matrix(NA_integer_, nrow = 10, ncol = 3)
colnames(result) <- c("p","d","q")
num<-60
set.seed(1234)
for(i in 1:10){
   result[i, ] <- arima.sim(n = num, model=list(ar=0.8, order = c(1, 0, 0))) %>%
     auto.arima() %>%
     arimaorder()
}
result
#p  d   q
#1  0   1
#1  0   0
#1  0   0
#1  0   0
#2  0   1
#1  0   0
#1  0   0
#1  0   0
#1  0   0
#4  0   3

我如何放置一个 R 代码来计算有多少次 ARIMA(1, 0, 0) 在我运行时出现

How do I put up an R code that will count how many times ARIMA(1, 0, 0) comes up when I run

num<-60
for(i in 1:10){
   ar1 <- arima.sim(n = num, model=list(ar=0.8, order = c(1, 0, 0)))
     auto.arima(ar1)
}

在一个循环

推荐答案

如果我们需要在for循环中获取count

If we need to get the count within the for loop

cnt <- 0
for(i in 1:10) { 
   ar1 <- arima.sim(n = num, 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
#[1] 3


或者如果是基于'result',那么就和vector做一个比较,得到rowSums,并检查我们在一行中是否有3个TRUE,以及sum


Or if it is based on the 'result', then do a comparison with the vector, get the rowSums, and check if we have 3 TRUE in a single row, and sum

sum(rowSums(result == c(1, 0, 0)[col(result)]) == 3)

这篇关于R 计算多少次`auto.arima()` 确认`arima.sim()` 为真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆