We want to use R base function arima.sim
for this task, and no extra libraries are required.
By default, arima.sim
generates ARIMA with innovations ~ N(0,1)
. If we want to change this, we need to control the rand.gen
or innov
argument. For example, you want innovations from uniform distributions U[-0.5, 0.5]
, we can do either of the following:
arima.sim(model=list(ar=.75), n=100, rand.gen = runif, min = -0.5, max = 0.5)
arima.sim(model=list(ar=.75), n = 100, innov = runif(100, -0.5, 0.5))
Example
set.seed(0)
y <- arima.sim(model=list(ar=.75), n = 100, innov = runif(100, -0.5, 0.5))
ts.plot(y)
In case we want to have explicit control on y[0]
, we can just shift the above time series such that it starts from y[0]
. Suppose y0
is our desired starting value, we can do
y <- y - y[1] + y0
For example, starting from y0 = 1
:
y <- y - y[1] + 1
ts.plot(y)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…