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

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

问题描述

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

我进一步研究了如何通过模拟相同的 ARIMA 模型来了解 arima.sim()在模拟 ARIMA 模型方面如何公平相同的 arima.sim()详细说明了很多次,然后使用 auto.arima() %auto.arima()%&%;%arimaorder()}结果#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)

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

循环

十(10)次

解决方案

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

  cnt<-0for(我在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}碳纳米管#[1] 3 


或者如果它基于结果",则与向量进行比较,获得 rowSums ,并检查单行中是否有3个TRUE,以及 sum

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

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.

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

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)
}

ten(10) times in a loop

解决方案

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


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()确认Arma.sim()为真的次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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