Description Usage Arguments Details Value References See Also Examples

Generate `R`

bootstrap replicates of a statistic applied to a
time series. The replicate time series can be generated using fixed
or random block lengths or can be model based replicates.

1 2 3 4 5 |

`tseries` |
A univariate or multivariate time series. |

`statistic` |
A function which when applied to |

`R` |
A positive integer giving the number of bootstrap replicates required. |

`sim` |
The type of simulation required to generate the replicate time series. The
possible input values are |

`l` |
If |

`endcorr` |
A logical variable indicating whether end corrections are to be
applied when |

`n.sim` |
The length of the simulated time series. Typically this will be equal
to the length of the original time series but there are situations when
it will be larger. One obvious situation is if prediction is required.
Another situation in which |

`orig.t` |
A logical variable which indicates whether |

`ran.gen` |
This is a function of three arguments. The first argument is a time
series. If |

`ran.args` |
This will be supplied to |

`norm` |
A logical argument indicating whether normal margins should be used
for phase scrambling. If |

`...` |
Extra named arguments to |

`parallel, ncpus, cl` |
See the help for |

If `sim`

is `"fixed"`

then each replicate time series is
found by taking blocks of length `l`

, from the original time
series and putting them end-to-end until a new series of length
`n.sim`

is created. When `sim`

is `"geom"`

a similar
approach is taken except that now the block lengths are generated from
a geometric distribution with mean `l`

. Post-blackening can be
carried out on these replicate time series by including the function
`ran.gen`

in the call to `tsboot`

and having `tseries`

as a time series of residuals.

Model based resampling is very similar to the parametric bootstrap and all simulation must be in one of the user specified functions. This avoids the complicated problem of choosing the block length but relies on an accurate model choice being made.

Phase scrambling is described in Section 8.2.4 of Davison and Hinkley
(1997). The types of statistic for which this method produces
reasonable results is very limited and the other methods seem to do
better in most situations. Other types of resampling in the frequency
domain can be accomplished using the function `boot`

with the
argument `sim = "parametric"`

.

An object of class `"boot"`

with the following components.

`t0` |
If |

`t` |
The results of applying |

`R` |
The value of |

`tseries` |
The original time series. |

`statistic` |
The function |

`sim` |
The simulation type used in generating the replicates. |

`endcorr` |
The value of |

`n.sim` |
The value of |

`l` |
The value of |

`ran.gen` |
The |

`ran.args` |
The extra arguments passed to |

`call` |
The original call to |

Davison, A.C. and Hinkley, D.V. (1997)
*Bootstrap Methods and Their Application*. Cambridge University Press.

Kunsch, H.R. (1989) The jackknife and the bootstrap for general stationary
observations. *Annals of Statistics*, **17**, 1217–1241.

Politis, D.N. and Romano, J.P. (1994) The stationary bootstrap.
*Journal of the American Statistical Association*, **89**, 1303–1313.

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 56 57 58 59 | ```
lynx.fun <- function(tsb) {
ar.fit <- ar(tsb, order.max = 25)
c(ar.fit$order, mean(tsb), tsb)
}
# the stationary bootstrap with mean block length 20
lynx.1 <- tsboot(log(lynx), lynx.fun, R = 99, l = 20, sim = "geom")
# the fixed block bootstrap with length 20
lynx.2 <- tsboot(log(lynx), lynx.fun, R = 99, l = 20, sim = "fixed")
# Now for model based resampling we need the original model
# Note that for all of the bootstraps which use the residuals as their
# data, we set orig.t to FALSE since the function applied to the residual
# time series will be meaningless.
lynx.ar <- ar(log(lynx))
lynx.model <- list(order = c(lynx.ar$order, 0, 0), ar = lynx.ar$ar)
lynx.res <- lynx.ar$resid[!is.na(lynx.ar$resid)]
lynx.res <- lynx.res - mean(lynx.res)
lynx.sim <- function(res,n.sim, ran.args) {
# random generation of replicate series using arima.sim
rg1 <- function(n, res) sample(res, n, replace = TRUE)
ts.orig <- ran.args$ts
ts.mod <- ran.args$model
mean(ts.orig)+ts(arima.sim(model = ts.mod, n = n.sim,
rand.gen = rg1, res = as.vector(res)))
}
lynx.3 <- tsboot(lynx.res, lynx.fun, R = 99, sim = "model", n.sim = 114,
orig.t = FALSE, ran.gen = lynx.sim,
ran.args = list(ts = log(lynx), model = lynx.model))
# For "post-blackening" we need to define another function
lynx.black <- function(res, n.sim, ran.args) {
ts.orig <- ran.args$ts
ts.mod <- ran.args$model
mean(ts.orig) + ts(arima.sim(model = ts.mod,n = n.sim,innov = res))
}
# Now we can run apply the two types of block resampling again but this
# time applying post-blackening.
lynx.1b <- tsboot(lynx.res, lynx.fun, R = 99, l = 20, sim = "fixed",
n.sim = 114, orig.t = FALSE, ran.gen = lynx.black,
ran.args = list(ts = log(lynx), model = lynx.model))
lynx.2b <- tsboot(lynx.res, lynx.fun, R = 99, l = 20, sim = "geom",
n.sim = 114, orig.t = FALSE, ran.gen = lynx.black,
ran.args = list(ts = log(lynx), model = lynx.model))
# To compare the observed order of the bootstrap replicates we
# proceed as follows.
table(lynx.1$t[, 1])
table(lynx.1b$t[, 1])
table(lynx.2$t[, 1])
table(lynx.2b$t[, 1])
table(lynx.3$t[, 1])
# Notice that the post-blackened and model-based bootstraps preserve
# the true order of the model (11) in many more cases than the others.
``` |

```
2 3 4 5 6 7 8 10 11 12 13
14 21 44 5 2 2 5 1 3 1 1
2 3 4 5 6 7 8 9 10 11 12 16
3 3 19 5 1 12 2 4 2 44 2 2
2 3 4 5 6 7 9 10 11 17 18
16 18 42 8 3 2 1 3 4 1 1
2 3 4 5 6 7 8 9 10 11 12
3 7 23 1 1 9 3 2 3 42 5
2 3 4 5 6 7 8 9 10 11 12 13 14
1 1 15 1 2 8 2 3 4 50 7 4 1
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.