jackknife_stats#
- astropy.stats.jackknife_stats(data, statistic, confidence_level=0.95)[source]#
Performs jackknife estimation on the basis of jackknife resamples.
This function requires SciPy to be installed.
- Parameters:
- data
ndarray
Original sample (1-D array).
- statisticfunction
Any function (or vector of functions) on the basis of the measured data, e.g, sample mean, sample variance, etc. The jackknife estimate of this statistic will be returned.
- confidence_level
float
, optional Confidence level for the confidence interval of the Jackknife estimate. Must be a real-valued number in (0,1). Default value is 0.95.
- data
- Returns:
- estimate
float
orndarray
The i-th element is the bias-corrected “jackknifed” estimate.
- bias
float
orndarray
The i-th element is the jackknife bias.
- std_err
float
orndarray
The i-th element is the jackknife standard error.
- conf_interval
ndarray
If
statistic
is single-valued, the first and second elements are the lower and upper bounds, respectively. Ifstatistic
is vector-valued, each column corresponds to the confidence interval for each component ofstatistic
. The first and second rows contain the lower and upper bounds, respectively.
- estimate
Examples
Obtain Jackknife resamples:
>>> import numpy as np >>> from astropy.stats import jackknife_resampling >>> from astropy.stats import jackknife_stats >>> data = np.array([1,2,3,4,5,6,7,8,9,0]) >>> resamples = jackknife_resampling(data) >>> resamples array([[2., 3., 4., 5., 6., 7., 8., 9., 0.], [1., 3., 4., 5., 6., 7., 8., 9., 0.], [1., 2., 4., 5., 6., 7., 8., 9., 0.], [1., 2., 3., 5., 6., 7., 8., 9., 0.], [1., 2., 3., 4., 6., 7., 8., 9., 0.], [1., 2., 3., 4., 5., 7., 8., 9., 0.], [1., 2., 3., 4., 5., 6., 8., 9., 0.], [1., 2., 3., 4., 5., 6., 7., 9., 0.], [1., 2., 3., 4., 5., 6., 7., 8., 0.], [1., 2., 3., 4., 5., 6., 7., 8., 9.]]) >>> resamples.shape (10, 9)
2. Obtain Jackknife estimate for the mean, its bias, its standard error, and its 95% confidence interval:
>>> test_statistic = np.mean >>> estimate, bias, stderr, conf_interval = jackknife_stats( ... data, test_statistic, 0.95) >>> estimate 4.5 >>> bias 0.0 >>> stderr 0.95742710775633832 >>> conf_interval array([2.62347735, 6.37652265])
Example for two estimates
>>> test_statistic = lambda x: (np.mean(x), np.var(x)) >>> estimate, bias, stderr, conf_interval = jackknife_stats( ... data, test_statistic, 0.95) >>> estimate array([4.5 , 9.16666667]) >>> bias array([ 0. , -0.91666667]) >>> stderr array([0.95742711, 2.69124476]) >>> conf_interval array([[ 2.62347735, 3.89192387], [ 6.37652265, 14.44140947]])
IMPORTANT: Note that confidence intervals are given as columns