fracdiff.sim: Simulate fractional ARIMA Time Series

Description Usage Arguments Value See Also Examples

View source: R/fracdiff.R

Description

Generates simulated long-memory time series data from the fractional ARIMA(p,d,q) model. This is a test problem generator for fracdiff.

Note that the MA coefficients have inverted signs compared to other parametrizations, see the details in fracdiff.

Usage

1
2
3
4
5
fracdiff.sim(n, ar = NULL, ma = NULL, d,
             rand.gen = rnorm, innov = rand.gen(n+q, ...),
             n.start = NA, backComp = TRUE, allow.0.nstart = FALSE,
             start.innov = rand.gen(n.start, ...),
             ..., mu = 0)

Arguments

n

length of the time series.

ar

vector of autoregressive parameters; empty by default.

ma

vector of moving average parameters; empty by default.

d

fractional differencing parameter.

rand.gen

a function to generate the innovations; the default, rnorm generates white N(0,1) noise.

innov

an optional times series of innovations. If not provided, rand.gen() is used.

n.start

length of “burn-in” period. If NA, the default, the same value as in arima.sim is computed.

backComp

logical indicating if back compatibility with older versions of fracdiff.sim is desired. Otherwise, for d = 0, compatibility with R's arima.sim is achieved.

allow.0.nstart

logical indicating if n.start = 0 should be allowed even when p + q > 0. This not recommended unless for producing the same series as with older versions of fracdiff.sim.

start.innov

an optional vector of innovations to be used for the burn-in period. If supplied there must be at least n.start values.

...

additional arguments for rand.gen(). Most usefully, the standard deviation of the innovations generated by rnorm can be specified by sd.

mu

time series mean (added at the end).

Value

a list containing the following elements :

series

time series

ar, ma, d, mu, n.start

same as input

See Also

fracdiff, also for references; arima.sim

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
## Pretty (too) short to "see" the long memory
fracdiff.sim(100, ar = .2, ma = .4, d = .3)

## longer with "extreme" ar:
r <- fracdiff.sim(n=1500, ar=-0.9, d= 0.3)
plot(as.ts(r$series))

## Show that  MA  coefficients meaning is inverted
## compared to   stats :: arima :

AR <- 0.7
MA <- -0.5
n.st <- 2

AR <- c(0.7, -0.1)
MA <- c(-0.5, 0.4)
n <- 512 ; sd <- 0.1
n.st <- 10

set.seed(101)
Y1 <- arima.sim(list(ar = AR, ma = MA), n = n, n.start = n.st, sd = sd)
plot(Y1)

# For our fracdiff, reverse the MA sign:
set.seed(101)
Y2 <- fracdiff.sim(n = n, ar = AR, ma = - MA, d = 0,
                   n.start = n.st, sd = sd)$series
lines(Y2, col=adjustcolor("red", 0.5))
## .. no, you don't need glasses ;-)  Y2 is Y1 shifted slightly

##' rotate left by k (k < 0: rotate right)
rot <- function(x, k) {
  stopifnot(k == round(k))
  n <- length(x)
  if(k <- k %% n) x[c((k+1):n, 1:k)] else x
}
k <- n.st - 2
Y2.s <- rot(Y2, k)
head.matrix(cbind(Y1, Y2.s))
plot(Y1, Y2.s); i <- (n-k+1):n
text(Y1[i], Y2.s[i], i, adj = c(0,0)-.1, col=2)

## With  backComp = FALSE,  get *the same* as arima.sim():
set.seed(101)
Y2. <- fracdiff.sim(n = n, ar = AR, ma = - MA, d = 0,
                    n.start = n.st, sd = sd, backComp = FALSE)$series
stopifnot( all.equal( c(Y1), Y2., tolerance= 1e-15))

Example output

$series
  [1]  1.07439044  1.12210308  1.77361019  1.69016208  2.21584460 -0.16316345
  [7]  1.23783578  3.92040189  2.57071041  1.73627958  1.36398217  0.20881677
 [13]  0.95231401  1.79634550  0.47784926  1.92450498  0.39561477  1.52302794
 [19]  1.55765338  1.24152762  2.07192259  0.36744711  1.61306399  0.09048140
 [25]  0.91043713  2.55597036 -0.48141722  0.20124869  1.11577895  0.52019040
 [31]  1.53493661 -0.63271378  1.39229624  1.44183980 -0.45809011  1.15890686
 [37]  0.19226339  1.66648583  0.61755054  0.14711422 -0.33713357  1.22183442
 [43]  2.30981184  0.07800016 -1.19445688  0.76631893  0.61152539  0.46360812
 [49]  0.28172150 -0.62046409 -0.73636018  0.87089662 -0.96372049  0.03646028
 [55] -0.11362939  0.19241972 -0.01551000 -0.57749425 -0.35012870 -0.08369779
 [61]  0.13821139  0.10606870 -0.95618221 -0.90275484 -0.31899366 -1.64683756
 [67] -1.14593445 -0.80459003 -2.05595683  1.65662774  1.36662355  0.58625490
 [73]  0.87108490  0.80320894  0.95162278 -1.15732966 -0.29851678  0.19967171
 [79]  1.55423469  0.48178540  1.03343070 -0.41360882  1.09044095  0.91878705
 [85] -0.53711647  0.79585493  0.75948224  0.47728585  0.37866963  0.11819536
 [91]  0.57039621  1.43632511 -0.28179184  1.49004302  1.12103185 -0.66494220
 [97] -1.59214366 -0.34321625  0.67482887 -1.59476085

$ar
[1] 0.2

$ma
[1] 0.4

$d
[1] 0.3

$mu
[1] 0

$n.start
[1] 6

               Y1         Y2.s
[1,]  0.105653840  0.105986817
[2,] -0.043723547 -0.043557047
[3,]  0.162403833  0.162487085
[4,] -0.131808486 -0.131766860
[5,] -0.001723455 -0.001702642
[6,] -0.054197985 -0.054187579

fracdiff documentation built on Jan. 25, 2020, 1:07 a.m.