arch.bootstrap.IIDBootstrap.cov¶
-
IIDBootstrap.cov(func: Callable[[...], ndarray | DataFrame | Series], reps: int =
1000, recenter: bool =True, extra_kwargs: dict[str, Any] | None =None) float | ndarray[tuple[int, ...], dtype[float64]][source]¶ Compute parameter covariance using bootstrap.
- Parameters:¶
- func: Callable[[...], ndarray | DataFrame | Series]¶
Callable function that returns the statistic of interest as a 1-d array.
- reps: int =
1000¶ Number of bootstrap replications. Must be at least 1.
- recenter: bool =
True¶ Whether to center the bootstrap variance estimator on the average of the bootstrap samples (True) or to center on the original sample estimate (False).
- extra_kwargs: dict[str, Any] | None =
None¶ Dictionary of extra keyword arguments to pass to func.
- Returns:¶
Bootstrap covariance estimator. If func returns complex values, this is the complex Hermitian covariance, which uses the conjugate transpose, and a complex128 array.
- Return type:¶
- Raises:¶
TypeError – If
funcis not callable,repsis not an int,recenteris not a bool, orextra_kwargsis not a dict.ValueError – If
repsis less than 1, orextra_kwargshas a key that is the name of bootstrapped data.
Notes
func must have the signature
func(*args, **kwargs)where *args and **kwargs are the bootstrap version of the data used in the bootstrap, and any
extra_kwargsare appended to **kwargs. The function returns a scalar, a 0-dimensional array or a 1-dimensional array-like. Aparamsargument is not passed, so only the nonparametric bootstrap can be used.Examples
Bootstrap covariance of the mean
>>> from arch.bootstrap import IIDBootstrap >>> import numpy as np >>> def func(x): ... return x.mean(axis=0) >>> y = np.random.randn(1000, 3) >>> bs = IIDBootstrap(y) >>> cov = bs.cov(func, 1000)Bootstrap covariance using a function that takes additional input
>>> def func(x, stat='mean'): ... if stat=='mean': ... return x.mean(axis=0) ... elif stat=='var': ... return x.var(axis=0) >>> cov = bs.cov(func, 1000, extra_kwargs={'stat':'var'})Note
Note this is a generic example and so the class used should be the name of the required bootstrap.