astsa (version 1.12)

sarima.sim: ARIMA Simulation

Description

Simulate data from (seasonal) ARIMA models.

Usage

sarima.sim(ar = NULL, d = 0, ma = NULL, sar = NULL, D = 0, sma = NULL, S = NULL, 
            n = 500, rand.gen = rnorm,  burnin = NA, ...)

Arguments

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 NA (the default) a reasonable value is selected.

additional arguments applied to the innovations. For rand.gen, the standard deviation of the innovations generated by rnorm can be specified by sd or the mean by mean (see details and examples). In addition, rand.gen may be overridden using a preset sequence of innovations specifying innov (see details and examples).

Value

a time series of length n from the specified SARIMA model with the specified frequency if the model is seasonal

Details

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.

References

https://www.stat.pitt.edu/stoffer/tsa4/ and https://www.stat.pitt.edu/stoffer/tsda/

Examples

Run this code
# NOT RUN {
## 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))
# }

Run the code above in your browser using DataLab