block_bootstrap: Block Bootstrap

View source: R/block_bootstrap.R

block_bootstrapR Documentation

Block Bootstrap

Description

This function performs block bootstrap (moving or circular) to obtain a (1-\alpha)\% confidence-interval for the autocovariance function. It will also compute average autocovariance function across all bootstrapped estimates.

Usage

block_bootstrap(
  X,
  maxLag,
  x = 0:length(X),
  n_bootstrap = 100,
  l = ceiling(length(X)^(1/3)),
  estimator = standard_est,
  type = c("autocovariance", "autocorrelation"),
  alpha = 0.05,
  boot_type = c("moving", "circular"),
  parallel = FALSE,
  ncores = parallel::detectCores() - 1,
  cl_export = NULL,
  boot_seed = NULL,
  cl = NULL,
  ...
)

Arguments

X

A vector representing observed values of the time series.

maxLag

The maximum lag to compute the estimated autocovariance function at.

x

A vector of lag indices. Defaults to the sequence 0:length(X). Must be at least as large as maxLag + 1.

n_bootstrap

The number of times to run moving block bootstrap. Defaults to 100.

l

The block length considered for bootstrap. Defaults to \lceil N \rceil^{1/3}, where N is the length of the observation window.

estimator

The function name of the estimator to use. Defaults to standard\_est.

type

Compute either the 'autocovariance' or 'autocorrelation'. Defaults to 'autocovariance'.

alpha

The quantile used to compute the (1 - \alpha)\% confidence interval. Defaults to 0.05.

boot_type

What type of block bootstrap should be used, either 'moving' for moving block bootstrap or 'circular' for circular block bootstrap.

parallel

Whether or not the bootstrap computations should be done in parallel or not. Defaults to FALSE.

ncores

The number of cores to be used in the parallel bootstrap computations. Defaults to the number cores - 1 (threads if hyperthreading is available), calculated from parallel::detectCores() - 1.

cl_export

A vector of any additional functions or variables to export for parallel computations. This may be required if estimator is not within the package. Defaults to NULL.

boot_seed

An integer seed for reproducibility. This is used for

cl

An optional cluster object created by parallel::makeCluster. Defaults to NULL, which creates a temporary PSOCK cluster.

...

Optional named arguments to the chosen estimator. See the examples.

Details

This function performs block bootstrap to obtain a (1-\alpha)\% confidence-interval for the autocovariance function. It will also compute average autocovariance function across all bootstrapped estimates.

Moving block bootstrap can be described as follows. For some times series X(1), X(2), \dots, X(n), construct k \in N overlapping blocks of the form B_{i} = (X(i), \dots, X(i + \ell - 1)), where \ell \in \{1, \dots , n\} is the block length. Randomly sample, with replacement, from the discrete uniform distribution with on \{1, \dots, n - \ell + 1\} to obtain a set of random starting locations I_{1}, \dots, I_{k}. Construct a bootstrapped time series B_{1}^{\ast}, B_{2}^{\ast}, \dots, B_{k}^{\ast}, where B_{i}^{\ast} = B_{I_{i}}. The bootstrapped time series is truncated to have length n, and will be of the form X^{\ast}(1), \dots , X^{\ast}(n). The autocovariance function is then computed for the bootstrapped time series.

An alternative to moving block bootstrap is circular block bootstrap. Circular block bootstrap uses the time series like a circle, that is, the observation at n + i is the same as the observation at location i. For example, for the block B_{n - \ell + 2}, we obtain (X(n - \ell + 2) , \dots , X(n), X(n + 1)) is the same as (X(n - \ell + 2) , \dots , X(n), X(1)). When performing random sampling to obtain starting locations, the set \{1, \dots, n\} is now considered. The procedure for constructing the bootstrap time series after constructing the blocks and selecting the starting indices is the same as moving block bootstrap.

This process is repeated n_bootstrap times to obtain n_boostrap estimates of the autocovariance function using the bootstrapped time series, for which the average autocovariance function and the (1 - \alpha)\% confidence intervals are constructed pointwise for each lag.

The choice of the block length, \ell , depends on the degree of dependence present in the time series. If the time series has a high degree of dependence, a larger block size should be chosen to ensure the dependency structure is maintained within the block.

Any estimator of the autocovariance function can be used in this function, including a custom estimator not in the package, see the examples.

When parallel = TRUE, L'Ecuyer-CMRG is used to ensure independent random numbers across workers. The serial version uses the Mersenne-Twister algorithm.

Value

A BootEsts S3 object (list) with the following values

acf_avg

A numeric vector containing the average autocovariance/autocorrelation bootstrap estimate.

lags

A numeric vector containing the lag indices used to compute the estimates on.

acf_orig

A numeric vector containing the nonbootstrapped autocovariance/autocorrelation estimate.

acf_mat

A numeric matrix of the a matrix of all of the bootstrap estimates.

conf_lower

A numeric vector containing the lower bounds for the estimated pointwise confidence interval.

conf_upper

A numeric vector containing the upper bounds for the estimated pointwise confidence interval.

est_type

The type of estimate, namely 'autocorrelation' or 'autocovariance', this depends on the argument type.

est_used

The estimator function used, this depends on the argument estimator.

boot_type

The type of estimate, namely 'moving' or 'circular', this depends on the argument boot_type.

alpha

A numeric value, which is the \alpha value used to compute the confidence intervals, this depends on the argument alpha.

References

Chapters 2.5 and 2.7 in Lahiri, S. N. (2003). Resampling Methods for Dependent Data. Springer. https://doi.org/10.1007/978-1-4757-3803-2

Künsch, H. R. (1989). The Jackknife and the Bootstrap for General Stationary Observations. The Annals of Statistics 17(3), 1217-1241. https://doi.org/10.1214/aos/1176347265

Politis, D. N. & Romano, J. P. (1991). A Circular Block-Resampling Procedure for Stationary Data. In R. LePage & L. Billard, eds, Exploring the Limits of Bootstrap, Wiley, 263-270.

Examples

X <- c(1, 2, 3, 3, 2, 1)
block_bootstrap(X, 4, n_bootstrap = 3, l = 2, type = 'autocorrelation')
block_bootstrap(X, 4, n_bootstrap = 3, l = 2, type = 'autocovariance')
block_bootstrap(X, 4, n_bootstrap = 3, l = 2, estimator=tapered_est,
    rho = 0.5, window_name = 'blackman', window_params = c(0.16),
    type='autocorrelation')
my_cov_est <- function(X, maxLag) {
  n <- length(X)
  covVals <- rep(0, maxLag + 1)
  for(h in 0:maxLag) {
    covVals_t <- (X[1:(n-h)] - mean(X)) * (X[(1+h):n] - mean(X))
    covVals[h] <- sum(covVals_t) / (n - h)
  }
  return(covVals)
}
block_bootstrap(X, 4, n_bootstrap = 3, l = 2, estimator=my_cov_est)

plot(LakeHuron, main="Lake Huron Levels", ylab="Feet")
X <- as.vector(LakeHuron)
block_bootstrap(X, 20, n_bootstrap = 100, l = 40, type = 'autocorrelation')
block_bootstrap(X, 20, n_bootstrap = 100, l = 40, type = 'autocorrelation')
block_bootstrap(X, 20, n_bootstrap = 100, l = 40, estimator=tapered_est,
    rho = 0.5, window_name = 'blackman', window_params = c(0.16),
    type='autocorrelation')

my_cov_est <- function(X, maxLag) {
  n <- length(X)
  covVals <- rep(0, maxLag + 1)
  for(h in 0:maxLag) {
    covVals_t <- (X[1:(n-h)] - mean(X)) * (X[(1+h):n] - mean(X))
    covVals[h] <- sum(covVals_t) / (n - h)
  }
  return(covVals)
}
block_bootstrap(X, 20, n_bootstrap = 100, l = 40, estimator = my_cov_est,
    type = 'autocorrelation')
## Not run: 
library(parallel)
X <- c(1, 2, 3, 3, 2, 1)
my_cl <- makePSOCKcluster(2)
block_bootstrap(X, 4, n_bootstrap = 1000, l = 3, parallel = TRUE, cl = my_cl)
stopCluster(my_cl)

## End(Not run)

CovEsts documentation built on April 19, 2026, 5:06 p.m.