arch.bootstrap.LocalBlockBootstrap¶
-
class arch.bootstrap.LocalBlockBootstrap(block_size: int, locality: int, *args: ndarray | DataFrame | Series, seed: int | Generator | RandomState | None =
None, **kwargs: ndarray | DataFrame | Series)[source]¶ Bootstrap using blocks that are resampled from near their own position.
- Parameters:¶
- block_size: int¶
Size of block to use. Must be an integer that is at least 1. Blocks do not wrap around, so the block size cannot be larger than the number of observations, which is checked when the iteration starts.
- locality: int¶
Half-width of the window, in observations, from which the start of a block is drawn. Must be an integer that is at least 0. The start of each block is drawn uniformly from the starts that are at most
localityobservations from the start of the block in the data. A value of 0 keeps every block in place. A value of at least the number of observations draws each block from anywhere in the data, which is the moving block bootstrap. See Notes.- *args: ndarray | DataFrame | Series¶
Positional arguments to bootstrap. Each must have at least one row.
- seed: int | Generator | RandomState | None =
None¶ Seed to use to ensure reproducible results. If an int, it must be non-negative and is passed to
np.random.default_rng. If None, a fresh Generator is constructed with system-provided entropy.- **kwargs: ndarray | DataFrame | Series¶
Keyword arguments to bootstrap. Each must have at least one row.
- data¶
Two-element tuple with the pos_data in the first position and kw_data in the second (pos_data, kw_data).
- Raises:¶
TypeError – If an input is not an ndarray, Series or DataFrame,
block_sizeorlocalityis not an int, orseedis not None, a non-negative int, a Generator or a RandomState.ValueError – If there are no inputs, an input has no rows, the inputs do not have the same number of rows,
block_sizeis less than 1 (or, when the iteration starts, larger than the number of observations),localityis negative,seedis a negative int, or a keyword argument has the name of an attribute or method of the bootstrap.
See also
arch.bootstrap.MovingBlockBootstrapBlocks without wrap around, drawn from the whole sample.
arch.bootstrap.CircularBlockBootstrapCircular (wrap-around) bootstrap.
arch.bootstrap.optimal_block_lengthOptimal block length estimation, for stationary data.
Notes
The local block bootstrap [1] is designed for series whose properties change slowly, such as a series with a trend or with a variance that moves over time. The block bootstraps for stationary data mix blocks from the whole sample, which is not appropriate when the observations at the start and at the end of the sample have different distributions. The local block bootstrap replaces a block only with a block that starts close to it.
The sample is covered by
ceil(n / block_size)blocks, wherenis the number of observations. With zero-based positions, blockm(form = 0, 1, ...) has the nominal startm * block_size, which is where it starts in the data. The start of the block that is used in its place is drawn uniformly from the integers in the interval:[max(0, m * block_size - locality), min(n - block_size, m * block_size + locality)]Both end points are possible. The blocks are independent, they do not wrap around the end of the data, and the concatenated blocks are truncated to
nobservations. In the last blocks the lower end can exceed the upper end, and it is then set to the upper end. Ifblock_sizedoes not dividen, the last block starts atn - block_sizeor earlier so that no block extends past the data, and so withlocality=0the bootstrap sample is the data only whenblock_sizedividesn.Paparoditis and Politis [1] number the observations from 1 and draw the start of block
mfrom[max(1, m * b - K), min(n - b + 1, m * b + K)], wherebis the block size andK = nBfor a fractionBof the sample. Here the observations are numbered from 0 and the window of blockmis centered onm * b, the position where the block starts in the data. In the numbering of the paper the window is centered one observation earlier, and this does not matter for the asymptotic results. The locality is the integer number of observationsK, and not the fractionB, so thatclonecan create a bootstrap with the same locality for data of any length. A block size of 1 is the local bootstrap for heteroskedastic regression of Shi [2].The method requires a block size that is large, and a window that is large relative to the block size and small relative to the number of observations. Neither is chosen automatically.
optimal_block_lengthassumes stationary data and does not give values to use here.Some of the methods that use the bootstrap need care:
The BCa interval computes its acceleration using a leave-one-out jackknife. This is a heuristic for dependent data, and in particular for data that are not stationary.
The studentized interval estimates the standard error of each resampled statistic using a bootstrap of the resampled data with the same block size and locality (see
clone). Usestd_err_funcinconf_intto provide another estimate of the standard error.
The local block bootstrap is not an option of the multiple comparison procedures
SPA,StepMandMCS, which assume stationary data.The data are used as given. They are not converted to float64 and are not checked for NaN or inf, since the function that is bootstrapped decides how to treat them (for example, using
np.nanmean).Data entered using keyword arguments is directly accessible as an attribute.
To ensure a reproducible bootstrap, you must pass the
seedkeyword argument when the bootstrap is created. See the example below. Note thatseedis a reserved keyword and any variable passed using this keyword must be an integer, aGeneratoror aRandomState.References
Examples
Estimate the standard error of the mean of a series with a trend.
>>> import numpy as np >>> from arch.bootstrap import LocalBlockBootstrap >>> rng = np.random.default_rng(1234) >>> y = 3 * np.arange(600) / 600 + rng.standard_normal(600) >>> bs = LocalBlockBootstrap(10, 40, y, seed=rng) >>> se = np.sqrt(bs.var(np.mean, reps=500))Data can be accessed in a number of ways. Positional data is retained in the same order as it was entered when the bootstrap was initialized. Keyword data is available both as an attribute or using a dictionary syntax on kw_data.
>>> x = rng.standard_normal((600, 2)) >>> z = rng.standard_normal(600) >>> bs = LocalBlockBootstrap(10, 40, x, y=y, z=z) >>> for data in bs.bootstrap(100): ... bs_x = data[0][0] ... bs_y = data[1]['y'] ... bs_z = bs.zMethods
apply(func[, reps, extra_kwargs])Apply a function to bootstrap replicated data.
bootstrap(reps)Iterate over the bootstrap replications.
clone(*args[, seed])Clone the bootstrap using different data with a fresh prng.
conf_int(func[, reps, method, size, tail, ...])Compute confidence intervals using the bootstrap.
cov(func[, reps, recenter, extra_kwargs])Compute parameter covariance using bootstrap.
reset([use_seed])Reset the bootstrap to its initial state.
Update indices for the next iteration of the bootstrap.
var(func[, reps, recenter, extra_kwargs])Compute parameter variance using bootstrap.
Properties
The block size of the bootstrap.
Set or get the instance PRNG.
The current index of the bootstrap.
The locality of the bootstrap.
Set or get the generator's state.