Java Code Examples for org.apache.commons.math.stat.StatUtils#meanDifference()

The following examples show how to use org.apache.commons.math.stat.StatUtils#meanDifference() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: astor   File: TTestImpl.java    License: GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the <i>observed significance level</i>, or 
 * <i> p-value</i>, associated with a paired, two-sample, two-tailed t-test 
 * based on the data in the input arrays.
 * <p>
 * The number returned is the smallest significance level
 * at which one can reject the null hypothesis that the mean of the paired
 * differences is 0 in favor of the two-sided alternative that the mean paired 
 * difference is not equal to 0. For a one-sided test, divide the returned 
 * value by 2.
 * <p>
 * This test is equivalent to a one-sample t-test computed using
 * {@link #tTest(double, double[])} with <code>mu = 0</code> and the sample
 * array consisting of the signed differences between corresponding elements of 
 * <code>sample1</code> and <code>sample2.</code>
 * <p>
 * <strong>Usage Note:</strong><br>
 * The validity of the p-value depends on the assumptions of the parametric
 * t-test procedure, as discussed 
 * <a href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html">
 * here</a>
 * <p>
 * <strong>Preconditions</strong>: <ul>
 * <li>The input array lengths must be the same and their common length must
 * be at least 2.
 * </li></ul>
 *
 * @param sample1 array of sample data values
 * @param sample2 array of sample data values
 * @return p-value for t-test
 * @throws IllegalArgumentException if the precondition is not met
 * @throws MathException if an error occurs computing the p-value
 */
public double pairedTTest(double[] sample1, double[] sample2)
    throws IllegalArgumentException, MathException {
    double meanDifference = StatUtils.meanDifference(sample1, sample2);
    return tTest(meanDifference, 0, 
            StatUtils.varianceDifference(sample1, sample2, meanDifference), 
            (double) sample1.length);
}
 
Example 2
/**
 * Returns the <i>observed significance level</i>, or 
 * <i> p-value</i>, associated with a paired, two-sample, two-tailed t-test 
 * based on the data in the input arrays.
 * <p>
 * The number returned is the smallest significance level
 * at which one can reject the null hypothesis that the mean of the paired
 * differences is 0 in favor of the two-sided alternative that the mean paired 
 * difference is not equal to 0. For a one-sided test, divide the returned 
 * value by 2.</p>
 * <p>
 * This test is equivalent to a one-sample t-test computed using
 * {@link #tTest(double, double[])} with <code>mu = 0</code> and the sample
 * array consisting of the signed differences between corresponding elements of 
 * <code>sample1</code> and <code>sample2.</code></p>
 * <p>
 * <strong>Usage Note:</strong><br>
 * The validity of the p-value depends on the assumptions of the parametric
 * t-test procedure, as discussed 
 * <a href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html">
 * here</a></p>
 * <p>
 * <strong>Preconditions</strong>: <ul>
 * <li>The input array lengths must be the same and their common length must
 * be at least 2.
 * </li></ul></p>
 *
 * @param sample1 array of sample data values
 * @param sample2 array of sample data values
 * @return p-value for t-test
 * @throws IllegalArgumentException if the precondition is not met
 * @throws MathException if an error occurs computing the p-value
 */
public double pairedTTest(double[] sample1, double[] sample2)
    throws IllegalArgumentException, MathException {
    double meanDifference = StatUtils.meanDifference(sample1, sample2);
    return tTest(meanDifference, 0, 
            StatUtils.varianceDifference(sample1, sample2, meanDifference), 
            (double) sample1.length);
}
 
Example 3
Source Project: astor   File: TTestImpl.java    License: GNU General Public License v2.0 3 votes vote down vote up
/**
 * Computes a paired, 2-sample t-statistic based on the data in the input
 * arrays.  The t-statistic returned is equivalent to what would be returned by
 * computing the one-sample t-statistic {@link #t(double, double[])}, with
 * <code>mu = 0</code> and the sample array consisting of the (signed)
 * differences between corresponding entries in <code>sample1</code> and
 * <code>sample2.</code>
 * <p>
 * <strong>Preconditions</strong>: <ul>
 * <li>The input arrays must have the same length and their common length
 * must be at least 2.
 * </li></ul></p>
 *
 * @param sample1 array of sample data values
 * @param sample2 array of sample data values
 * @return t statistic
 * @throws IllegalArgumentException if the precondition is not met
 * @throws MathException if the statistic can not be computed do to a
 *         convergence or other numerical error.
 */
public double pairedT(double[] sample1, double[] sample2)
    throws IllegalArgumentException, MathException {
    checkSampleData(sample1);
    checkSampleData(sample2);
    double meanDifference = StatUtils.meanDifference(sample1, sample2);
    return t(meanDifference, 0,
            StatUtils.varianceDifference(sample1, sample2, meanDifference),
            sample1.length);
}
 
Example 4
Source Project: astor   File: TTestImpl.java    License: GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the <i>observed significance level</i>, or
 * <i> p-value</i>, associated with a paired, two-sample, two-tailed t-test
 * based on the data in the input arrays.
 * <p>
 * The number returned is the smallest significance level
 * at which one can reject the null hypothesis that the mean of the paired
 * differences is 0 in favor of the two-sided alternative that the mean paired
 * difference is not equal to 0. For a one-sided test, divide the returned
 * value by 2.</p>
 * <p>
 * This test is equivalent to a one-sample t-test computed using
 * {@link #tTest(double, double[])} with <code>mu = 0</code> and the sample
 * array consisting of the signed differences between corresponding elements of
 * <code>sample1</code> and <code>sample2.</code></p>
 * <p>
 * <strong>Usage Note:</strong><br>
 * The validity of the p-value depends on the assumptions of the parametric
 * t-test procedure, as discussed
 * <a href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html">
 * here</a></p>
 * <p>
 * <strong>Preconditions</strong>: <ul>
 * <li>The input array lengths must be the same and their common length must
 * be at least 2.
 * </li></ul></p>
 *
 * @param sample1 array of sample data values
 * @param sample2 array of sample data values
 * @return p-value for t-test
 * @throws IllegalArgumentException if the precondition is not met
 * @throws MathException if an error occurs computing the p-value
 */
public double pairedTTest(double[] sample1, double[] sample2)
    throws IllegalArgumentException, MathException {
    double meanDifference = StatUtils.meanDifference(sample1, sample2);
    return tTest(meanDifference, 0,
            StatUtils.varianceDifference(sample1, sample2, meanDifference),
            sample1.length);
}
 
Example 5
Source Project: astor   File: TTestImpl.java    License: GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the <i>observed significance level</i>, or
 * <i> p-value</i>, associated with a paired, two-sample, two-tailed t-test
 * based on the data in the input arrays.
 * <p>
 * The number returned is the smallest significance level
 * at which one can reject the null hypothesis that the mean of the paired
 * differences is 0 in favor of the two-sided alternative that the mean paired
 * difference is not equal to 0. For a one-sided test, divide the returned
 * value by 2.</p>
 * <p>
 * This test is equivalent to a one-sample t-test computed using
 * {@link #tTest(double, double[])} with <code>mu = 0</code> and the sample
 * array consisting of the signed differences between corresponding elements of
 * <code>sample1</code> and <code>sample2.</code></p>
 * <p>
 * <strong>Usage Note:</strong><br>
 * The validity of the p-value depends on the assumptions of the parametric
 * t-test procedure, as discussed
 * <a href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html">
 * here</a></p>
 * <p>
 * <strong>Preconditions</strong>: <ul>
 * <li>The input array lengths must be the same and their common length must
 * be at least 2.
 * </li></ul></p>
 *
 * @param sample1 array of sample data values
 * @param sample2 array of sample data values
 * @return p-value for t-test
 * @throws IllegalArgumentException if the precondition is not met
 * @throws MathException if an error occurs computing the p-value
 */
public double pairedTTest(double[] sample1, double[] sample2)
    throws IllegalArgumentException, MathException {
    double meanDifference = StatUtils.meanDifference(sample1, sample2);
    return tTest(meanDifference, 0,
            StatUtils.varianceDifference(sample1, sample2, meanDifference),
            sample1.length);
}
 
Example 6
Source Project: astor   File: TTestImpl.java    License: GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the <i>observed significance level</i>, or 
 * <i> p-value</i>, associated with a paired, two-sample, two-tailed t-test 
 * based on the data in the input arrays.
 * <p>
 * The number returned is the smallest significance level
 * at which one can reject the null hypothesis that the mean of the paired
 * differences is 0 in favor of the two-sided alternative that the mean paired 
 * difference is not equal to 0. For a one-sided test, divide the returned 
 * value by 2.</p>
 * <p>
 * This test is equivalent to a one-sample t-test computed using
 * {@link #tTest(double, double[])} with <code>mu = 0</code> and the sample
 * array consisting of the signed differences between corresponding elements of 
 * <code>sample1</code> and <code>sample2.</code></p>
 * <p>
 * <strong>Usage Note:</strong><br>
 * The validity of the p-value depends on the assumptions of the parametric
 * t-test procedure, as discussed 
 * <a href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html">
 * here</a></p>
 * <p>
 * <strong>Preconditions</strong>: <ul>
 * <li>The input array lengths must be the same and their common length must
 * be at least 2.
 * </li></ul></p>
 *
 * @param sample1 array of sample data values
 * @param sample2 array of sample data values
 * @return p-value for t-test
 * @throws IllegalArgumentException if the precondition is not met
 * @throws MathException if an error occurs computing the p-value
 */
public double pairedTTest(double[] sample1, double[] sample2)
    throws IllegalArgumentException, MathException {
    double meanDifference = StatUtils.meanDifference(sample1, sample2);
    return tTest(meanDifference, 0, 
            StatUtils.varianceDifference(sample1, sample2, meanDifference), 
            sample1.length);
}
 
Example 7
Source Project: astor   File: TTestImpl.java    License: GNU General Public License v2.0 3 votes vote down vote up
/**
 * Computes a paired, 2-sample t-statistic based on the data in the input
 * arrays.  The t-statistic returned is equivalent to what would be returned by
 * computing the one-sample t-statistic {@link #t(double, double[])}, with
 * <code>mu = 0</code> and the sample array consisting of the (signed)
 * differences between corresponding entries in <code>sample1</code> and
 * <code>sample2.</code>
 * <p>
 * <strong>Preconditions</strong>: <ul>
 * <li>The input arrays must have the same length and their common length
 * must be at least 2.
 * </li></ul></p>
 *
 * @param sample1 array of sample data values
 * @param sample2 array of sample data values
 * @return t statistic
 * @throws IllegalArgumentException if the precondition is not met
 * @throws MathException if the statistic can not be computed do to a
 *         convergence or other numerical error.
 */
public double pairedT(double[] sample1, double[] sample2)
    throws IllegalArgumentException, MathException {
    checkSampleData(sample1);
    checkSampleData(sample2);
    double meanDifference = StatUtils.meanDifference(sample1, sample2);
    return t(meanDifference, 0,
            StatUtils.varianceDifference(sample1, sample2, meanDifference),
            sample1.length);
}
 
Example 8
Source Project: astor   File: TTestImpl.java    License: GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the <i>observed significance level</i>, or 
 * <i> p-value</i>, associated with a paired, two-sample, two-tailed t-test 
 * based on the data in the input arrays.
 * <p>
 * The number returned is the smallest significance level
 * at which one can reject the null hypothesis that the mean of the paired
 * differences is 0 in favor of the two-sided alternative that the mean paired 
 * difference is not equal to 0. For a one-sided test, divide the returned 
 * value by 2.</p>
 * <p>
 * This test is equivalent to a one-sample t-test computed using
 * {@link #tTest(double, double[])} with <code>mu = 0</code> and the sample
 * array consisting of the signed differences between corresponding elements of 
 * <code>sample1</code> and <code>sample2.</code></p>
 * <p>
 * <strong>Usage Note:</strong><br>
 * The validity of the p-value depends on the assumptions of the parametric
 * t-test procedure, as discussed 
 * <a href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html">
 * here</a></p>
 * <p>
 * <strong>Preconditions</strong>: <ul>
 * <li>The input array lengths must be the same and their common length must
 * be at least 2.
 * </li></ul></p>
 *
 * @param sample1 array of sample data values
 * @param sample2 array of sample data values
 * @return p-value for t-test
 * @throws IllegalArgumentException if the precondition is not met
 * @throws MathException if an error occurs computing the p-value
 */
public double pairedTTest(double[] sample1, double[] sample2)
    throws IllegalArgumentException, MathException {
    double meanDifference = StatUtils.meanDifference(sample1, sample2);
    return tTest(meanDifference, 0, 
            StatUtils.varianceDifference(sample1, sample2, meanDifference), 
            sample1.length);
}
 
Example 9
Source Project: astor   File: TTestImpl.java    License: GNU General Public License v2.0 3 votes vote down vote up
/**
 * Computes a paired, 2-sample t-statistic based on the data in the input 
 * arrays.  The t-statistic returned is equivalent to what would be returned by
 * computing the one-sample t-statistic {@link #t(double, double[])}, with
 * <code>mu = 0</code> and the sample array consisting of the (signed) 
 * differences between corresponding entries in <code>sample1</code> and 
 * <code>sample2.</code>
 * <p>
 * <strong>Preconditions</strong>: <ul>
 * <li>The input arrays must have the same length and their common length
 * must be at least 2.
 * </li></ul></p>
 *
 * @param sample1 array of sample data values
 * @param sample2 array of sample data values
 * @return t statistic
 * @throws IllegalArgumentException if the precondition is not met
 * @throws MathException if the statistic can not be computed do to a
 *         convergence or other numerical error.
 */
public double pairedT(double[] sample1, double[] sample2)
    throws IllegalArgumentException, MathException {
    checkSampleData(sample1);
    checkSampleData(sample2);
    double meanDifference = StatUtils.meanDifference(sample1, sample2);
    return t(meanDifference, 0,  
            StatUtils.varianceDifference(sample1, sample2, meanDifference),
            sample1.length);
}
 
Example 10
Source Project: astor   File: TTestImpl.java    License: GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the <i>observed significance level</i>, or
 * <i> p-value</i>, associated with a paired, two-sample, two-tailed t-test
 * based on the data in the input arrays.
 * <p>
 * The number returned is the smallest significance level
 * at which one can reject the null hypothesis that the mean of the paired
 * differences is 0 in favor of the two-sided alternative that the mean paired
 * difference is not equal to 0. For a one-sided test, divide the returned
 * value by 2.</p>
 * <p>
 * This test is equivalent to a one-sample t-test computed using
 * {@link #tTest(double, double[])} with <code>mu = 0</code> and the sample
 * array consisting of the signed differences between corresponding elements of
 * <code>sample1</code> and <code>sample2.</code></p>
 * <p>
 * <strong>Usage Note:</strong><br>
 * The validity of the p-value depends on the assumptions of the parametric
 * t-test procedure, as discussed
 * <a href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html">
 * here</a></p>
 * <p>
 * <strong>Preconditions</strong>: <ul>
 * <li>The input array lengths must be the same and their common length must
 * be at least 2.
 * </li></ul></p>
 *
 * @param sample1 array of sample data values
 * @param sample2 array of sample data values
 * @return p-value for t-test
 * @throws IllegalArgumentException if the precondition is not met
 * @throws MathException if an error occurs computing the p-value
 */
public double pairedTTest(double[] sample1, double[] sample2)
    throws IllegalArgumentException, MathException {
    double meanDifference = StatUtils.meanDifference(sample1, sample2);
    return tTest(meanDifference, 0,
            StatUtils.varianceDifference(sample1, sample2, meanDifference),
            sample1.length);
}
 
Example 11
Source Project: astor   File: TTestImpl.java    License: GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the <i>observed significance level</i>, or
 * <i> p-value</i>, associated with a paired, two-sample, two-tailed t-test
 * based on the data in the input arrays.
 * <p>
 * The number returned is the smallest significance level
 * at which one can reject the null hypothesis that the mean of the paired
 * differences is 0 in favor of the two-sided alternative that the mean paired
 * difference is not equal to 0. For a one-sided test, divide the returned
 * value by 2.</p>
 * <p>
 * This test is equivalent to a one-sample t-test computed using
 * {@link #tTest(double, double[])} with <code>mu = 0</code> and the sample
 * array consisting of the signed differences between corresponding elements of
 * <code>sample1</code> and <code>sample2.</code></p>
 * <p>
 * <strong>Usage Note:</strong><br>
 * The validity of the p-value depends on the assumptions of the parametric
 * t-test procedure, as discussed
 * <a href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html">
 * here</a></p>
 * <p>
 * <strong>Preconditions</strong>: <ul>
 * <li>The input array lengths must be the same and their common length must
 * be at least 2.
 * </li></ul></p>
 *
 * @param sample1 array of sample data values
 * @param sample2 array of sample data values
 * @return p-value for t-test
 * @throws IllegalArgumentException if the precondition is not met
 * @throws MathException if an error occurs computing the p-value
 */
public double pairedTTest(double[] sample1, double[] sample2)
    throws IllegalArgumentException, MathException {
    double meanDifference = StatUtils.meanDifference(sample1, sample2);
    return tTest(meanDifference, 0,
            StatUtils.varianceDifference(sample1, sample2, meanDifference),
            sample1.length);
}
 
Example 12
Source Project: astor   File: TTestImpl.java    License: GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the <i>observed significance level</i>, or
 * <i> p-value</i>, associated with a paired, two-sample, two-tailed t-test
 * based on the data in the input arrays.
 * <p>
 * The number returned is the smallest significance level
 * at which one can reject the null hypothesis that the mean of the paired
 * differences is 0 in favor of the two-sided alternative that the mean paired
 * difference is not equal to 0. For a one-sided test, divide the returned
 * value by 2.</p>
 * <p>
 * This test is equivalent to a one-sample t-test computed using
 * {@link #tTest(double, double[])} with <code>mu = 0</code> and the sample
 * array consisting of the signed differences between corresponding elements of
 * <code>sample1</code> and <code>sample2.</code></p>
 * <p>
 * <strong>Usage Note:</strong><br>
 * The validity of the p-value depends on the assumptions of the parametric
 * t-test procedure, as discussed
 * <a href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html">
 * here</a></p>
 * <p>
 * <strong>Preconditions</strong>: <ul>
 * <li>The input array lengths must be the same and their common length must
 * be at least 2.
 * </li></ul></p>
 *
 * @param sample1 array of sample data values
 * @param sample2 array of sample data values
 * @return p-value for t-test
 * @throws IllegalArgumentException if the precondition is not met
 * @throws MathException if an error occurs computing the p-value
 */
public double pairedTTest(double[] sample1, double[] sample2)
    throws IllegalArgumentException, MathException {
    double meanDifference = StatUtils.meanDifference(sample1, sample2);
    return tTest(meanDifference, 0,
            StatUtils.varianceDifference(sample1, sample2, meanDifference),
            sample1.length);
}
 
Example 13
Source Project: astor   File: TTestImpl.java    License: GNU General Public License v2.0 3 votes vote down vote up
/**
 * Computes a paired, 2-sample t-statistic based on the data in the input 
 * arrays.  The t-statistic returned is equivalent to what would be returned by
 * computing the one-sample t-statistic {@link #t(double, double[])}, with
 * <code>mu = 0</code> and the sample array consisting of the (signed) 
 * differences between corresponding entries in <code>sample1</code> and 
 * <code>sample2.</code>
 * <p>
 * <strong>Preconditions</strong>: <ul>
 * <li>The input arrays must have the same length and their common length
 * must be at least 2.
 * </li></ul>
 *
 * @param sample1 array of sample data values
 * @param sample2 array of sample data values
 * @return t statistic
 * @throws IllegalArgumentException if the precondition is not met
 * @throws MathException if the statistic can not be computed do to a
 *         convergence or other numerical error.
 */
public double pairedT(double[] sample1, double[] sample2)
    throws IllegalArgumentException, MathException {
    if ((sample1 == null) || (sample2 == null ||
            Math.min(sample1.length, sample2.length) < 2)) {
        throw new IllegalArgumentException("insufficient data for t statistic");
    }
    double meanDifference = StatUtils.meanDifference(sample1, sample2);
    return t(meanDifference, 0,  
            StatUtils.varianceDifference(sample1, sample2, meanDifference),
            (double) sample1.length);
}
 
Example 14
Source Project: astor   File: TTestImpl.java    License: GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the <i>observed significance level</i>, or
 * <i> p-value</i>, associated with a paired, two-sample, two-tailed t-test
 * based on the data in the input arrays.
 * <p>
 * The number returned is the smallest significance level
 * at which one can reject the null hypothesis that the mean of the paired
 * differences is 0 in favor of the two-sided alternative that the mean paired
 * difference is not equal to 0. For a one-sided test, divide the returned
 * value by 2.</p>
 * <p>
 * This test is equivalent to a one-sample t-test computed using
 * {@link #tTest(double, double[])} with <code>mu = 0</code> and the sample
 * array consisting of the signed differences between corresponding elements of
 * <code>sample1</code> and <code>sample2.</code></p>
 * <p>
 * <strong>Usage Note:</strong><br>
 * The validity of the p-value depends on the assumptions of the parametric
 * t-test procedure, as discussed
 * <a href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html">
 * here</a></p>
 * <p>
 * <strong>Preconditions</strong>: <ul>
 * <li>The input array lengths must be the same and their common length must
 * be at least 2.
 * </li></ul></p>
 *
 * @param sample1 array of sample data values
 * @param sample2 array of sample data values
 * @return p-value for t-test
 * @throws IllegalArgumentException if the precondition is not met
 * @throws MathException if an error occurs computing the p-value
 */
public double pairedTTest(double[] sample1, double[] sample2)
    throws IllegalArgumentException, MathException {
    double meanDifference = StatUtils.meanDifference(sample1, sample2);
    return tTest(meanDifference, 0,
            StatUtils.varianceDifference(sample1, sample2, meanDifference),
            sample1.length);
}
 
Example 15
Source Project: astor   File: TTestImpl.java    License: GNU General Public License v2.0 3 votes vote down vote up
/**
 * Computes a paired, 2-sample t-statistic based on the data in the input
 * arrays.  The t-statistic returned is equivalent to what would be returned by
 * computing the one-sample t-statistic {@link #t(double, double[])}, with
 * <code>mu = 0</code> and the sample array consisting of the (signed)
 * differences between corresponding entries in <code>sample1</code> and
 * <code>sample2.</code>
 * <p>
 * <strong>Preconditions</strong>: <ul>
 * <li>The input arrays must have the same length and their common length
 * must be at least 2.
 * </li></ul></p>
 *
 * @param sample1 array of sample data values
 * @param sample2 array of sample data values
 * @return t statistic
 * @throws IllegalArgumentException if the precondition is not met
 * @throws MathException if the statistic can not be computed do to a
 *         convergence or other numerical error.
 */
public double pairedT(double[] sample1, double[] sample2)
    throws IllegalArgumentException, MathException {
    checkSampleData(sample1);
    checkSampleData(sample2);
    double meanDifference = StatUtils.meanDifference(sample1, sample2);
    return t(meanDifference, 0,
            StatUtils.varianceDifference(sample1, sample2, meanDifference),
            sample1.length);
}
 
Example 16
Source Project: astor   File: TTestImpl.java    License: GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the <i>observed significance level</i>, or
 * <i> p-value</i>, associated with a paired, two-sample, two-tailed t-test
 * based on the data in the input arrays.
 * <p>
 * The number returned is the smallest significance level
 * at which one can reject the null hypothesis that the mean of the paired
 * differences is 0 in favor of the two-sided alternative that the mean paired
 * difference is not equal to 0. For a one-sided test, divide the returned
 * value by 2.</p>
 * <p>
 * This test is equivalent to a one-sample t-test computed using
 * {@link #tTest(double, double[])} with <code>mu = 0</code> and the sample
 * array consisting of the signed differences between corresponding elements of
 * <code>sample1</code> and <code>sample2.</code></p>
 * <p>
 * <strong>Usage Note:</strong><br>
 * The validity of the p-value depends on the assumptions of the parametric
 * t-test procedure, as discussed
 * <a href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html">
 * here</a></p>
 * <p>
 * <strong>Preconditions</strong>: <ul>
 * <li>The input array lengths must be the same and their common length must
 * be at least 2.
 * </li></ul></p>
 *
 * @param sample1 array of sample data values
 * @param sample2 array of sample data values
 * @return p-value for t-test
 * @throws IllegalArgumentException if the precondition is not met
 * @throws MathException if an error occurs computing the p-value
 */
public double pairedTTest(double[] sample1, double[] sample2)
    throws IllegalArgumentException, MathException {
    double meanDifference = StatUtils.meanDifference(sample1, sample2);
    return tTest(meanDifference, 0,
            StatUtils.varianceDifference(sample1, sample2, meanDifference),
            sample1.length);
}
 
Example 17
Source Project: astor   File: TTestImpl.java    License: GNU General Public License v2.0 3 votes vote down vote up
/**
 * Computes a paired, 2-sample t-statistic based on the data in the input 
 * arrays.  The t-statistic returned is equivalent to what would be returned by
 * computing the one-sample t-statistic {@link #t(double, double[])}, with
 * <code>mu = 0</code> and the sample array consisting of the (signed) 
 * differences between corresponding entries in <code>sample1</code> and 
 * <code>sample2.</code>
 * <p>
 * <strong>Preconditions</strong>: <ul>
 * <li>The input arrays must have the same length and their common length
 * must be at least 2.
 * </li></ul></p>
 *
 * @param sample1 array of sample data values
 * @param sample2 array of sample data values
 * @return t statistic
 * @throws IllegalArgumentException if the precondition is not met
 * @throws MathException if the statistic can not be computed do to a
 *         convergence or other numerical error.
 */
public double pairedT(double[] sample1, double[] sample2)
    throws IllegalArgumentException, MathException {
    checkSampleData(sample1);
    checkSampleData(sample2);
    double meanDifference = StatUtils.meanDifference(sample1, sample2);
    return t(meanDifference, 0,  
            StatUtils.varianceDifference(sample1, sample2, meanDifference),
            sample1.length);
}
 
Example 18
Source Project: astor   File: TTestImpl.java    License: GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the <i>observed significance level</i>, or
 * <i> p-value</i>, associated with a paired, two-sample, two-tailed t-test
 * based on the data in the input arrays.
 * <p>
 * The number returned is the smallest significance level
 * at which one can reject the null hypothesis that the mean of the paired
 * differences is 0 in favor of the two-sided alternative that the mean paired
 * difference is not equal to 0. For a one-sided test, divide the returned
 * value by 2.</p>
 * <p>
 * This test is equivalent to a one-sample t-test computed using
 * {@link #tTest(double, double[])} with <code>mu = 0</code> and the sample
 * array consisting of the signed differences between corresponding elements of
 * <code>sample1</code> and <code>sample2.</code></p>
 * <p>
 * <strong>Usage Note:</strong><br>
 * The validity of the p-value depends on the assumptions of the parametric
 * t-test procedure, as discussed
 * <a href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html">
 * here</a></p>
 * <p>
 * <strong>Preconditions</strong>: <ul>
 * <li>The input array lengths must be the same and their common length must
 * be at least 2.
 * </li></ul></p>
 *
 * @param sample1 array of sample data values
 * @param sample2 array of sample data values
 * @return p-value for t-test
 * @throws IllegalArgumentException if the precondition is not met
 * @throws MathException if an error occurs computing the p-value
 */
public double pairedTTest(double[] sample1, double[] sample2)
    throws IllegalArgumentException, MathException {
    double meanDifference = StatUtils.meanDifference(sample1, sample2);
    return tTest(meanDifference, 0,
            StatUtils.varianceDifference(sample1, sample2, meanDifference),
            sample1.length);
}
 
Example 19
Source Project: astor   File: TTestImpl.java    License: GNU General Public License v2.0 3 votes vote down vote up
/**
 * Computes a paired, 2-sample t-statistic based on the data in the input
 * arrays.  The t-statistic returned is equivalent to what would be returned by
 * computing the one-sample t-statistic {@link #t(double, double[])}, with
 * <code>mu = 0</code> and the sample array consisting of the (signed)
 * differences between corresponding entries in <code>sample1</code> and
 * <code>sample2.</code>
 * <p>
 * <strong>Preconditions</strong>: <ul>
 * <li>The input arrays must have the same length and their common length
 * must be at least 2.
 * </li></ul></p>
 *
 * @param sample1 array of sample data values
 * @param sample2 array of sample data values
 * @return t statistic
 * @throws IllegalArgumentException if the precondition is not met
 * @throws MathException if the statistic can not be computed do to a
 *         convergence or other numerical error.
 */
public double pairedT(double[] sample1, double[] sample2)
    throws IllegalArgumentException, MathException {
    checkSampleData(sample1);
    checkSampleData(sample2);
    double meanDifference = StatUtils.meanDifference(sample1, sample2);
    return t(meanDifference, 0,
            StatUtils.varianceDifference(sample1, sample2, meanDifference),
            sample1.length);
}
 
Example 20
Source Project: astor   File: TTestImpl.java    License: GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the <i>observed significance level</i>, or
 * <i> p-value</i>, associated with a paired, two-sample, two-tailed t-test
 * based on the data in the input arrays.
 * <p>
 * The number returned is the smallest significance level
 * at which one can reject the null hypothesis that the mean of the paired
 * differences is 0 in favor of the two-sided alternative that the mean paired
 * difference is not equal to 0. For a one-sided test, divide the returned
 * value by 2.</p>
 * <p>
 * This test is equivalent to a one-sample t-test computed using
 * {@link #tTest(double, double[])} with <code>mu = 0</code> and the sample
 * array consisting of the signed differences between corresponding elements of
 * <code>sample1</code> and <code>sample2.</code></p>
 * <p>
 * <strong>Usage Note:</strong><br>
 * The validity of the p-value depends on the assumptions of the parametric
 * t-test procedure, as discussed
 * <a href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html">
 * here</a></p>
 * <p>
 * <strong>Preconditions</strong>: <ul>
 * <li>The input array lengths must be the same and their common length must
 * be at least 2.
 * </li></ul></p>
 *
 * @param sample1 array of sample data values
 * @param sample2 array of sample data values
 * @return p-value for t-test
 * @throws IllegalArgumentException if the precondition is not met
 * @throws MathException if an error occurs computing the p-value
 */
public double pairedTTest(double[] sample1, double[] sample2)
    throws IllegalArgumentException, MathException {
    double meanDifference = StatUtils.meanDifference(sample1, sample2);
    return tTest(meanDifference, 0,
            StatUtils.varianceDifference(sample1, sample2, meanDifference),
            sample1.length);
}