Class Jackknife
- java.lang.Object
-
- it.unimi.dsi.stat.Jackknife
-
public class Jackknife extends java.lang.Object
Applies the jackknife to generic statistics.This class applies the jackknife method (see, e.g., “A leisurely look at the bootstrap, the jackknife, and cross-validation”, by Bradley Efron and Gail Gong, The American Statistician, 37(1):36−48, 1983) to reduce the bias in the estimation of a nonlinear statistic of interest (linear statistics, such as the mean, pass through the jackknife without change). The statistic must take a sample (an array of big decimals) and return corresponding values (again as an array of big decimals). In case high-precision arithmetic is not required, an instance of
Jackknife.AbstractStatistic
just takes an array of doubles and returns an array of doubles, handling all necessary type conversions.The static method
compute(List, Statistic, MathContext)
takes a list of samples (arrays of doubles of the same length) and returns an instance of this class containing estimates and standard errors for every value computed by the statistic (estimates of the statistic are available both as an array of big decimals and as an array of doubles, whereas estimates of standard errors are provided in double format, only).All computations are performed internally using
BigDecimal
and a providedMathContext
. The methodcompute(List, Statistic)
uses 100 decimal digits.The identical statistic can be used to compute the (pointwise) empirical mean and standard error of a sample.
- Author:
- Sebastiano Vigna
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Jackknife.AbstractStatistic
An abstract statistic with a template method that accepts an array of doubles, returns an array of doubles and handles the data conversions that are necessary to callJackknife.Statistic.compute(BigDecimal[], MathContext)
.static interface
Jackknife.Statistic
A statistic to be estimated using the jackknife on a set of samples.
-
Field Summary
Fields Modifier and Type Field Description java.math.BigDecimal[]
bigEstimate
A vector of high-precision estimates for a statistic of interest.static java.math.MathContext
DEFAULT_MATH_CONTEXT
double[]
estimate
A vector of estimates for a statistic of interest (obtained by invokingBigDecimal.doubleValue()
onbigEstimate
).static Jackknife.Statistic
IDENTITY
A statistic that returns the sample.double[]
standardError
A vector of (estimates of the) standard error parallel tobigEstimate
/estimate
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static double[]
bigDecimalArray2DoubleArray(java.math.BigDecimal[] input)
static Jackknife
compute(java.util.List<double[]> samples, Jackknife.Statistic f)
Applies the jackknife to a statistic of interest using a list of samples usingDEFAULT_MATH_CONTEXT
as context.static Jackknife
compute(java.util.List<double[]> samples, Jackknife.Statistic f, java.math.MathContext mc)
Applies the jackknife to a statistic of interest using a list of samples.static java.math.BigDecimal[]
doubleArray2BigDecimalArray(double[] input)
java.lang.String
toString()
-
-
-
Field Detail
-
DEFAULT_MATH_CONTEXT
public static final java.math.MathContext DEFAULT_MATH_CONTEXT
-
bigEstimate
public final java.math.BigDecimal[] bigEstimate
A vector of high-precision estimates for a statistic of interest.
-
estimate
public final double[] estimate
A vector of estimates for a statistic of interest (obtained by invokingBigDecimal.doubleValue()
onbigEstimate
).
-
standardError
public final double[] standardError
A vector of (estimates of the) standard error parallel tobigEstimate
/estimate
.
-
IDENTITY
public static Jackknife.Statistic IDENTITY
A statistic that returns the sample. Useful to compute the average and the empirical standard error.
-
-
Method Detail
-
bigDecimalArray2DoubleArray
public static double[] bigDecimalArray2DoubleArray(java.math.BigDecimal[] input)
-
doubleArray2BigDecimalArray
public static java.math.BigDecimal[] doubleArray2BigDecimalArray(double[] input)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
compute
public static Jackknife compute(java.util.List<double[]> samples, Jackknife.Statistic f)
Applies the jackknife to a statistic of interest using a list of samples usingDEFAULT_MATH_CONTEXT
as context.- Parameters:
samples
- a list of samples (arrays of doubles of the same length).f
- a statistic of interest.- Returns:
- an instance of this class containing estimates of
f
and corresponding standard errors obtained by the jackknife on the given set of samples.
-
compute
public static Jackknife compute(java.util.List<double[]> samples, Jackknife.Statistic f, java.math.MathContext mc)
Applies the jackknife to a statistic of interest using a list of samples.- Parameters:
samples
- a list of samples (arrays of doubles of the same length).f
- a statistic of interest.mc
- the mathematical context to be used when dividing big decimals.- Returns:
- an instance of this class containing estimates of
f
and corresponding standard errors obtained by the jackknife on the given set of samples.
-
-