sim_sarima: Simulate trajectories of seasonal arima models

View source: R/sarima.R

sim_sarimaR Documentation

Simulate trajectories of seasonal arima models

Description

Simulate trajectories of seasonal arima models.

Usage

sim_sarima(model, n = NA, rand.gen = rnorm, n.start = NA, x, eps,
           xcenter = NULL, xintercept = NULL, ...)

Arguments

model

specification of the model, a list or a model object, see ‘Details’.

rand.gen

random number generator for the innovations.

n

length of the time series.

n.start

number of burn-in observations.

x

initial/before values of the time series, a list, a numeric vector or time series, see Details.

eps

initial/before values of the innovations, a list or a numeric vector, see Details.

xintercept

non-constant intercept which may represent trend or covariate effects.

xcenter

currently ignored.

...

additional arguments for arima.sim and rand.gen, see ‘Details’.

Details

The model can be specified by a model object, e.g., from class SarimaModel. It can also be a list with elements suitable to be passed to new("SarimaModel", ...), see the description of class "SarimaModel". Here are some of the possible components:

nseasons

number of seasons in a year (or whatever is the larger time unit)

iorder

order of differencing, specifies the factor (1-B)^{d1} for the model.

siorder

order of seasonal differencing, specifies the factor (1-B^{period})^{ds} for the model.

ar

ar parameters (non-seasonal)

ma

ma parameters (non-seasonal)

sar

seasonal ar parameters

sma

seasonal ma parameters

Additional arguments for rand.gen may be specified via the "..." argument. In particular, the length of the generated series is specified with argument n. Arguments for rand.gen can also be passed via the "..." argument.

If the model is stationary the generated time series is stationary starting with the first value. In particular, there is no need for a ‘warm-up’ period.

Information about the model is printed on the screen if info = "print". To suppress this, set info to any other value.

For multple simulations with the same (or almost the same) setup, it is better to execute prepareSimSarima once and call the function returned by it as many times as needed.

Value

an object of class "ts", a simulated time series from the given model

Author(s)

Georgi N. Boshnakov

Examples

require("PolynomF") # guaranteed to be available since package "sarima" imports it.

x <- sim_sarima(n=144, model = list(ma=0.8))               # MA(1)
x <- sim_sarima(n=144, model = list(ar=0.8))               # AR(1)

x <- sim_sarima(n=144, model = list(ar=c(rep(0,11),0.8)))  # SAR(1), 12  seasons
x <- sim_sarima(n=144, model = list(ma=c(rep(0,11),0.8)))  # SMA(1)

                                  # more enlightened SAR(1) and SMA(1)
x <- sim_sarima(n=144,model=list(sar=0.8, nseasons=12, sigma2 = 1))  # SAR(1), 12 seasons
x <- sim_sarima(n=144,model=list(sma=0.8, nseasons=12, sigma2 = 1))  # SMA(1)

x <- sim_sarima(n=144, model = list(iorder=1, sigma2 = 1)) # (1-B)X_t = e_t (random walk)
acf(x)
acf(diff(x))

x <- sim_sarima(n=144, model = list(iorder=2, sigma2 = 1))  # (1-B)^2 X_t = e_t
x <- sim_sarima(n=144, model = list(siorder=1,
                                    nseasons=12, sigma2 = 1)) # (1-B)^{12} X_t = e_t

x <- sim_sarima(n=144, model = list(iorder=1, siorder=1,
                                    nseasons=12, sigma2 = 1))
x <- sim_sarima(n=144, model = list(ma=0.4, iorder=1, siorder=1,
                                    nseasons=12, sigma2 = 1))
x <- sim_sarima(n=144, model = list(ma=0.4, sma=0.7, iorder=1, siorder=1,
                                    nseasons=12, sigma2 = 1))

x <- sim_sarima(n=144, model = list(ar=c(1.2,-0.8), ma=0.4,
                                    sar=0.3, sma=0.7, iorder=1, siorder=1,
                                    nseasons=12, sigma2 = 1))

x <- sim_sarima(n=144, model = list(iorder=1, siorder=1,
                                    nseasons=12, sigma2 = 1),
                x = list(init=AirPassengers[1:13]))

p <- polynom(c(1,-1.2,0.8))
solve(p)
abs(solve(p))

sim_sarima(n=144, model = list(ar=c(1.2,-0.8), ma=0.4, sar=0.3, sma=0.7,
                               iorder=1, siorder=1, nseasons=12))

x <- sim_sarima(n=144, model=list(ma=0.4, iorder=1, siorder=1, nseasons=12))
acf(x, lag.max=48)
x <- sim_sarima(n=144, model=list(sma=0.4, iorder=1, siorder=1, nseasons=12))
acf(x, lag.max=48)
x <- sim_sarima(n=144, model=list(sma=0.4, iorder=0, siorder=0, nseasons=12))
acf(x, lag.max=48)
x <- sim_sarima(n=144, model=list(sar=0.4, iorder=0, siorder=0, nseasons=12))
acf(x, lag.max=48)
x <- sim_sarima(n=144, model=list(sar=-0.4, iorder=0, siorder=0, nseasons=12))
acf(x, lag.max=48)

x <- sim_sarima(n=144, model=list(ar=c(1.2, -0.8), ma=0.4, sar=0.3, sma=0.7,
                                  iorder=1, siorder=1, nseasons=12))
## use xintercept to include arbitrary trend/covariates
sim_sarima(n = 144, model = list(sma = 0.4, ma = 0.4, sar = 0.8, ar = 0.5, 
    nseasons = 12, sigma2 = 1), xintercept = 1:144)

GeoBosh/sarima documentation built on March 27, 2024, 6:31 p.m.