Simulate fractional ARIMA Time Series
fracdiff.sim.RdGenerates 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
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,
rnormgenerates 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 inarima.simis computed.- backComp
logical indicating if back compatibility with older versions of
fracdiff.simis desired. Otherwise, ford = 0, compatibility with R'sarima.simis achieved.- allow.0.nstart
logical indicating if
n.start = 0should be allowed even when \(p + q > 0\). This not recommended unless for producing the same series as with older versions offracdiff.sim.- start.innov
an optional vector of innovations to be used for the burn-in period. If supplied there must be at least
n.startvalues.- ...
additional arguments for
rand.gen(). Most usefully, the standard deviation of the innovations generated byrnormcan be specified bysd.- 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
Examples
## Pretty (too) short to "see" the long memory
fracdiff.sim(100, ar = .2, ma = .4, d = .3)
#> $series
#> [1] 1.638800218 -1.603146117 -0.054717460 1.403075920 -0.659829202
#> [6] 0.013055359 -0.972348581 0.536532022 0.440775043 -0.873033650
#> [11] -0.432069381 0.094774774 -1.648142812 -0.210777100 0.617922101
#> [16] 2.764655474 0.753441848 0.515446273 -0.014856082 2.121160874
#> [21] 1.445149215 1.289507605 -0.707403820 0.879238788 2.614860696
#> [26] 1.172039268 0.721397889 2.188541912 1.006855452 0.925061611
#> [31] -0.459106839 1.847786874 1.402210782 0.427446021 2.097796988
#> [36] -0.673488716 -0.230542183 0.568655111 2.609624653 1.771011342
#> [41] 0.516286980 1.352795573 1.562642739 1.934142563 1.124433135
#> [46] 1.270348383 1.361166793 0.175551401 0.755878082 0.849239877
#> [51] 0.477828428 0.473281788 0.169620245 0.526362814 1.349228496
#> [56] 1.239364747 1.193070841 1.204387420 1.641551435 1.041120684
#> [61] 1.626609504 1.724350559 1.248292526 1.940142594 0.081973195
#> [66] -0.444548735 -0.796570297 -0.546593677 0.717776767 0.040881270
#> [71] 1.793192136 0.159579097 0.015848061 0.964101534 0.448662554
#> [76] -1.724601439 -1.407805075 -0.899407175 -0.181081262 -0.224475580
#> [81] 1.507365541 0.974737047 -1.220979546 -0.350581962 0.009325098
#> [86] 0.253554447 0.629093465 -0.897742019 0.014869018 0.821637422
#> [91] -1.163497727 -0.400604240 1.110154286 -0.997538749 0.870989573
#> [96] -0.133547186 -0.744269960 1.041665315 0.846093565 0.482715675
#>
#> $ar
#> [1] 0.2
#>
#> $ma
#> [1] 0.4
#>
#> $d
#> [1] 0.3
#>
#> $mu
#> [1] 0
#>
#> $n.start
#> [1] 6
#>
## 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))
#> 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
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))