bb.science
Class Bootstrap

java.lang.Object
  extended by bb.science.Bootstrap

public class Bootstrap
extends Object

Performs statistical bootstrap calculations.

Concerning the quality of the results: bootstrapping is no magic bullet. So, if you supply garbage inputs, the outputs are also garbage. One example is insufficient data: the fundamental constructor will accept a sample which has but one element in it, but the statistical results that are calculated are almost certainly worthless.

This class is multithread safe: it is immutable (both its immediate state, as well as the deep state of its fields).

Author:
Brent Boyer

Nested Class Summary
static class Bootstrap.Estimate
          Holds a complete (point and interval) estimate for some Bootstrap.Estimator.
static interface Bootstrap.Estimator
          Specifies the api for classes that calculate an estimate for a statistic from a sample.
static class Bootstrap.EstimatorMean
          Calculates a point estimate for the population's arithmetic mean from sample.
static class Bootstrap.EstimatorMedian
          Calculates a point estimate for the population's median from sample.
static class Bootstrap.EstimatorSd
          Calculates a point estimate for the population's standard deviation from sample.
static class Bootstrap.UnitTest
          See the Overview page of the project's javadocs for a general description of this unit test class.
 
Field Summary
private  double confidenceLevel
           
private static double confidenceLevel_default
          Default value for confidenceLevel.
private static Bootstrap.Estimator[] estimators_default
          Default value for the estimators param of the fundamental constructor.
private  ConcurrentHashMap<Bootstrap.Estimator,Bootstrap.Estimate> estimatorToEstimate
           
private  int numberResamples
           
static int numberResamples_default
          Default value for numberResamples.
private  double[] sample
           
 
Constructor Summary
Bootstrap(double[] sample)
          Convenience constructor that simply calls this(sample, numberResamples_default).
Bootstrap(double[] sample, int numberResamples)
          Convenience constructor that simply calls this(sample, numberResamples, confidenceLevel_default).
Bootstrap(double[] sample, int numberResamples, double confidenceLevel)
          Convenience constructor that simply calls this(sample, numberResamples, confidenceLevel, estimators_default).
Bootstrap(double[] sample, int numberResamples, double confidenceLevel, Bootstrap.Estimator... estimators)
          Fundamental constructor.
 
Method Summary
private  double calcAcceleration(Bootstrap.Estimator estimator)
          Calculates the acceleration estimation for a BCa bootstrap.
private  double calcBias(double point, double[] resampleEsts, JSci.maths.statistics.NormalDistribution normalDistribution)
          Calculates the bias estimation for a BCa bootstrap.
private  ConcurrentHashMap<Bootstrap.Estimator,Bootstrap.Estimate> calcEstimates_BCa(Bootstrap.Estimator[] estimators)
          Performs a bootstrap calculation, determining one Bootstrap.Estimate for each element of estimators.
private  ConcurrentHashMap<Bootstrap.Estimator,Bootstrap.Estimate> calcEstimates_percentile(Bootstrap.Estimator[] estimators)
          Performs a bootstrap calculation, determining one Bootstrap.Estimate for each element of estimators.
private  ConcurrentHashMap<Bootstrap.Estimator,Bootstrap.Estimate> calcEstimates(Bootstrap.Estimator[] estimators)
           
private  double[] calcJackknifeEsts(Bootstrap.Estimator estimator)
          Jackknifes sample, calculating a point estimate for each jackknife resample using estimator.
private  Map<Bootstrap.Estimator,double[]> doResampling(Bootstrap.Estimator[] estimators)
          Generates numberResamples bootstrap resamples.
 Bootstrap.Estimate getEstimate(Bootstrap.Estimator estimator)
          Returns the Bootstrap.Estimate which corresponds to estimator.
 Bootstrap.Estimate getEstimate(String estimatorName)
          Returns the first Bootstrap.Estimate which corresponds to estimator with the same name as estimatorName.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

numberResamples_default

public static final int numberResamples_default
Default value for numberResamples. Its value of 100,000 was recommended by Tim Hesterberg (private communication) as providing the best balance between high accuracy and reasonable computation time.

See Also:
Constant Field Values

confidenceLevel_default

private static final double confidenceLevel_default
Default value for confidenceLevel. Its value of 0.95 is the usual 95% confidence level used in statistics.

See Also:
Constant Field Values

estimators_default

private static final Bootstrap.Estimator[] estimators_default
Default value for the estimators param of the fundamental constructor. Its value is the mean, median, and standard deviation estimators typically used in statistics.


sample

private final double[] sample

numberResamples

private final int numberResamples

confidenceLevel

private final double confidenceLevel

estimatorToEstimate

private final ConcurrentHashMap<Bootstrap.Estimator,Bootstrap.Estimate> estimatorToEstimate
Constructor Detail

Bootstrap

public Bootstrap(double[] sample)
          throws IllegalArgumentException
Convenience constructor that simply calls this(sample, numberResamples_default).

Throws:
IllegalArgumentException - if sample == null; sample.length == 0

Bootstrap

public Bootstrap(double[] sample,
                 int numberResamples)
          throws IllegalArgumentException
Convenience constructor that simply calls this(sample, numberResamples, confidenceLevel_default).

Throws:
IllegalArgumentException - if sample == null; sample.length == 0

Bootstrap

public Bootstrap(double[] sample,
                 int numberResamples,
                 double confidenceLevel)
          throws IllegalArgumentException
Convenience constructor that simply calls this(sample, numberResamples, confidenceLevel, estimators_default).

Throws:
IllegalArgumentException - if sample == null; sample.length == 0; numberResamples < 1; confidenceLevel <= 0 or confidenceLevel >= 1

Bootstrap

public Bootstrap(double[] sample,
                 int numberResamples,
                 double confidenceLevel,
                 Bootstrap.Estimator... estimators)
          throws IllegalArgumentException
Fundamental constructor.

Throws:
IllegalArgumentException - if sample == null; sample.length < 1; numberResamples < 1; confidenceLevel <= 0 or confidenceLevel >= 1; estimators == null; estimators.length == 0; the names of estimators fail to all be unique
Method Detail

calcEstimates

private ConcurrentHashMap<Bootstrap.Estimator,Bootstrap.Estimate> calcEstimates(Bootstrap.Estimator[] estimators)

calcEstimates_percentile

private ConcurrentHashMap<Bootstrap.Estimator,Bootstrap.Estimate> calcEstimates_percentile(Bootstrap.Estimator[] estimators)
Performs a bootstrap calculation, determining one Bootstrap.Estimate for each element of estimators. The simple bootstrap percentile method is used to calculate the confidence intervals.


calcEstimates_BCa

private ConcurrentHashMap<Bootstrap.Estimator,Bootstrap.Estimate> calcEstimates_BCa(Bootstrap.Estimator[] estimators)
Performs a bootstrap calculation, determining one Bootstrap.Estimate for each element of estimators. The Bias Corrected accelerated (BCa) bootstrap percentile method is used to calculate the confidence intervals. See pp. 185ff of "An Introduction to the Bootstrap", B. Efron and R. Tibshirani, Chapman and Hall, 1993 for a description of the calculation technique.


doResampling

private Map<Bootstrap.Estimator,double[]> doResampling(Bootstrap.Estimator[] estimators)
Generates numberResamples bootstrap resamples. For each resample, determines one point estimate for each element of estimators. The result is a Map from each Estimator to its array of resampled point estimates. Each array is sorted before return.


calcBias

private double calcBias(double point,
                        double[] resampleEsts,
                        JSci.maths.statistics.NormalDistribution normalDistribution)
Calculates the bias estimation for a BCa bootstrap. See Eq. 14.14 p. 186 of "An Introduction to the Bootstrap", B. Efron and R. Tibshirani, Chapman and Hall, 1993.


calcAcceleration

private double calcAcceleration(Bootstrap.Estimator estimator)
Calculates the acceleration estimation for a BCa bootstrap. See Eq. 14.15 p. 186 of "An Introduction to the Bootstrap", B. Efron and R. Tibshirani, Chapman and Hall, 1993.


calcJackknifeEsts

private double[] calcJackknifeEsts(Bootstrap.Estimator estimator)
Jackknifes sample, calculating a point estimate for each jackknife resample using estimator.


getEstimate

public Bootstrap.Estimate getEstimate(Bootstrap.Estimator estimator)
                               throws IllegalArgumentException
Returns the Bootstrap.Estimate which corresponds to estimator.

Throws:
IllegalArgumentException - if estimator == null; if there is no result for it

getEstimate

public Bootstrap.Estimate getEstimate(String estimatorName)
                               throws IllegalArgumentException
Returns the first Bootstrap.Estimate which corresponds to estimator with the same name as estimatorName.

Throws:
IllegalArgumentException - if estimatorName is blank; if there is no result for it