Time series bootstrapping in R: How can I access each simulated path using tsbootstrap?
r, simulation, statistics, statistics-bootstrap, time-series
Solution
The `b` argument is the block length. `m` is the "block of blocks" argument for when you want to calculate statistics for each resampled series, rather than return each resampled series itself.
library(tseries)
# Simulate a time series
set.seed(1)
TS<-arima.sim(model=list(ar=c(.8,-.2)), n=20)
plot(TS)
# 3 bootstrap samples with block size b=5
TSboot = tsbootstrap(TS, m=1, b=5, type="block", nb=3)
# Here are the individual bootstrapped series
TSboot
Time Series:
Start = 1
End = 20
Frequency = 1
[,1] [,2] [,3]
1 -0.72571390 1.94273559 1.62729703
2 -0.36463539 2.00048877 0.34495502
3 -0.30236104 1.28640888 -2.26419528
...
18 0.96532247 -0.72571390 -0.36463539
19 1.59792898 -0.36463539 -0.30236104
20 1.67918002 -0.30236104 -1.63971414
plot(TSboot)
Problem
I want to perform a bootstrap analysis of a specific time series. I am using the function `tsbootstrap` of the package `tseries`. My problem: for values of m > 1, I cannot access each bootstrapped path individually (m: the length of the basic blocks in the block of blocks bootstrap, see `?tsbootstrap`) ``` library(tseries) set.seed(1) TS <- sample(1:20) tsbootstrap(TS,m=2, nb=1) ``` gives: ``` Error in tsbootstrap(TS, m = 2, nb = 1) : can only return bootstrap data for m = 1 ``` To my knowledge, the function can only compute some statistics (e.g. mean) over all of the simulated tranjectories, but I need each simulation itself. How can I come around this problem? (I am aware of the function `tsboot` of the package `boot`, but I was not able to operationalize the function yet)