R中是否有任何软件包/功能可以做到这一点?我已经找到了datagen.stsm,但是它没有使用季节性周期。
首先,我使用datagen.stsm创建本地趋势序列。 然后,将从datagen.stsm生成的序列添加六个随机周期的季节性分量。
m <- stsm.model(model = "local-trend", y = ts(seq(120), frequency = 12),
pars = pars, nopars = NULL)
ss <- char2numeric(m)
p <- datagen.stsm(n = 120, model = list(Z = ss$Z, T = ss$T, H = ss$H, Q = ss$Q),
n0 = 20, freq = 12, old.version = T)$data
pp <- as.vector(p)
for (i in 1:288){
ey[i] <- i + pp[i] + 20*sin(2*pi*i/12) + 20*cos(2*pi*i/12) + rnorm(1,0,0.05)
+ 20*sin(2*6*pi*i/12) + 20*cos(2*6*pi*i/12) + rnorm(1,0,0.05)
+ 20*sin(2*2*pi*i/12) + 20*cos(2*2*pi*i/12) + rnorm(1,0,0.05)
+ 20*sin(2*3*pi*i/12) + 20*cos(2*3*pi*i/12) + rnorm(1,0,0.05)
+ 20*sin(2*4*pi*i/12) + 20*cos(2*4*pi*i/12) + rnorm(1,0,0.05)
+ 20*sin(2*5*pi*i/12) + 20*cos(2*5*pi*i/12) + rnorm(1,0,0.05)
}
这是创建包含六个随机周期成分的时间序列数据的正确方法吗? 我随机选择20作为振幅。