1dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond/* 2dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Licensed to the Apache Software Foundation (ASF) under one or more 3dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * contributor license agreements. See the NOTICE file distributed with 4dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * this work for additional information regarding copyright ownership. 5dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The ASF licenses this file to You under the Apache License, Version 2.0 6dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * (the "License"); you may not use this file except in compliance with 7dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * the License. You may obtain a copy of the License at 8dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 9dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * http://www.apache.org/licenses/LICENSE-2.0 10dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 11dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Unless required by applicable law or agreed to in writing, software 12dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * distributed under the License is distributed on an "AS IS" BASIS, 13dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * See the License for the specific language governing permissions and 15dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * limitations under the License. 16dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 17dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondpackage org.apache.commons.math.stat.inference; 18dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 19dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.MathException; 20dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport org.apache.commons.math.stat.descriptive.StatisticalSummary; 21dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 22dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond/** 23dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * An interface for Student's t-tests. 24dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 25dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Tests can be:<ul> 26dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>One-sample or two-sample</li> 27dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>One-sided or two-sided</li> 28dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>Paired or unpaired (for two-sample tests)</li> 29dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>Homoscedastic (equal variance assumption) or heteroscedastic 30dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * (for two sample tests)</li> 31dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>Fixed significance level (boolean-valued) or returning p-values. 32dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ul></p> 33dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 34dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Test statistics are available for all tests. Methods including "Test" in 35dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * in their names perform tests, all other methods return t-statistics. Among 36dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * the "Test" methods, <code>double-</code>valued methods return p-values; 37dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <code>boolean-</code>valued methods perform fixed significance level tests. 38dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Significance levels are always specified as numbers between 0 and 0.5 39dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * (e.g. tests at the 95% level use <code>alpha=0.05</code>).</p> 40dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 41dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Input to tests can be either <code>double[]</code> arrays or 42dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * {@link StatisticalSummary} instances.</p> 43dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 44dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 45dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @version $Revision: 811786 $ $Date: 2009-09-06 11:36:08 +0200 (dim. 06 sept. 2009) $ 46dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 47dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondpublic interface TTest { 48dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 49dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Computes a paired, 2-sample t-statistic based on the data in the input 50dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * arrays. The t-statistic returned is equivalent to what would be returned by 51dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * computing the one-sample t-statistic {@link #t(double, double[])}, with 52dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <code>mu = 0</code> and the sample array consisting of the (signed) 53dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * differences between corresponding entries in <code>sample1</code> and 54dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <code>sample2.</code> 55dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 56dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Preconditions</strong>: <ul> 57dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>The input arrays must have the same length and their common length 58dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * must be at least 2. 59dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ul></p> 60dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 61dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sample1 array of sample data values 62dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sample2 array of sample data values 63dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @return t statistic 64dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws IllegalArgumentException if the precondition is not met 65dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws MathException if the statistic can not be computed do to a 66dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * convergence or other numerical error. 67dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 68dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double pairedT(double[] sample1, double[] sample2) 69dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond throws IllegalArgumentException, MathException; 70dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 71dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Returns the <i>observed significance level</i>, or 72dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <i> p-value</i>, associated with a paired, two-sample, two-tailed t-test 73dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * based on the data in the input arrays. 74dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 75dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The number returned is the smallest significance level 76dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * at which one can reject the null hypothesis that the mean of the paired 77dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * differences is 0 in favor of the two-sided alternative that the mean paired 78dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * difference is not equal to 0. For a one-sided test, divide the returned 79dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * value by 2.</p> 80dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 81dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * This test is equivalent to a one-sample t-test computed using 82dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * {@link #tTest(double, double[])} with <code>mu = 0</code> and the sample 83dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * array consisting of the signed differences between corresponding elements of 84dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <code>sample1</code> and <code>sample2.</code></p> 85dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 86dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Usage Note:</strong><br> 87dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The validity of the p-value depends on the assumptions of the parametric 88dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * t-test procedure, as discussed 89dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <a href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html"> 90dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * here</a></p> 91dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 92dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Preconditions</strong>: <ul> 93dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>The input array lengths must be the same and their common length must 94dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * be at least 2. 95dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ul></p> 96dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 97dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sample1 array of sample data values 98dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sample2 array of sample data values 99dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @return p-value for t-test 100dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws IllegalArgumentException if the precondition is not met 101dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws MathException if an error occurs computing the p-value 102dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 103dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double pairedTTest(double[] sample1, double[] sample2) 104dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond throws IllegalArgumentException, MathException; 105dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 106dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Performs a paired t-test evaluating the null hypothesis that the 107dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * mean of the paired differences between <code>sample1</code> and 108dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <code>sample2</code> is 0 in favor of the two-sided alternative that the 109dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * mean paired difference is not equal to 0, with significance level 110dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <code>alpha</code>. 111dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 112dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Returns <code>true</code> iff the null hypothesis can be rejected with 113dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * confidence <code>1 - alpha</code>. To perform a 1-sided test, use 114dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <code>alpha * 2</code></p> 115dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 116dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Usage Note:</strong><br> 117dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The validity of the test depends on the assumptions of the parametric 118dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * t-test procedure, as discussed 119dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <a href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html"> 120dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * here</a></p> 121dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 122dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Preconditions</strong>: <ul> 123dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>The input array lengths must be the same and their common length 124dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * must be at least 2. 125dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li> 126dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li> <code> 0 < alpha < 0.5 </code> 127dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ul></p> 128dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 129dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sample1 array of sample data values 130dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sample2 array of sample data values 131dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param alpha significance level of the test 132dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @return true if the null hypothesis can be rejected with 133dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * confidence 1 - alpha 134dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws IllegalArgumentException if the preconditions are not met 135dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws MathException if an error occurs performing the test 136dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 137dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond boolean pairedTTest( 138dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double[] sample1, 139dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double[] sample2, 140dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double alpha) 141dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond throws IllegalArgumentException, MathException; 142dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 143dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Computes a <a href="http://www.itl.nist.gov/div898/handbook/prc/section2/prc22.htm#formula"> 144dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * t statistic </a> given observed values and a comparison constant. 145dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 146dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * This statistic can be used to perform a one sample t-test for the mean. 147dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </p><p> 148dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Preconditions</strong>: <ul> 149dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>The observed array length must be at least 2. 150dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ul></p> 151dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 152dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param mu comparison constant 153dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param observed array of values 154dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @return t statistic 155dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws IllegalArgumentException if input array length is less than 2 156dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 157dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double t(double mu, double[] observed) 158dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond throws IllegalArgumentException; 159dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 160dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Computes a <a href="http://www.itl.nist.gov/div898/handbook/prc/section2/prc22.htm#formula"> 161dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * t statistic </a> to use in comparing the mean of the dataset described by 162dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <code>sampleStats</code> to <code>mu</code>. 163dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 164dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * This statistic can be used to perform a one sample t-test for the mean. 165dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </p><p> 166dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Preconditions</strong>: <ul> 167dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li><code>observed.getN() > = 2</code>. 168dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ul></p> 169dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 170dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param mu comparison constant 171dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sampleStats DescriptiveStatistics holding sample summary statitstics 172dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @return t statistic 173dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws IllegalArgumentException if the precondition is not met 174dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 175dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double t(double mu, StatisticalSummary sampleStats) 176dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond throws IllegalArgumentException; 177dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 178dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Computes a 2-sample t statistic, under the hypothesis of equal 179dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * subpopulation variances. To compute a t-statistic without the 180dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * equal variances hypothesis, use {@link #t(double[], double[])}. 181dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 182dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * This statistic can be used to perform a (homoscedastic) two-sample 183dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * t-test to compare sample means.</p> 184dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 185dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The t-statisitc is</p> 186dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 187dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <code> t = (m1 - m2) / (sqrt(1/n1 +1/n2) sqrt(var))</code> 188dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </p><p> 189dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * where <strong><code>n1</code></strong> is the size of first sample; 190dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong><code> n2</code></strong> is the size of second sample; 191dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong><code> m1</code></strong> is the mean of first sample; 192dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong><code> m2</code></strong> is the mean of second sample</li> 193dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </ul> 194dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * and <strong><code>var</code></strong> is the pooled variance estimate: 195dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </p><p> 196dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <code>var = sqrt(((n1 - 1)var1 + (n2 - 1)var2) / ((n1-1) + (n2-1)))</code> 197dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </p><p> 198dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * with <strong><code>var1<code></strong> the variance of the first sample and 199dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong><code>var2</code></strong> the variance of the second sample. 200dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </p><p> 201dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Preconditions</strong>: <ul> 202dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>The observed array lengths must both be at least 2. 203dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ul></p> 204dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 205dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sample1 array of sample data values 206dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sample2 array of sample data values 207dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @return t statistic 208dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws IllegalArgumentException if the precondition is not met 209dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 210dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double homoscedasticT(double[] sample1, double[] sample2) 211dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond throws IllegalArgumentException; 212dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 213dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Computes a 2-sample t statistic, without the hypothesis of equal 214dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * subpopulation variances. To compute a t-statistic assuming equal 215dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * variances, use {@link #homoscedasticT(double[], double[])}. 216dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 217dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * This statistic can be used to perform a two-sample t-test to compare 218dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * sample means.</p> 219dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 220dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The t-statisitc is</p> 221dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 222dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <code> t = (m1 - m2) / sqrt(var1/n1 + var2/n2)</code> 223dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </p><p> 224dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * where <strong><code>n1</code></strong> is the size of the first sample 225dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong><code> n2</code></strong> is the size of the second sample; 226dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong><code> m1</code></strong> is the mean of the first sample; 227dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong><code> m2</code></strong> is the mean of the second sample; 228dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong><code> var1</code></strong> is the variance of the first sample; 229dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong><code> var2</code></strong> is the variance of the second sample; 230dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </p><p> 231dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Preconditions</strong>: <ul> 232dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>The observed array lengths must both be at least 2. 233dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ul></p> 234dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 235dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sample1 array of sample data values 236dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sample2 array of sample data values 237dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @return t statistic 238dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws IllegalArgumentException if the precondition is not met 239dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 240dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double t(double[] sample1, double[] sample2) 241dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond throws IllegalArgumentException; 242dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 243dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Computes a 2-sample t statistic </a>, comparing the means of the datasets 244dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * described by two {@link StatisticalSummary} instances, without the 245dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * assumption of equal subpopulation variances. Use 246dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * {@link #homoscedasticT(StatisticalSummary, StatisticalSummary)} to 247dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * compute a t-statistic under the equal variances assumption. 248dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 249dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * This statistic can be used to perform a two-sample t-test to compare 250dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * sample means.</p> 251dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 252dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The returned t-statisitc is</p> 253dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 254dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <code> t = (m1 - m2) / sqrt(var1/n1 + var2/n2)</code> 255dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </p><p> 256dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * where <strong><code>n1</code></strong> is the size of the first sample; 257dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong><code> n2</code></strong> is the size of the second sample; 258dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong><code> m1</code></strong> is the mean of the first sample; 259dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong><code> m2</code></strong> is the mean of the second sample 260dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong><code> var1</code></strong> is the variance of the first sample; 261dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong><code> var2</code></strong> is the variance of the second sample 262dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </p><p> 263dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Preconditions</strong>: <ul> 264dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>The datasets described by the two Univariates must each contain 265dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * at least 2 observations. 266dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ul></p> 267dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 268dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sampleStats1 StatisticalSummary describing data from the first sample 269dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sampleStats2 StatisticalSummary describing data from the second sample 270dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @return t statistic 271dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws IllegalArgumentException if the precondition is not met 272dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 273dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double t( 274dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond StatisticalSummary sampleStats1, 275dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond StatisticalSummary sampleStats2) 276dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond throws IllegalArgumentException; 277dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 278dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Computes a 2-sample t statistic, comparing the means of the datasets 279dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * described by two {@link StatisticalSummary} instances, under the 280dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * assumption of equal subpopulation variances. To compute a t-statistic 281dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * without the equal variances assumption, use 282dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * {@link #t(StatisticalSummary, StatisticalSummary)}. 283dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 284dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * This statistic can be used to perform a (homoscedastic) two-sample 285dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * t-test to compare sample means.</p> 286dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 287dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The t-statisitc returned is</p> 288dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 289dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <code> t = (m1 - m2) / (sqrt(1/n1 +1/n2) sqrt(var))</code> 290dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </p><p> 291dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * where <strong><code>n1</code></strong> is the size of first sample; 292dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong><code> n2</code></strong> is the size of second sample; 293dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong><code> m1</code></strong> is the mean of first sample; 294dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong><code> m2</code></strong> is the mean of second sample 295dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * and <strong><code>var</code></strong> is the pooled variance estimate: 296dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </p><p> 297dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <code>var = sqrt(((n1 - 1)var1 + (n2 - 1)var2) / ((n1-1) + (n2-1)))</code> 298dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </p><p> 299dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * with <strong><code>var1<code></strong> the variance of the first sample and 300dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong><code>var2</code></strong> the variance of the second sample. 301dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </p><p> 302dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Preconditions</strong>: <ul> 303dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>The datasets described by the two Univariates must each contain 304dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * at least 2 observations. 305dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ul></p> 306dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 307dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sampleStats1 StatisticalSummary describing data from the first sample 308dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sampleStats2 StatisticalSummary describing data from the second sample 309dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @return t statistic 310dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws IllegalArgumentException if the precondition is not met 311dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 312dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double homoscedasticT( 313dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond StatisticalSummary sampleStats1, 314dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond StatisticalSummary sampleStats2) 315dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond throws IllegalArgumentException; 316dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 317dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Returns the <i>observed significance level</i>, or 318dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <i>p-value</i>, associated with a one-sample, two-tailed t-test 319dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * comparing the mean of the input array with the constant <code>mu</code>. 320dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 321dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The number returned is the smallest significance level 322dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * at which one can reject the null hypothesis that the mean equals 323dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <code>mu</code> in favor of the two-sided alternative that the mean 324dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * is different from <code>mu</code>. For a one-sided test, divide the 325dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * returned value by 2.</p> 326dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 327dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Usage Note:</strong><br> 328dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The validity of the test depends on the assumptions of the parametric 329dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * t-test procedure, as discussed 330dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <a href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html">here</a> 331dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </p><p> 332dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Preconditions</strong>: <ul> 333dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>The observed array length must be at least 2. 334dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ul></p> 335dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 336dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param mu constant value to compare sample mean against 337dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sample array of sample data values 338dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @return p-value 339dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws IllegalArgumentException if the precondition is not met 340dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws MathException if an error occurs computing the p-value 341dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 342dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double tTest(double mu, double[] sample) 343dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond throws IllegalArgumentException, MathException; 344dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 345dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Performs a <a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda353.htm"> 346dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * two-sided t-test</a> evaluating the null hypothesis that the mean of the population from 347dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * which <code>sample</code> is drawn equals <code>mu</code>. 348dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 349dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Returns <code>true</code> iff the null hypothesis can be 350dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * rejected with confidence <code>1 - alpha</code>. To 351dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * perform a 1-sided test, use <code>alpha * 2</code></p> 352dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 353dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Examples:</strong><br><ol> 354dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>To test the (2-sided) hypothesis <code>sample mean = mu </code> at 355dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * the 95% level, use <br><code>tTest(mu, sample, 0.05) </code> 356dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li> 357dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>To test the (one-sided) hypothesis <code> sample mean < mu </code> 358dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * at the 99% level, first verify that the measured sample mean is less 359dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * than <code>mu</code> and then use 360dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <br><code>tTest(mu, sample, 0.02) </code> 361dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ol></p> 362dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 363dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Usage Note:</strong><br> 364dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The validity of the test depends on the assumptions of the one-sample 365dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * parametric t-test procedure, as discussed 366dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <a href="http://www.basic.nwu.edu/statguidefiles/sg_glos.html#one-sample">here</a> 367dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </p><p> 368dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Preconditions</strong>: <ul> 369dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>The observed array length must be at least 2. 370dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ul></p> 371dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 372dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param mu constant value to compare sample mean against 373dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sample array of sample data values 374dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param alpha significance level of the test 375dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @return p-value 376dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws IllegalArgumentException if the precondition is not met 377dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws MathException if an error computing the p-value 378dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 379dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond boolean tTest(double mu, double[] sample, double alpha) 380dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond throws IllegalArgumentException, MathException; 381dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 382dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Returns the <i>observed significance level</i>, or 383dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <i>p-value</i>, associated with a one-sample, two-tailed t-test 384dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * comparing the mean of the dataset described by <code>sampleStats</code> 385dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * with the constant <code>mu</code>. 386dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 387dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The number returned is the smallest significance level 388dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * at which one can reject the null hypothesis that the mean equals 389dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <code>mu</code> in favor of the two-sided alternative that the mean 390dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * is different from <code>mu</code>. For a one-sided test, divide the 391dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * returned value by 2.</p> 392dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 393dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Usage Note:</strong><br> 394dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The validity of the test depends on the assumptions of the parametric 395dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * t-test procedure, as discussed 396dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <a href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html"> 397dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * here</a></p> 398dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 399dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Preconditions</strong>: <ul> 400dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>The sample must contain at least 2 observations. 401dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ul></p> 402dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 403dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param mu constant value to compare sample mean against 404dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sampleStats StatisticalSummary describing sample data 405dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @return p-value 406dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws IllegalArgumentException if the precondition is not met 407dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws MathException if an error occurs computing the p-value 408dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 409dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double tTest(double mu, StatisticalSummary sampleStats) 410dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond throws IllegalArgumentException, MathException; 411dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 412dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Performs a <a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda353.htm"> 413dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * two-sided t-test</a> evaluating the null hypothesis that the mean of the 414dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * population from which the dataset described by <code>stats</code> is 415dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * drawn equals <code>mu</code>. 416dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 417dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Returns <code>true</code> iff the null hypothesis can be rejected with 418dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * confidence <code>1 - alpha</code>. To perform a 1-sided test, use 419dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <code>alpha * 2.</code></p> 420dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 421dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Examples:</strong><br><ol> 422dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>To test the (2-sided) hypothesis <code>sample mean = mu </code> at 423dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * the 95% level, use <br><code>tTest(mu, sampleStats, 0.05) </code> 424dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li> 425dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>To test the (one-sided) hypothesis <code> sample mean < mu </code> 426dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * at the 99% level, first verify that the measured sample mean is less 427dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * than <code>mu</code> and then use 428dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <br><code>tTest(mu, sampleStats, 0.02) </code> 429dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ol></p> 430dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 431dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Usage Note:</strong><br> 432dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The validity of the test depends on the assumptions of the one-sample 433dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * parametric t-test procedure, as discussed 434dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <a href="http://www.basic.nwu.edu/statguidefiles/sg_glos.html#one-sample">here</a> 435dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </p><p> 436dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Preconditions</strong>: <ul> 437dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>The sample must include at least 2 observations. 438dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ul></p> 439dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 440dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param mu constant value to compare sample mean against 441dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sampleStats StatisticalSummary describing sample data values 442dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param alpha significance level of the test 443dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @return p-value 444dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws IllegalArgumentException if the precondition is not met 445dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws MathException if an error occurs computing the p-value 446dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 447dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond boolean tTest( 448dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double mu, 449dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond StatisticalSummary sampleStats, 450dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double alpha) 451dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond throws IllegalArgumentException, MathException; 452dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 453dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Returns the <i>observed significance level</i>, or 454dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <i>p-value</i>, associated with a two-sample, two-tailed t-test 455dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * comparing the means of the input arrays. 456dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 457dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The number returned is the smallest significance level 458dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * at which one can reject the null hypothesis that the two means are 459dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * equal in favor of the two-sided alternative that they are different. 460dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * For a one-sided test, divide the returned value by 2.</p> 461dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 462dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The test does not assume that the underlying popuation variances are 463dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * equal and it uses approximated degrees of freedom computed from the 464dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * sample data to compute the p-value. The t-statistic used is as defined in 465dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * {@link #t(double[], double[])} and the Welch-Satterthwaite approximation 466dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * to the degrees of freedom is used, 467dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * as described 468dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <a href="http://www.itl.nist.gov/div898/handbook/prc/section3/prc31.htm"> 469dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * here.</a> To perform the test under the assumption of equal subpopulation 470dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * variances, use {@link #homoscedasticTTest(double[], double[])}.</p> 471dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 472dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Usage Note:</strong><br> 473dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The validity of the p-value depends on the assumptions of the parametric 474dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * t-test procedure, as discussed 475dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <a href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html"> 476dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * here</a></p> 477dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 478dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Preconditions</strong>: <ul> 479dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>The observed array lengths must both be at least 2. 480dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ul></p> 481dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 482dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sample1 array of sample data values 483dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sample2 array of sample data values 484dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @return p-value for t-test 485dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws IllegalArgumentException if the precondition is not met 486dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws MathException if an error occurs computing the p-value 487dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 488dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double tTest(double[] sample1, double[] sample2) 489dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond throws IllegalArgumentException, MathException; 490dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 491dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Returns the <i>observed significance level</i>, or 492dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <i>p-value</i>, associated with a two-sample, two-tailed t-test 493dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * comparing the means of the input arrays, under the assumption that 494dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * the two samples are drawn from subpopulations with equal variances. 495dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * To perform the test without the equal variances assumption, use 496dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * {@link #tTest(double[], double[])}.</p> 497dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 498dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The number returned is the smallest significance level 499dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * at which one can reject the null hypothesis that the two means are 500dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * equal in favor of the two-sided alternative that they are different. 501dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * For a one-sided test, divide the returned value by 2.</p> 502dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 503dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * A pooled variance estimate is used to compute the t-statistic. See 504dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * {@link #homoscedasticT(double[], double[])}. The sum of the sample sizes 505dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * minus 2 is used as the degrees of freedom.</p> 506dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 507dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Usage Note:</strong><br> 508dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The validity of the p-value depends on the assumptions of the parametric 509dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * t-test procedure, as discussed 510dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <a href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html"> 511dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * here</a></p> 512dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 513dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Preconditions</strong>: <ul> 514dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>The observed array lengths must both be at least 2. 515dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ul></p> 516dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 517dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sample1 array of sample data values 518dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sample2 array of sample data values 519dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @return p-value for t-test 520dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws IllegalArgumentException if the precondition is not met 521dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws MathException if an error occurs computing the p-value 522dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 523dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double homoscedasticTTest( 524dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double[] sample1, 525dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double[] sample2) 526dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond throws IllegalArgumentException, MathException; 527dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 528dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Performs a 529dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda353.htm"> 530dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * two-sided t-test</a> evaluating the null hypothesis that <code>sample1</code> 531dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * and <code>sample2</code> are drawn from populations with the same mean, 532dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * with significance level <code>alpha</code>. This test does not assume 533dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * that the subpopulation variances are equal. To perform the test assuming 534dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * equal variances, use 535dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * {@link #homoscedasticTTest(double[], double[], double)}. 536dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 537dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Returns <code>true</code> iff the null hypothesis that the means are 538dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * equal can be rejected with confidence <code>1 - alpha</code>. To 539dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * perform a 1-sided test, use <code>alpha * 2</code></p> 540dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 541dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * See {@link #t(double[], double[])} for the formula used to compute the 542dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * t-statistic. Degrees of freedom are approximated using the 543dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <a href="http://www.itl.nist.gov/div898/handbook/prc/section3/prc31.htm"> 544dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Welch-Satterthwaite approximation.</a></p> 545dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 546dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Examples:</strong><br><ol> 547dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>To test the (2-sided) hypothesis <code>mean 1 = mean 2 </code> at 548dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * the 95% level, use 549dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <br><code>tTest(sample1, sample2, 0.05). </code> 550dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li> 551dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>To test the (one-sided) hypothesis <code> mean 1 < mean 2 </code>, 552dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * at the 99% level, first verify that the measured mean of <code>sample 1</code> 553dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * is less than the mean of <code>sample 2</code> and then use 554dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <br><code>tTest(sample1, sample2, 0.02) </code> 555dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ol></p> 556dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 557dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Usage Note:</strong><br> 558dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The validity of the test depends on the assumptions of the parametric 559dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * t-test procedure, as discussed 560dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <a href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html"> 561dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * here</a></p> 562dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 563dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Preconditions</strong>: <ul> 564dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>The observed array lengths must both be at least 2. 565dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li> 566dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li> <code> 0 < alpha < 0.5 </code> 567dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ul></p> 568dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 569dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sample1 array of sample data values 570dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sample2 array of sample data values 571dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param alpha significance level of the test 572dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @return true if the null hypothesis can be rejected with 573dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * confidence 1 - alpha 574dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws IllegalArgumentException if the preconditions are not met 575dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws MathException if an error occurs performing the test 576dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 577dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond boolean tTest( 578dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double[] sample1, 579dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double[] sample2, 580dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double alpha) 581dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond throws IllegalArgumentException, MathException; 582dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 583dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Performs a 584dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda353.htm"> 585dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * two-sided t-test</a> evaluating the null hypothesis that <code>sample1</code> 586dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * and <code>sample2</code> are drawn from populations with the same mean, 587dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * with significance level <code>alpha</code>, assuming that the 588dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * subpopulation variances are equal. Use 589dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * {@link #tTest(double[], double[], double)} to perform the test without 590dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * the assumption of equal variances. 591dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 592dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Returns <code>true</code> iff the null hypothesis that the means are 593dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * equal can be rejected with confidence <code>1 - alpha</code>. To 594dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * perform a 1-sided test, use <code>alpha * 2.</code> To perform the test 595dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * without the assumption of equal subpopulation variances, use 596dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * {@link #tTest(double[], double[], double)}.</p> 597dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 598dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * A pooled variance estimate is used to compute the t-statistic. See 599dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * {@link #t(double[], double[])} for the formula. The sum of the sample 600dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * sizes minus 2 is used as the degrees of freedom.</p> 601dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 602dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Examples:</strong><br><ol> 603dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>To test the (2-sided) hypothesis <code>mean 1 = mean 2 </code> at 604dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * the 95% level, use <br><code>tTest(sample1, sample2, 0.05). </code> 605dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li> 606dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>To test the (one-sided) hypothesis <code> mean 1 < mean 2, </code> 607dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * at the 99% level, first verify that the measured mean of 608dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <code>sample 1</code> is less than the mean of <code>sample 2</code> 609dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * and then use 610dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <br><code>tTest(sample1, sample2, 0.02) </code> 611dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ol></p> 612dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 613dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Usage Note:</strong><br> 614dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The validity of the test depends on the assumptions of the parametric 615dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * t-test procedure, as discussed 616dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <a href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html"> 617dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * here</a></p> 618dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 619dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Preconditions</strong>: <ul> 620dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>The observed array lengths must both be at least 2. 621dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li> 622dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li> <code> 0 < alpha < 0.5 </code> 623dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ul></p> 624dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 625dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sample1 array of sample data values 626dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sample2 array of sample data values 627dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param alpha significance level of the test 628dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @return true if the null hypothesis can be rejected with 629dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * confidence 1 - alpha 630dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws IllegalArgumentException if the preconditions are not met 631dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws MathException if an error occurs performing the test 632dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 633dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond boolean homoscedasticTTest( 634dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double[] sample1, 635dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double[] sample2, 636dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double alpha) 637dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond throws IllegalArgumentException, MathException; 638dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 639dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Returns the <i>observed significance level</i>, or 640dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <i>p-value</i>, associated with a two-sample, two-tailed t-test 641dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * comparing the means of the datasets described by two StatisticalSummary 642dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * instances. 643dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 644dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The number returned is the smallest significance level 645dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * at which one can reject the null hypothesis that the two means are 646dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * equal in favor of the two-sided alternative that they are different. 647dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * For a one-sided test, divide the returned value by 2.</p> 648dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 649dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The test does not assume that the underlying popuation variances are 650dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * equal and it uses approximated degrees of freedom computed from the 651dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * sample data to compute the p-value. To perform the test assuming 652dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * equal variances, use 653dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * {@link #homoscedasticTTest(StatisticalSummary, StatisticalSummary)}.</p> 654dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 655dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Usage Note:</strong><br> 656dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The validity of the p-value depends on the assumptions of the parametric 657dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * t-test procedure, as discussed 658dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <a href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html"> 659dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * here</a></p> 660dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 661dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Preconditions</strong>: <ul> 662dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>The datasets described by the two Univariates must each contain 663dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * at least 2 observations. 664dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ul></p> 665dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 666dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sampleStats1 StatisticalSummary describing data from the first sample 667dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sampleStats2 StatisticalSummary describing data from the second sample 668dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @return p-value for t-test 669dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws IllegalArgumentException if the precondition is not met 670dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws MathException if an error occurs computing the p-value 671dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 672dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double tTest( 673dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond StatisticalSummary sampleStats1, 674dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond StatisticalSummary sampleStats2) 675dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond throws IllegalArgumentException, MathException; 676dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 677dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Returns the <i>observed significance level</i>, or 678dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <i>p-value</i>, associated with a two-sample, two-tailed t-test 679dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * comparing the means of the datasets described by two StatisticalSummary 680dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * instances, under the hypothesis of equal subpopulation variances. To 681dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * perform a test without the equal variances assumption, use 682dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * {@link #tTest(StatisticalSummary, StatisticalSummary)}. 683dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 684dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The number returned is the smallest significance level 685dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * at which one can reject the null hypothesis that the two means are 686dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * equal in favor of the two-sided alternative that they are different. 687dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * For a one-sided test, divide the returned value by 2.</p> 688dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 689dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * See {@link #homoscedasticT(double[], double[])} for the formula used to 690dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * compute the t-statistic. The sum of the sample sizes minus 2 is used as 691dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * the degrees of freedom.</p> 692dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 693dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Usage Note:</strong><br> 694dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The validity of the p-value depends on the assumptions of the parametric 695dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * t-test procedure, as discussed 696dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <a href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html">here</a> 697dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </p><p> 698dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Preconditions</strong>: <ul> 699dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>The datasets described by the two Univariates must each contain 700dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * at least 2 observations. 701dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ul></p> 702dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 703dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sampleStats1 StatisticalSummary describing data from the first sample 704dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sampleStats2 StatisticalSummary describing data from the second sample 705dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @return p-value for t-test 706dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws IllegalArgumentException if the precondition is not met 707dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws MathException if an error occurs computing the p-value 708dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 709dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double homoscedasticTTest( 710dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond StatisticalSummary sampleStats1, 711dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond StatisticalSummary sampleStats2) 712dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond throws IllegalArgumentException, MathException; 713dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 714dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Performs a 715dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda353.htm"> 716dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * two-sided t-test</a> evaluating the null hypothesis that 717dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <code>sampleStats1</code> and <code>sampleStats2</code> describe 718dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * datasets drawn from populations with the same mean, with significance 719dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * level <code>alpha</code>. This test does not assume that the 720dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * subpopulation variances are equal. To perform the test under the equal 721dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * variances assumption, use 722dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * {@link #homoscedasticTTest(StatisticalSummary, StatisticalSummary)}. 723dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 724dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Returns <code>true</code> iff the null hypothesis that the means are 725dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * equal can be rejected with confidence <code>1 - alpha</code>. To 726dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * perform a 1-sided test, use <code>alpha * 2</code></p> 727dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 728dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * See {@link #t(double[], double[])} for the formula used to compute the 729dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * t-statistic. Degrees of freedom are approximated using the 730dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <a href="http://www.itl.nist.gov/div898/handbook/prc/section3/prc31.htm"> 731dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Welch-Satterthwaite approximation.</a></p> 732dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 733dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Examples:</strong><br><ol> 734dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>To test the (2-sided) hypothesis <code>mean 1 = mean 2 </code> at 735dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * the 95%, use 736dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <br><code>tTest(sampleStats1, sampleStats2, 0.05) </code> 737dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li> 738dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>To test the (one-sided) hypothesis <code> mean 1 < mean 2 </code> 739dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * at the 99% level, first verify that the measured mean of 740dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <code>sample 1</code> is less than the mean of <code>sample 2</code> 741dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * and then use 742dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <br><code>tTest(sampleStats1, sampleStats2, 0.02) </code> 743dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ol></p> 744dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 745dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Usage Note:</strong><br> 746dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The validity of the test depends on the assumptions of the parametric 747dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * t-test procedure, as discussed 748dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <a href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html"> 749dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * here</a></p> 750dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p> 751dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <strong>Preconditions</strong>: <ul> 752dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li>The datasets described by the two Univariates must each contain 753dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * at least 2 observations. 754dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li> 755dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <li> <code> 0 < alpha < 0.5 </code> 756dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * </li></ul></p> 757dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 758dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sampleStats1 StatisticalSummary describing sample data values 759dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param sampleStats2 StatisticalSummary describing sample data values 760dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param alpha significance level of the test 761dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @return true if the null hypothesis can be rejected with 762dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * confidence 1 - alpha 763dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws IllegalArgumentException if the preconditions are not met 764dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @throws MathException if an error occurs performing the test 765dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 766dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond boolean tTest( 767dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond StatisticalSummary sampleStats1, 768dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond StatisticalSummary sampleStats2, 769dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond double alpha) 770dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond throws IllegalArgumentException, MathException; 771dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond} 772