ARIMA Simulation
Simulate data from (seasonal) ARIMA models.
sarima.sim(ar = NULL, d = 0, ma = NULL, sar = NULL, D = 0, sma = NULL, S = NULL, n = 500, rand.gen = rnorm, burnin = NA, ...)
ar |
coefficients of AR component (does not have to be specified) |
d |
order of regular difference (does not have to be specified) |
ma |
coefficients of MA component (does not have to be specified) |
sar |
coefficients of SAR component (does not have to be specified) |
D |
order of seasonal difference (does not have to be specified) |
sma |
coefficients of SMA component (does not have to be specified) |
S |
seasonal period (does not have to be specified) |
n |
desired sample size (defaults to 500) |
rand.gen |
optional; a function to generate the innovations (defaults to normal) |
burnin |
length of burn-in (a non-negative integer). If |
... |
additional arguments applied to the innovations. For |
Will generate a time series of length n
from the specified SARIMA model using simplified input.
The use of the term mean
in ... refers to the generation of normal innovations. For example, sarima.sim(ar=.9, mean=5)
will generate data using N(5,1) or 5+N(0,1) innovations, so that the constant in the model is 5 and the mean of the AR model is 5/(1-.9) = 50. In sarima.sim(ma=.9, mean=5)
, however, the model mean is 5 (the constant). Also, a random walk with drift = .1 can be generated by sarima.sim(d=1, mean=.1, burnin=0)
, which is equivalent to cumsum(rnorm(500, mean=.1))
. Because anything specified in ... refers to the innovations, a simpler way to generate a non-zero mean is to add the value outside the call; see the examples.
If innov
is used to input the innovations and override rand.gen
, be sure that length(innov)
is at least n + burnin
noting that burnin = 0
is allowed (but not recommended). If the criterion is not met, the script will return less than the desired number of values and a warning will be given.
a time series of length n from the specified SARIMA model with the specified frequency if the model is seasonal
The script uses polyMul
to obtain the appropriate autoregressive and moving average polynomials from the specified model and feeds those into .zarima_sim
. The model autoregressive polynomial ('AR side' = AR x SAR) is checked for causality and the model moving average polynomial ('MA side' = MA x SMA) is checked invertibility. The script stops and reports an error at the first violation of causality or invertibility; i.e., it will not report multiple errors.
D.S. Stoffer
## AR(2) with mean 50 [n = 500 is default] y = sarima.sim(ar=c(1.5,-.75)) + 50 tsplot(y) ## ARIMA(0,1,1) with drift tsplot(sarima.sim(ma=-.8, d=1, mean=.1)) ## SAR(1) example from text Months = c("J","F","M","A","M","J","J","A","S","O","N","D") sAR = sarima.sim(sar=.9, S=12, n=36) tsplot(sAR, type='c') points(sAR, pch=Months, cex=1.1, font=4, col=1:4) ## SARIMA(0,1,1)x(0,1,1)_12 - B&J's favorite tsplot(sarima.sim(d=1, ma=-.4, D=1, sma=-.6, S=12, n=120)) ## infinite variance t-errors tsplot(sarima.sim(ar=.9, rand.gen=function(n, ...) rt(n, df=2) )) ## use your own innovations dog = rexp(150, rate=.5)*sign(runif(150,-1,1)) tsplot(sarima.sim(n=100, ar=.99, innov=dog, burnin=50))
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.