我想在 R 中将种子设置和自动化为向量而不是整数

I Want to set and Automate Seed as a Vector Instead of an Integer in R

使用 arima.sim() 函数模拟遵循特定 ARIMA 模型的时间序列数据需要进行大量此类试验:

library(forecast)
set.seed(1)
ar1 <- arima.sim(n = 10, model=list(ar=0.2, order = c(1, 0, 0)), sd = 1)
ar2 <- auto.arima(ar1, ic ="aicc")
ar2

需要更改种子整数,直到存档所需的结果。我现在想的不是手动更改种子整数并使用 auto.arima() 函数检查我应该使用这样的向量自动化种子:

library(forecast)
SEED <- c(1,2,3,4,5,6,7,8,9,10)
set.seed(SEED)
ar1 <- arima.sim(n = 10, model=list(ar=0.2, order = c(1, 0, 0)), sd = 1)
ar2 <- auto.arima(ar1, ic ="aicc")
arimaorder(ar2)

这样它将打印特定种子试验的 arimaorder(ar2) 函数的结果及其种子。有了它,我将能够看到给我想要的 arimaorder 的种子整数,并且会去寻找它,而不是在订单后手动尝试它。

我想这应该适合您的目的。您会为每个种子获得不同的 arima 订单。你可以访问,因为我将它保存在数据框中" arima_order_results

library(forecast)
SEED_vector <- c(1,2,3,4,5,6,7,8,9,10)
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")
  
  arima_order = arimaorder(ar2)
  arima_order = t(as.data.frame(arima_order))
  # Print the arima order.
  print(arima_order)
  # This line of code is just if yo uwant to store the results in a dataframe
  arima_order_results = rbind(arima_order_results,arima_order)
}
# See your results (you also printed them in console)
View(arima_order_results )