strapvizpy.bootstrap
Module Contents
Functions
|
Bootstraps a sampling distribution for a sample. |
|
Calculates a bootstrapped confidence interval for a sample. |
Attributes
- strapvizpy.bootstrap.SUPPORTED_ESTIMATORS
- strapvizpy.bootstrap.bootstrap_distribution(sample, rep, n='auto', estimator='mean', random_seed=None)[source]
Bootstraps a sampling distribution for a sample.
A sampling distribution of rep replicates is generated for the specified estimator`with replacement with a bootstrap sample size of `n.
- Parameters
sample (list or numpy.ndarray or pandas.core.series.Series) – sample to bootstrap
rep (int) – number of replicates of the distribution
n (str or int, default="auto") – bootstrap sample size, “auto” specifies using the same size as the sample
estimator ({"mean", "median", "var", "sd"}) – sampling distributor’s estimator
random_seed (None or int, default=None) – seed for random state
- Returns
bootstrapped sampling distribution
- Return type
numpy.ndarray
Examples
>>> bootstrap_distribution([1, 2, 3], 3, 3) array([1.66, 2, 2.66])
- strapvizpy.bootstrap.calculate_boot_stats(sample, rep, n='auto', level=0.95, estimator='mean', random_seed=None, pass_dist=False)[source]
Calculates a bootstrapped confidence interval for a sample.
A bootstrapped confidence interval for the desired estimator for the provided sample is calculated for a confidence level level. Other stats and parameters of the distribution and sample are also returned.
- Parameters
sample (list or numpy.ndarray or pandas.core.series.Series) – sample to bootstrap
rep (int) – number of replicates of the distribution
n (str or int, default="auto") – bootstrap sample size, “auto” specifies using the same size as the sample
level (float, default=0.95) – confidence level
estimator ({"mean", "median", "var", "sd"}) – sampling distributor’s estimator
random_seed (None or int, default=None) – seed for random state
pass_dist (bool, default = "False") – return the bootstrapped sample distribution - False or True
- Returns
Dictionary containing lower and upper bootstrapped confidence interval for the desired estimator, along with the given estimator. Also
- Return type
dictionary
Examples
>>> calculate_boot_stats([1, 2, 3, 4], 1000, level=0.95, random_seed=123) {'lower': 1.5, 'upper': 3.5, 'sample_mean': 2.5, 'std_err': 0.5414773771820943, 'level': 0.95, 'sample size': 4, 'n': 'auto', 'rep': 1000, 'estimator': 'mean'}