模拟多个单元的时间序列数据,没有跨单元相关性

问题描述

我想模拟多个单元的时间序列数据,每个单元中包含 ar = 0.7。然而,在这些单元之间,我希望它们彼此不相关。任何人都知道如何实现这一目标?谢谢!

这是我目前尝试过的:

set.seed(842)
##This is time series for one unit
tsfunc2 <- function (size=20) {
  y <- arima.sim(list(order = c(1,0),ar = 0.7),n = size,sd=2) 
  data.frame(time=1:size,as.numeric(y))} 

#Use `Map` to create time series for multiple units
Map(function(x,y) {
  data.frame(id=x,tsfunc2(y))
},1:30,22)

#Extract time series data for just two units to later test their correlation
u <- Map(function(x,22) [[1]][,"as.numeric.y."]

t <- Map(function(x,22) [[2]][,"as.numeric.y."]

#These two units indeed seem to be correlated
cor(u,t)
[1] -0.5244

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)