/** * @see org.apache.commons.math3.stat.inference.TTest#t(double, org.apache.commons.math3.stat.descriptive.StatisticalSummary) */ public static double t(final double mu, final StatisticalSummary sampleStats) throws NullArgumentException, NumberIsTooSmallException { return T_TEST.t(mu, sampleStats); }
/** * @see org.apache.commons.math3.stat.inference.TTest#t(double[], double[]) */ public static double t(final double[] sample1, final double[] sample2) throws NullArgumentException, NumberIsTooSmallException { return T_TEST.t(sample1, sample2); }
/** * @see org.apache.commons.math3.stat.inference.TTest#t(org.apache.commons.math3.stat.descriptive.StatisticalSummary, org.apache.commons.math3.stat.descriptive.StatisticalSummary) */ public static double t(final StatisticalSummary sampleStats1, final StatisticalSummary sampleStats2) throws NullArgumentException, NumberIsTooSmallException { return T_TEST.t(sampleStats1, sampleStats2); }
/** * @see org.apache.commons.math3.stat.inference.TTest#t(double, double[]) */ public static double t(final double mu, final double[] observed) throws NullArgumentException, NumberIsTooSmallException { return T_TEST.t(mu, observed); }
/** * Computes p-value for 2-sided, 1-sample t-test. * * @param m sample mean * @param mu constant to test against * @param v sample variance * @param n sample n * @return p-value * @throws MaxCountExceededException if an error occurs computing the p-value * @throws MathIllegalArgumentException if n is not greater than 1 */ protected double tTest(final double m, final double mu, final double v, final double n) throws MaxCountExceededException, MathIllegalArgumentException { final double t = FastMath.abs(t(m, mu, v, n)); // pass a null rng to avoid unneeded overhead as we will not sample from this distribution final TDistribution distribution = new TDistribution(null, n - 1); return 2.0 * distribution.cumulativeProbability(-t); }
/** * Computes a <a href="http://www.itl.nist.gov/div898/handbook/prc/section2/prc22.htm#formula"> * t statistic </a> given observed values and a comparison constant. * <p> * This statistic can be used to perform a one sample t-test for the mean. * </p><p> * <strong>Preconditions</strong>: <ul> * <li>The observed array length must be at least 2. * </li></ul></p> * * @param mu comparison constant * @param observed array of values * @return t statistic * @throws NullArgumentException if <code>observed</code> is <code>null</code> * @throws NumberIsTooSmallException if the length of <code>observed</code> is < 2 */ public double t(final double mu, final double[] observed) throws NullArgumentException, NumberIsTooSmallException { checkSampleData(observed); // No try-catch or advertised exception because args have just been checked return t(StatUtils.mean(observed), mu, StatUtils.variance(observed), observed.length); }
/** * Computes a <a href="http://www.itl.nist.gov/div898/handbook/prc/section2/prc22.htm#formula"> * t statistic </a> to use in comparing the mean of the dataset described by * <code>sampleStats</code> to <code>mu</code>. * <p> * This statistic can be used to perform a one sample t-test for the mean. * </p><p> * <strong>Preconditions</strong>: <ul> * <li><code>observed.getN() ≥ 2</code>. * </li></ul></p> * * @param mu comparison constant * @param sampleStats DescriptiveStatistics holding sample summary statitstics * @return t statistic * @throws NullArgumentException if <code>sampleStats</code> is <code>null</code> * @throws NumberIsTooSmallException if the number of samples is < 2 */ public double t(final double mu, final StatisticalSummary sampleStats) throws NullArgumentException, NumberIsTooSmallException { checkSampleData(sampleStats); return t(sampleStats.getMean(), mu, sampleStats.getVariance(), sampleStats.getN()); }
/** * Computes p-value for 2-sided, 2-sample t-test. * <p> * Does not assume subpopulation variances are equal. Degrees of freedom * are estimated from the data.</p> * * @param m1 first sample mean * @param m2 second sample mean * @param v1 first sample variance * @param v2 second sample variance * @param n1 first sample n * @param n2 second sample n * @return p-value * @throws MaxCountExceededException if an error occurs computing the p-value * @throws NotStrictlyPositiveException if the estimated degrees of freedom is not * strictly positive */ protected double tTest(final double m1, final double m2, final double v1, final double v2, final double n1, final double n2) throws MaxCountExceededException, NotStrictlyPositiveException { final double t = FastMath.abs(t(m1, m2, v1, v2, n1, n2)); final double degreesOfFreedom = df(v1, v2, n1, n2); // pass a null rng to avoid unneeded overhead as we will not sample from this distribution final TDistribution distribution = new TDistribution(null, degreesOfFreedom); return 2.0 * distribution.cumulativeProbability(-t); }
checkSampleData(sample2); double meanDifference = StatUtils.meanDifference(sample1, sample2); return t(meanDifference, 0, StatUtils.varianceDifference(sample1, sample2, meanDifference), sample1.length);
checkSampleData(sample2); return t(StatUtils.mean(sample1), StatUtils.mean(sample2), StatUtils.variance(sample1), StatUtils.variance(sample2), sample1.length, sample2.length);
return t(sampleStats1.getMean(), sampleStats2.getMean(), sampleStats1.getVariance(), sampleStats2.getVariance(), sampleStats1.getN(), sampleStats2.getN());
/** * @see org.apache.commons.math3.stat.inference.TTest#t(double, org.apache.commons.math3.stat.descriptive.StatisticalSummary) */ public static double t(final double mu, final StatisticalSummary sampleStats) throws NullArgumentException, NumberIsTooSmallException { return T_TEST.t(mu, sampleStats); }
/** * @see org.apache.commons.math3.stat.inference.TTest#t(double[], double[]) */ public static double t(final double[] sample1, final double[] sample2) throws NullArgumentException, NumberIsTooSmallException { return T_TEST.t(sample1, sample2); }
/** * @see org.apache.commons.math3.stat.inference.TTest#t(org.apache.commons.math3.stat.descriptive.StatisticalSummary, org.apache.commons.math3.stat.descriptive.StatisticalSummary) */ public static double t(final StatisticalSummary sampleStats1, final StatisticalSummary sampleStats2) throws NullArgumentException, NumberIsTooSmallException { return T_TEST.t(sampleStats1, sampleStats2); }
/** * @see org.apache.commons.math3.stat.inference.TTest#t(double, double[]) */ public static double t(final double mu, final double[] observed) throws NullArgumentException, NumberIsTooSmallException { return T_TEST.t(mu, observed); }
/** * Computes p-value for 2-sided, 1-sample t-test. * * @param m sample mean * @param mu constant to test against * @param v sample variance * @param n sample n * @return p-value * @throws MaxCountExceededException if an error occurs computing the p-value * @throws MathIllegalArgumentException if n is not greater than 1 */ protected double tTest(final double m, final double mu, final double v, final double n) throws MaxCountExceededException, MathIllegalArgumentException { final double t = Math.abs(t(m, mu, v, n)); // pass a null rng to avoid unneeded overhead as we will not sample from this distribution final TDistribution distribution = new TDistribution(null, n - 1); return 2.0 * distribution.cumulativeProbability(-t); }
/** * Computes p-value for 2-sided, 2-sample t-test. * <p> * Does not assume subpopulation variances are equal. Degrees of freedom * are estimated from the data.</p> * * @param m1 first sample mean * @param m2 second sample mean * @param v1 first sample variance * @param v2 second sample variance * @param n1 first sample n * @param n2 second sample n * @return p-value * @throws MaxCountExceededException if an error occurs computing the p-value * @throws NotStrictlyPositiveException if the estimated degrees of freedom is not * strictly positive */ protected double tTest(final double m1, final double m2, final double v1, final double v2, final double n1, final double n2) throws MaxCountExceededException, NotStrictlyPositiveException { final double t = Math.abs(t(m1, m2, v1, v2, n1, n2)); final double degreesOfFreedom = df(v1, v2, n1, n2); // pass a null rng to avoid unneeded overhead as we will not sample from this distribution final TDistribution distribution = new TDistribution(null, degreesOfFreedom); return 2.0 * distribution.cumulativeProbability(-t); }
/** * Computes p-value for 2-sided, 1-sample t-test. * * @param m sample mean * @param mu constant to test against * @param v sample variance * @param n sample n * @return p-value * @throws MaxCountExceededException if an error occurs computing the p-value * @throws MathIllegalArgumentException if n is not greater than 1 */ protected double tTest(final double m, final double mu, final double v, final double n) throws MaxCountExceededException, MathIllegalArgumentException { final double t = FastMath.abs(t(m, mu, v, n)); // pass a null rng to avoid unneeded overhead as we will not sample from this distribution final TDistribution distribution = new TDistribution(null, n - 1); return 2.0 * distribution.cumulativeProbability(-t); }
/** * Computes a <a href="http://www.itl.nist.gov/div898/handbook/prc/section2/prc22.htm#formula"> * t statistic </a> given observed values and a comparison constant. * <p> * This statistic can be used to perform a one sample t-test for the mean. * </p><p> * <strong>Preconditions</strong>: <ul> * <li>The observed array length must be at least 2. * </li></ul></p> * * @param mu comparison constant * @param observed array of values * @return t statistic * @throws NullArgumentException if <code>observed</code> is <code>null</code> * @throws NumberIsTooSmallException if the length of <code>observed</code> is < 2 */ public double t(final double mu, final double[] observed) throws NullArgumentException, NumberIsTooSmallException { checkSampleData(observed); // No try-catch or advertised exception because args have just been checked return t(StatUtils.mean(observed), mu, StatUtils.variance(observed), observed.length); }
/** * Computes a <a href="http://www.itl.nist.gov/div898/handbook/prc/section2/prc22.htm#formula"> * t statistic </a> given observed values and a comparison constant. * <p> * This statistic can be used to perform a one sample t-test for the mean. * </p><p> * <strong>Preconditions</strong>: <ul> * <li>The observed array length must be at least 2. * </li></ul></p> * * @param mu comparison constant * @param observed array of values * @return t statistic * @throws NullArgumentException if <code>observed</code> is <code>null</code> * @throws NumberIsTooSmallException if the length of <code>observed</code> is < 2 */ public double t(final double mu, final double[] observed) throws NullArgumentException, NumberIsTooSmallException { checkSampleData(observed); // No try-catch or advertised exception because args have just been checked return t(StatUtils.mean(observed), mu, StatUtils.variance(observed), observed.length); }