【发布时间】:2020-07-13 04:57:23
【问题描述】:
我想用变量模拟ARIMA(1,1,0):
- 样本大小
- phi 值
- 标准偏差值。
我很佩服下面的r 代码如何只模拟一个ARIMA(1,1,0),我想按照格式模拟许多具有不同样本大小、phi值ARIMA(1,1,0) /strong> 和 标准差值
wn <- rnorm(10, mean = 0, sd = 1)
ar <- wn[1:2]
for (i in 3:10){
ar<- arima.sim(n=10,model=list(ar=-0.7048,order=c(1,1,0)),start.innov=4.1,n.start=1,innov=wn)
}
我问了一个类似的问题here 并根据我的问题给出了一个很好的答案,但现在我看到arima.sim() 函数在模拟ARIMA 时间序列中是必不可少的,因此想将它纳入我的风格模拟ARIMA 时间序列。
我想出了这个试验,它使用 arima.sim() 函数来模拟 N=c(15, 20) ARIMA(1,1,0) 具有不同 样本大小、标准的时间序列偏差值和phi值,首先生成N个随机数,然后用最初的两个随机数作为前两个ARIMA(1,1,0). The 3rd to **n**th are the made to followARIMA(1,1 ,0)`。
这是我在下面尝试过的:
N <- c(15L, 20L)
SD = c(1, 2) ^ 2
phi = c(0.2, 0.4)
res <- vector('list', length(N))
names(res) <- paste('N', N, sep = '_')
set.seed(123L)
for (i in seq_along(N)){
res[[i]] <- vector('list', length(SD))
names(res[[i]]) <- paste('SD', SD, sep = '_')
ma <- matrix(NA_real_, nrow = N[i], ncol = length(phi))
for (j in seq_along(SD)){
wn <- rnorm(N[i], mean = 0, sd = SD[j])
ar[[1:2, ]] <- wn[[1:2]]
for (k in 3:N[i]){
ar[k, ] <- arima.sim(n=N[[i]],model=list(ar=phi[[k]],order=c(1,1,0)),start.innov=4.1,n.start=1,innov=wn)
}
colnames(ar) <- paste('ar_theta', phi, sep = '_')
res[[i]][[j]] <- ar
}
}
res1 <- lapply(res, function(dat) do.call(cbind, dat))
sapply(names(res1), function(nm) write.csv(res1[[nm]],
file = paste0(nm, ".csv"), row.names = FALSE, quote = FALSE))
最后两行将时间序列数据写入.csv并保存在我的工作目录中。
【问题讨论】:
-
我非常需要帮助
-
我还在等待帮助