sim_sarima: Simulate trajectories of seasonal arima models

Description Usage Arguments Details Value Author(s) Examples

View source: R/sarima.R

Description

Simulate trajectories of seasonal arima models.

Usage

1
2
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, 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 is specified by the argument "model" which is 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.

sim_sarima calls internally arima.sim to simulate the ARMA part of the model. Then undifferences the result to obtain the end result.

The function returns the simulated time series from the requested model.

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

Value

an object of class "ts"

Author(s)

Georgi N. Boshnakov

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require("PolynomF") # package "sarima" imports it, so should not be absent here.

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))

Example output

Loading required package: stats4
Loading required package: PolynomF
[1] 0.75-0.8291562i 0.75+0.8291562i
[1] 1.118034 1.118034
  [1]    0.000000    0.000000    0.000000    0.000000    0.000000    0.000000
  [7]    0.000000    0.000000    0.000000    0.000000    0.000000    0.000000
 [13]    0.000000    0.000000    0.000000    0.000000    0.000000    0.000000
 [19]    0.000000    0.000000    0.000000    0.000000    0.000000    0.000000
 [25]    0.000000    0.000000    0.000000   -1.942217   -5.992453   -9.320076
 [31]   -9.680192   -7.021296   -3.914545   -3.830058   -7.497865  -13.035282
 [37]  -18.618735  -21.920163  -22.504375  -25.337934  -30.450877  -33.307610
 [43]  -30.135677  -22.356761  -16.493137  -18.920828  -28.728212  -39.699934
 [49]  -47.720824  -50.281221  -49.449562  -53.012600  -59.933588  -65.003714
 [55]  -62.049688  -50.778899  -40.491678  -41.505010  -53.180047  -67.026983
 [61]  -77.309148  -83.202168  -86.257162  -91.911293  -99.516329 -107.494897
 [67] -106.823445  -94.742215  -81.686481  -80.790762  -92.851524 -108.811944
 [73] -123.933075 -135.894424 -144.441736 -151.044019 -156.617914 -165.325093
 [79] -167.769041 -156.973836 -141.089142 -136.317766 -144.974506 -159.356045
 [85] -178.941230 -200.992331 -221.868476 -236.789641 -244.333950 -250.628139
 [91] -247.714540 -231.177407 -210.423912 -203.209219 -213.134999 -231.896265
 [97] -259.234487 -290.208095 -315.887108 -329.354008 -330.992084 -332.327050
[103] -325.248817 -308.551599 -290.886095 -285.260088 -294.415578 -310.693824
[109] -339.254929 -376.496836 -406.441524 -417.811682 -413.285992 -411.261839
[115] -403.579358 -388.999098 -374.192040 -369.180427 -377.375480 -391.320914
[121] -419.770609 -460.739516 -493.992127 -505.005060 -497.562135 -494.197560
[127] -487.595435 -475.099995 -461.917299 -455.818472 -462.173956 -476.652281
[133] -508.582470 -553.963534 -588.383066 -595.617922 -582.017257 -575.515789
[139] -570.748324 -562.740387 -553.990709 -548.807995 -551.127697 -562.093114

sarima documentation built on Aug. 23, 2018, 9:03 a.m.