打印一组模拟 AR(1) 的系数以及 R 中的种子的优雅方法
Elegant Way to Print Coefficients of Set of Simulated AR(1) Along with there Seeds in R
我也得到了在 R and another solution to filter the true arimaorder
of the simulated data that follows ARIMA(1, 0, 0)
along with the seeds that produce them 中将种子自动化为向量而不是整数的解决方案。在产生指定 ARIMA
顺序的种子中,我想要 print
它们的 ar coefficients
连同那里的种子。
我试过这个:
SEED_vector <- c(14, 152, 165,528, 539, 1091, 1240, 1259, 1314, 1425, 1481, 1552)
arima_order_results = data.frame()
for (my_seed in SEED_vector){
set.seed(my_seed)
ar1 <- arima.sim(n = 10, model=list(ar=0.2, order = c(1, 0, 0)), sd = 1)
ar2 <- auto.arima(ar1, ic ="aicc")
arr <- ar2$coef
print(arr)
arima_order_results = rbind(arima_order_results,arr)
}
我得到这个作为输出:
#ar1 intercept
#-0.6920070 0.4209332
#ar1 intercept
#-0.7202459 -0.3036454
#ar1 intercept
#-0.8971835 -0.4130711
#ar1
#0.8749406
#ar1
#-0.7520381
#ar1 intercept
#-0.8363416 0.3014670
#ar1 intercept
#-0.7016283 0.4847039
#ar1 intercept
#-0.6667556 0.6719526
#ar1 intercept
#-0.6481393 -0.3125167
#ar1 intercept
#-0.6084819 -0.9350262
#ar1 intercept
#-0.8985071 0.4437974
#ar1 intercept
#-0.7552149 1.2879873
而不是 R
输出中的 ar1
我更喜欢产生系数
的种子数
试试这个方法:
library(forecast)
library(dplyr)
SEED_vector <- c(14, 152, 165,528, 539, 1091, 1240, 1259, 1314, 1425, 1481, 1552)
arima_order_results = data.frame()
for (my_seed in SEED_vector){
set.seed(my_seed)
ar1 <- arima.sim(n = 10, model=list(ar=0.2, order = c(1, 0, 0)), sd = 1)
ar2 <- auto.arima(ar1, ic ="aicc")
arr <- as.data.frame(t(ar2$coef))
arr <- cbind(data.frame(seed=my_seed),arr)
print(arr)
arima_order_results = bind_rows(arima_order_results,arr)
}
输出:
arima_order_results
seed ar1 intercept
1 14 -0.6920070 0.4209332
2 152 -0.7202459 -0.3036454
3 165 -0.8971835 -0.4130711
4 528 0.8749406 NA
5 539 -0.7520381 NA
6 1091 -0.8363416 0.3014670
7 1240 -0.7016283 0.4847039
8 1259 -0.6667556 0.6719526
9 1314 -0.6481393 -0.3125167
10 1425 -0.6084819 -0.9350262
11 1481 -0.8985071 0.4437974
12 1552 -0.7552149 1.2879873
我也得到了在 R arimaorder
of the simulated data that follows ARIMA(1, 0, 0)
along with the seeds that produce them ARIMA
顺序的种子中,我想要 print
它们的 ar coefficients
连同那里的种子。
我试过这个:
SEED_vector <- c(14, 152, 165,528, 539, 1091, 1240, 1259, 1314, 1425, 1481, 1552)
arima_order_results = data.frame()
for (my_seed in SEED_vector){
set.seed(my_seed)
ar1 <- arima.sim(n = 10, model=list(ar=0.2, order = c(1, 0, 0)), sd = 1)
ar2 <- auto.arima(ar1, ic ="aicc")
arr <- ar2$coef
print(arr)
arima_order_results = rbind(arima_order_results,arr)
}
我得到这个作为输出:
#ar1 intercept
#-0.6920070 0.4209332
#ar1 intercept
#-0.7202459 -0.3036454
#ar1 intercept
#-0.8971835 -0.4130711
#ar1
#0.8749406
#ar1
#-0.7520381
#ar1 intercept
#-0.8363416 0.3014670
#ar1 intercept
#-0.7016283 0.4847039
#ar1 intercept
#-0.6667556 0.6719526
#ar1 intercept
#-0.6481393 -0.3125167
#ar1 intercept
#-0.6084819 -0.9350262
#ar1 intercept
#-0.8985071 0.4437974
#ar1 intercept
#-0.7552149 1.2879873
而不是 R
输出中的 ar1
我更喜欢产生系数
试试这个方法:
library(forecast)
library(dplyr)
SEED_vector <- c(14, 152, 165,528, 539, 1091, 1240, 1259, 1314, 1425, 1481, 1552)
arima_order_results = data.frame()
for (my_seed in SEED_vector){
set.seed(my_seed)
ar1 <- arima.sim(n = 10, model=list(ar=0.2, order = c(1, 0, 0)), sd = 1)
ar2 <- auto.arima(ar1, ic ="aicc")
arr <- as.data.frame(t(ar2$coef))
arr <- cbind(data.frame(seed=my_seed),arr)
print(arr)
arima_order_results = bind_rows(arima_order_results,arr)
}
输出:
arima_order_results
seed ar1 intercept
1 14 -0.6920070 0.4209332
2 152 -0.7202459 -0.3036454
3 165 -0.8971835 -0.4130711
4 528 0.8749406 NA
5 539 -0.7520381 NA
6 1091 -0.8363416 0.3014670
7 1240 -0.7016283 0.4847039
8 1259 -0.6667556 0.6719526
9 1314 -0.6481393 -0.3125167
10 1425 -0.6084819 -0.9350262
11 1481 -0.8985071 0.4437974
12 1552 -0.7552149 1.2879873