Top Description Constructors Methods
org.apache.commons.math3.stat.inference

public Class TTest

extends Object
Class Inheritance
Imports
org.apache.commons.math3.distribution.TDistribution, org.apache.commons.math3.exception.DimensionMismatchException, .MathIllegalArgumentException, .MaxCountExceededException, .NoDataException, .NotStrictlyPositiveException, .NullArgumentException, .NumberIsTooSmallException, .OutOfRangeException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.stat.StatUtils, org.apache.commons.math3.stat.descriptive.StatisticalSummary, org.apache.commons.math3.util.FastMath

An implementation for Student's t-tests.

Tests can be:

Test statistics are available for all tests. Methods including "Test" in in their names perform tests, all other methods return t-statistics. Among the "Test" methods, double-valued methods return p-values; boolean-valued methods perform fixed significance level tests. Significance levels are always specified as numbers between 0 and 0.5 (e.g. tests at the 95% level use alpha=0.05).

Input to tests can be either double[] arrays or StatisticalSummary instances.

Uses commons-math org.apache.commons.math3.distribution.TDistribution implementation to estimate exact p-values.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
checkSampleData(final double[]
Sample data.
data
)

Check sample data.

private void
checkSampleData(final StatisticalSummary
Statistical summary.
stat
)

Check sample data.

private void
checkSignificanceLevel(final double
significance level
alpha
)

Check significance level.

protected double

Returns:

approximate degrees of freedom
df
(double
first sample variance
v1
,
double
second sample variance
v2
,
double
first sample n
n1
,
double
second sample n
n2
)

Computes approximate degrees of freedom for 2-sample t-test.

public double

Returns:

t statistic
homoscedasticT
(final double[]
array of sample data values
sample1
,
final double[]
array of sample data values
sample2
)

Computes a 2-sample t statistic, under the hypothesis of equal subpopulation variances.

public double

Returns:

t statistic
homoscedasticT
(final StatisticalSummary
StatisticalSummary describing data from the first sample
sampleStats1
,
final StatisticalSummary
StatisticalSummary describing data from the second sample
sampleStats2
)

Computes a 2-sample t statistic, comparing the means of the datasets described by two StatisticalSummary instances, under the assumption of equal subpopulation variances.

protected double

Returns:

t test statistic
homoscedasticT
(final double
first sample mean
m1
,
final double
second sample mean
m2
,
final double
first sample variance
v1
,
final double
second sample variance
v2
,
final double
first sample n
n1
,
final double
second sample n
n2
)

Computes t test statistic for 2-sample t-test under the hypothesis of equal subpopulation variances.

public double

Returns:

p-value for t-test
homoscedasticTTest
(final double[]
array of sample data values
sample1
,
final double[]
array of sample data values
sample2
)

Returns the observed significance level, or p-value, associated with a two-sample, two-tailed t-test comparing the means of the input arrays, under the assumption that the two samples are drawn from subpopulations with equal variances.

public boolean

Returns:

true if the null hypothesis can be rejected with confidence 1 - alpha
homoscedasticTTest
(final double[]
array of sample data values
sample1
,
final double[]
array of sample data values
sample2
,
final double
significance level of the test
alpha
)

Performs a two-sided t-test evaluating the null hypothesis that sample1 and sample2 are drawn from populations with the same mean, with significance level alpha, assuming that the subpopulation variances are equal.

public double

Returns:

p-value for t-test
homoscedasticTTest
(final StatisticalSummary
StatisticalSummary describing data from the first sample
sampleStats1
,
final StatisticalSummary
StatisticalSummary describing data from the second sample
sampleStats2
)

Returns the observed significance level, or p-value, associated with a two-sample, two-tailed t-test comparing the means of the datasets described by two StatisticalSummary instances, under the hypothesis of equal subpopulation variances.

protected double

Returns:

p-value
homoscedasticTTest
(double
first sample mean
m1
,
double
second sample mean
m2
,
double
first sample variance
v1
,
double
second sample variance
v2
,
double
first sample n
n1
,
double
second sample n
n2
)

Computes p-value for 2-sided, 2-sample t-test, under the assumption of equal subpopulation variances.

public double

Returns:

t statistic
pairedT
(final double[]
array of sample data values
sample1
,
final double[]
array of sample data values
sample2
)

Computes a paired, 2-sample t-statistic based on the data in the input arrays.

public double

Returns:

p-value for t-test
pairedTTest
(final double[]
array of sample data values
sample1
,
final double[]
array of sample data values
sample2
)

Returns the observed significance level, or p-value, associated with a paired, two-sample, two-tailed t-test based on the data in the input arrays.

public boolean

Returns:

true if the null hypothesis can be rejected with confidence 1 - alpha
pairedTTest
(final double[]
array of sample data values
sample1
,
final double[]
array of sample data values
sample2
,
final double
significance level of the test
alpha
)

Performs a paired t-test evaluating the null hypothesis that the mean of the paired differences between sample1 and sample2 is 0 in favor of the two-sided alternative that the mean paired difference is not equal to 0, with significance level alpha.

public double
public double
public double

Returns:

t statistic
t
(final double[]
array of sample data values
sample1
,
final double[]
array of sample data values
sample2
)

Computes a 2-sample t statistic, without the hypothesis of equal subpopulation variances.

public double

Returns:

t statistic
t
(final StatisticalSummary
StatisticalSummary describing data from the first sample
sampleStats1
,
final StatisticalSummary
StatisticalSummary describing data from the second sample
sampleStats2
)

Computes a 2-sample t statistic, comparing the means of the datasets described by two StatisticalSummary instances, without the assumption of equal subpopulation variances.

protected double

Returns:

t test statistic
t
(final double
sample mean
m
,
final double
constant to test against
mu
,
final double
sample variance
v
,
final double
sample n
n
)

Computes t test statistic for 1-sample t-test.

protected double

Returns:

t test statistic
t
(final double
first sample mean
m1
,
final double
second sample mean
m2
,
final double
first sample variance
v1
,
final double
second sample variance
v2
,
final double
first sample n
n1
,
final double
second sample n
n2
)

Computes t test statistic for 2-sample t-test.

public double

Returns:

p-value
tTest
(final double
constant value to compare sample mean against
mu
,
final double[]
array of sample data values
sample
)

Returns the observed significance level, or p-value, associated with a one-sample, two-tailed t-test comparing the mean of the input array with the constant mu.

public boolean

Returns:

p-value
tTest
(final double
constant value to compare sample mean against
mu
,
final double[]
array of sample data values
sample
,
final double
significance level of the test
alpha
)

Performs a two-sided t-test evaluating the null hypothesis that the mean of the population from which sample is drawn equals mu.

public double

Returns:

p-value
tTest
(final double
constant value to compare sample mean against
mu
,
final StatisticalSummary
StatisticalSummary describing sample data
sampleStats
)

Returns the observed significance level, or p-value, associated with a one-sample, two-tailed t-test comparing the mean of the dataset described by sampleStats with the constant mu.

public boolean

Returns:

p-value
tTest
(final double
constant value to compare sample mean against
mu
,
final StatisticalSummary
StatisticalSummary describing sample data values
sampleStats
,
final double
significance level of the test
alpha
)

Performs a two-sided t-test evaluating the null hypothesis that the mean of the population from which the dataset described by stats is drawn equals mu.

public double

Returns:

p-value for t-test
tTest
(final double[]
array of sample data values
sample1
,
final double[]
array of sample data values
sample2
)

Returns the observed significance level, or p-value, associated with a two-sample, two-tailed t-test comparing the means of the input arrays.

public boolean

Returns:

true if the null hypothesis can be rejected with confidence 1 - alpha
tTest
(final double[]
array of sample data values
sample1
,
final double[]
array of sample data values
sample2
,
final double
significance level of the test
alpha
)

Performs a two-sided t-test evaluating the null hypothesis that sample1 and sample2 are drawn from populations with the same mean, with significance level alpha.

public double

Returns:

p-value for t-test
tTest
(final StatisticalSummary
StatisticalSummary describing data from the first sample
sampleStats1
,
final StatisticalSummary
StatisticalSummary describing data from the second sample
sampleStats2
)

Returns the observed significance level, or p-value, associated with a two-sample, two-tailed t-test comparing the means of the datasets described by two StatisticalSummary instances.

public boolean

Returns:

true if the null hypothesis can be rejected with confidence 1 - alpha
tTest
(final StatisticalSummary
StatisticalSummary describing sample data values
sampleStats1
,
final StatisticalSummary
StatisticalSummary describing sample data values
sampleStats2
,
final double
significance level of the test
alpha
)

Performs a two-sided t-test evaluating the null hypothesis that sampleStats1 and sampleStats2 describe datasets drawn from populations with the same mean, with significance level alpha.

protected double

Returns:

p-value
tTest
(final double
sample mean
m
,
final double
constant to test against
mu
,
final double
sample variance
v
,
final double
sample n
n
)

Computes p-value for 2-sided, 1-sample t-test.

protected double

Returns:

p-value
tTest
(final double
first sample mean
m1
,
final double
second sample mean
m2
,
final double
first sample variance
v1
,
final double
second sample variance
v2
,
final double
first sample n
n1
,
final double
second sample n
n2
)

Computes p-value for 2-sided, 2-sample t-test.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

TTestback to summary
public TTest()

Method Detail

checkSampleDataback to summary
private void checkSampleData(final double[] data) throws NullArgumentException, NumberIsTooSmallException

Check sample data.

Parameters
data:double[]

Sample data.

Exceptions
NullArgumentException:
if data is null.
NumberIsTooSmallException:
if there is not enough sample data.
checkSampleDataback to summary
private void checkSampleData(final StatisticalSummary stat) throws NullArgumentException, NumberIsTooSmallException

Check sample data.

Parameters
stat:StatisticalSummary

Statistical summary.

Exceptions
NullArgumentException:
if data is null.
NumberIsTooSmallException:
if there is not enough sample data.
checkSignificanceLevelback to summary
private void checkSignificanceLevel(final double alpha) throws OutOfRangeException

Check significance level.

Parameters
alpha:double

significance level

Exceptions
OutOfRangeException:
if the significance level is out of bounds.
dfback to summary
protected double df(double v1, double v2, double n1, double n2)

Computes approximate degrees of freedom for 2-sample t-test.

Parameters
v1:double

first sample variance

v2:double

second sample variance

n1:double

first sample n

n2:double

second sample n

Returns:double

approximate degrees of freedom

homoscedasticTback to summary
public double homoscedasticT(final double[] sample1, final double[] sample2) throws NullArgumentException, NumberIsTooSmallException

Computes a 2-sample t statistic, under the hypothesis of equal subpopulation variances. To compute a t-statistic without the equal variances hypothesis, use t(double[], double[]).

This statistic can be used to perform a (homoscedastic) two-sample t-test to compare sample means.

The t-statistic is

   t = (m1 - m2) / (sqrt(1/n1 +1/n2) sqrt(var))

where n1 is the size of first sample; n2 is the size of second sample; m1 is the mean of first sample; m2 is the mean of second sample and var is the pooled variance estimate:

var = sqrt(((n1 - 1)var1 + (n2 - 1)var2) / ((n1-1) + (n2-1)))

with var1 the variance of the first sample and var2 the variance of the second sample.

Preconditions:

  • The observed array lengths must both be at least 2.

Parameters
sample1:double[]

array of sample data values

sample2:double[]

array of sample data values

Returns:double

t statistic

Exceptions
NullArgumentException:
if the arrays are null
NumberIsTooSmallException:
if the length of the arrays is < 2
homoscedasticTback to summary
public double homoscedasticT(final StatisticalSummary sampleStats1, final StatisticalSummary sampleStats2) throws NullArgumentException, NumberIsTooSmallException

Computes a 2-sample t statistic, comparing the means of the datasets described by two StatisticalSummary instances, under the assumption of equal subpopulation variances. To compute a t-statistic without the equal variances assumption, use t(StatisticalSummary, StatisticalSummary).

This statistic can be used to perform a (homoscedastic) two-sample t-test to compare sample means.

The t-statistic returned is

   t = (m1 - m2) / (sqrt(1/n1 +1/n2) sqrt(var))

where n1 is the size of first sample; n2 is the size of second sample; m1 is the mean of first sample; m2 is the mean of second sample and var is the pooled variance estimate:

var = sqrt(((n1 - 1)var1 + (n2 - 1)var2) / ((n1-1) + (n2-1)))

with var1 the variance of the first sample and var2 the variance of the second sample.

Preconditions:

  • The datasets described by the two Univariates must each contain at least 2 observations.

Parameters
sampleStats1:StatisticalSummary

StatisticalSummary describing data from the first sample

sampleStats2:StatisticalSummary

StatisticalSummary describing data from the second sample

Returns:double

t statistic

Exceptions
NullArgumentException:
if the sample statistics are null
NumberIsTooSmallException:
if the number of samples is < 2
homoscedasticTback to summary
protected double homoscedasticT(final double m1, final double m2, final double v1, final double v2, final double n1, final double n2)

Computes t test statistic for 2-sample t-test under the hypothesis of equal subpopulation variances.

Parameters
m1:double

first sample mean

m2:double

second sample mean

v1:double

first sample variance

v2:double

second sample variance

n1:double

first sample n

n2:double

second sample n

Returns:double

t test statistic

homoscedasticTTestback to summary
public double homoscedasticTTest(final double[] sample1, final double[] sample2) throws NullArgumentException, NumberIsTooSmallException, MaxCountExceededException

Returns the observed significance level, or p-value, associated with a two-sample, two-tailed t-test comparing the means of the input arrays, under the assumption that the two samples are drawn from subpopulations with equal variances. To perform the test without the equal variances assumption, use tTest(double[], double[]).

The number returned is the smallest significance level at which one can reject the null hypothesis that the two means are equal in favor of the two-sided alternative that they are different. For a one-sided test, divide the returned value by 2.

A pooled variance estimate is used to compute the t-statistic. See homoscedasticT(double[], double[]). The sum of the sample sizes minus 2 is used as the degrees of freedom.

Usage Note:
The validity of the p-value depends on the assumptions of the parametric t-test procedure, as discussed here

Preconditions:

  • The observed array lengths must both be at least 2.

Parameters
sample1:double[]

array of sample data values

sample2:double[]

array of sample data values

Returns:double

p-value for t-test

Exceptions
NullArgumentException:
if the arrays are null
NumberIsTooSmallException:
if the length of the arrays is < 2
MaxCountExceededException:
if an error occurs computing the p-value
homoscedasticTTestback to summary
public boolean homoscedasticTTest(final double[] sample1, final double[] sample2, final double alpha) throws NullArgumentException, NumberIsTooSmallException, OutOfRangeException, MaxCountExceededException

Performs a two-sided t-test evaluating the null hypothesis that sample1 and sample2 are drawn from populations with the same mean, with significance level alpha, assuming that the subpopulation variances are equal. Use tTest(double[], double[], double) to perform the test without the assumption of equal variances.

Returns true iff the null hypothesis that the means are equal can be rejected with confidence 1 - alpha. To perform a 1-sided test, use alpha * 2. To perform the test without the assumption of equal subpopulation variances, use tTest(double[], double[], double).

A pooled variance estimate is used to compute the t-statistic. See t(double[], double[]) for the formula. The sum of the sample sizes minus 2 is used as the degrees of freedom.

Examples:

  1. To test the (2-sided) hypothesis mean 1 = mean 2 at the 95% level, use
    tTest(sample1, sample2, 0.05).
  2. To test the (one-sided) hypothesis mean 1 < mean 2, at the 99% level, first verify that the measured mean of sample 1 is less than the mean of sample 2 and then use
    tTest(sample1, sample2, 0.02)

Usage Note:
The validity of the test depends on the assumptions of the parametric t-test procedure, as discussed here

Preconditions:

  • The observed array lengths must both be at least 2.
  • 0 < alpha < 0.5

Parameters
sample1:double[]

array of sample data values

sample2:double[]

array of sample data values

alpha:double

significance level of the test

Returns:boolean

true if the null hypothesis can be rejected with confidence 1 - alpha

Exceptions
NullArgumentException:
if the arrays are null
NumberIsTooSmallException:
if the length of the arrays is < 2
OutOfRangeException:
if alpha is not in the range (0, 0.5]
MaxCountExceededException:
if an error occurs computing the p-value
homoscedasticTTestback to summary
public double homoscedasticTTest(final StatisticalSummary sampleStats1, final StatisticalSummary sampleStats2) throws NullArgumentException, NumberIsTooSmallException, MaxCountExceededException

Returns the observed significance level, or p-value, associated with a two-sample, two-tailed t-test comparing the means of the datasets described by two StatisticalSummary instances, under the hypothesis of equal subpopulation variances. To perform a test without the equal variances assumption, use tTest(StatisticalSummary, StatisticalSummary).

The number returned is the smallest significance level at which one can reject the null hypothesis that the two means are equal in favor of the two-sided alternative that they are different. For a one-sided test, divide the returned value by 2.

See homoscedasticT(double[], double[]) for the formula used to compute the t-statistic. The sum of the sample sizes minus 2 is used as the degrees of freedom.

Usage Note:
The validity of the p-value depends on the assumptions of the parametric t-test procedure, as discussed here

Preconditions:

  • The datasets described by the two Univariates must each contain at least 2 observations.

Parameters
sampleStats1:StatisticalSummary

StatisticalSummary describing data from the first sample

sampleStats2:StatisticalSummary

StatisticalSummary describing data from the second sample

Returns:double

p-value for t-test

Exceptions
NullArgumentException:
if the sample statistics are null
NumberIsTooSmallException:
if the number of samples is < 2
MaxCountExceededException:
if an error occurs computing the p-value
homoscedasticTTestback to summary
protected double homoscedasticTTest(double m1, double m2, double v1, double v2, double n1, double n2) throws MaxCountExceededException, NotStrictlyPositiveException

Computes p-value for 2-sided, 2-sample t-test, under the assumption of equal subpopulation variances.

The sum of the sample sizes minus 2 is used as degrees of freedom.

Parameters
m1:double

first sample mean

m2:double

second sample mean

v1:double

first sample variance

v2:double

second sample variance

n1:double

first sample n

n2:double

second sample n

Returns:double

p-value

Exceptions
MaxCountExceededException:
if an error occurs computing the p-value
NotStrictlyPositiveException:
if the estimated degrees of freedom is not strictly positive
pairedTback to summary
public double pairedT(final double[] sample1, final double[] sample2) throws NullArgumentException, NoDataException, DimensionMismatchException, NumberIsTooSmallException

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 t(double, double[]), with mu = 0 and the sample array consisting of the (signed) differences between corresponding entries in sample1 and sample2.

Preconditions:

  • The input arrays must have the same length and their common length must be at least 2.

Parameters
sample1:double[]

array of sample data values

sample2:double[]

array of sample data values

Returns:double

t statistic

Exceptions
NullArgumentException:
if the arrays are null
NoDataException:
if the arrays are empty
DimensionMismatchException:
if the length of the arrays is not equal
NumberIsTooSmallException:
if the length of the arrays is < 2
pairedTTestback to summary
public double pairedTTest(final double[] sample1, final double[] sample2) throws NullArgumentException, NoDataException, DimensionMismatchException, NumberIsTooSmallException, MaxCountExceededException

Returns the observed significance level, or p-value, associated with a paired, two-sample, two-tailed t-test based on the data in the input arrays.

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.

This test is equivalent to a one-sample t-test computed using tTest(double, double[]) with mu = 0 and the sample array consisting of the signed differences between corresponding elements of sample1 and sample2.

Usage Note:
The validity of the p-value depends on the assumptions of the parametric t-test procedure, as discussed here

Preconditions:

  • The input array lengths must be the same and their common length must be at least 2.

Parameters
sample1:double[]

array of sample data values

sample2:double[]

array of sample data values

Returns:double

p-value for t-test

Exceptions
NullArgumentException:
if the arrays are null
NoDataException:
if the arrays are empty
DimensionMismatchException:
if the length of the arrays is not equal
NumberIsTooSmallException:
if the length of the arrays is < 2
MaxCountExceededException:
if an error occurs computing the p-value
pairedTTestback to summary
public boolean pairedTTest(final double[] sample1, final double[] sample2, final double alpha) throws NullArgumentException, NoDataException, DimensionMismatchException, NumberIsTooSmallException, OutOfRangeException, MaxCountExceededException

Performs a paired t-test evaluating the null hypothesis that the mean of the paired differences between sample1 and sample2 is 0 in favor of the two-sided alternative that the mean paired difference is not equal to 0, with significance level alpha.

Returns true iff the null hypothesis can be rejected with confidence 1 - alpha. To perform a 1-sided test, use alpha * 2

Usage Note:
The validity of the test depends on the assumptions of the parametric t-test procedure, as discussed here

Preconditions:

  • The input array lengths must be the same and their common length must be at least 2.
  • 0 < alpha < 0.5

Parameters
sample1:double[]

array of sample data values

sample2:double[]

array of sample data values

alpha:double

significance level of the test

Returns:boolean

true if the null hypothesis can be rejected with confidence 1 - alpha

Exceptions
NullArgumentException:
if the arrays are null
NoDataException:
if the arrays are empty
DimensionMismatchException:
if the length of the arrays is not equal
NumberIsTooSmallException:
if the length of the arrays is < 2
OutOfRangeException:
if alpha is not in the range (0, 0.5]
MaxCountExceededException:
if an error occurs computing the p-value
tback to summary
public double t(final double mu, final double[] observed) throws NullArgumentException, NumberIsTooSmallException

Computes a t statistic given observed values and a comparison constant.

This statistic can be used to perform a one sample t-test for the mean.

Preconditions:

Parameters
mu:double

comparison constant

observed:double[]

array of values

Returns:double

t statistic

Exceptions
NullArgumentException:
if observed is null
NumberIsTooSmallException:
if the length of observed is < 2
tback to summary
public double t(final double mu, final StatisticalSummary sampleStats) throws NullArgumentException, NumberIsTooSmallException

Computes a t statistic to use in comparing the mean of the dataset described by sampleStats to mu.

This statistic can be used to perform a one sample t-test for the mean.

Preconditions:

Parameters
mu:double

comparison constant

sampleStats:StatisticalSummary

DescriptiveStatistics holding sample summary statitstics

Returns:double

t statistic

Exceptions
NullArgumentException:
if sampleStats is null
NumberIsTooSmallException:
if the number of samples is < 2
tback to summary
public double t(final double[] sample1, final double[] sample2) throws NullArgumentException, NumberIsTooSmallException

Computes a 2-sample t statistic, without the hypothesis of equal subpopulation variances. To compute a t-statistic assuming equal variances, use homoscedasticT(double[], double[]).

This statistic can be used to perform a two-sample t-test to compare sample means.

The t-statistic is

   t = (m1 - m2) / sqrt(var1/n1 + var2/n2)

where n1 is the size of the first sample n2 is the size of the second sample; m1 is the mean of the first sample; m2 is the mean of the second sample; var1 is the variance of the first sample; var2 is the variance of the second sample;

Preconditions:

  • The observed array lengths must both be at least 2.

Parameters
sample1:double[]

array of sample data values

sample2:double[]

array of sample data values

Returns:double

t statistic

Exceptions
NullArgumentException:
if the arrays are null
NumberIsTooSmallException:
if the length of the arrays is < 2
tback to summary
public double t(final StatisticalSummary sampleStats1, final StatisticalSummary sampleStats2) throws NullArgumentException, NumberIsTooSmallException

Computes a 2-sample t statistic, comparing the means of the datasets described by two StatisticalSummary instances, without the assumption of equal subpopulation variances. Use homoscedasticT(StatisticalSummary, StatisticalSummary) to compute a t-statistic under the equal variances assumption.

This statistic can be used to perform a two-sample t-test to compare sample means.

The returned t-statistic is

   t = (m1 - m2) / sqrt(var1/n1 + var2/n2)

where n1 is the size of the first sample; n2 is the size of the second sample; m1 is the mean of the first sample; m2 is the mean of the second sample var1 is the variance of the first sample; var2 is the variance of the second sample

Preconditions:

  • The datasets described by the two Univariates must each contain at least 2 observations.

Parameters
sampleStats1:StatisticalSummary

StatisticalSummary describing data from the first sample

sampleStats2:StatisticalSummary

StatisticalSummary describing data from the second sample

Returns:double

t statistic

Exceptions
NullArgumentException:
if the sample statistics are null
NumberIsTooSmallException:
if the number of samples is < 2
tback to summary
protected double t(final double m, final double mu, final double v, final double n)

Computes t test statistic for 1-sample t-test.

Parameters
m:double

sample mean

mu:double

constant to test against

v:double

sample variance

n:double

sample n

Returns:double

t test statistic

tback to summary
protected double t(final double m1, final double m2, final double v1, final double v2, final double n1, final double n2)

Computes t test statistic for 2-sample t-test.

Does not assume that subpopulation variances are equal.

Parameters
m1:double

first sample mean

m2:double

second sample mean

v1:double

first sample variance

v2:double

second sample variance

n1:double

first sample n

n2:double

second sample n

Returns:double

t test statistic

tTestback to summary
public double tTest(final double mu, final double[] sample) throws NullArgumentException, NumberIsTooSmallException, MaxCountExceededException

Returns the observed significance level, or p-value, associated with a one-sample, two-tailed t-test comparing the mean of the input array with the constant mu.

The number returned is the smallest significance level at which one can reject the null hypothesis that the mean equals mu in favor of the two-sided alternative that the mean is different from mu. For a one-sided test, divide the returned value by 2.

Usage Note:
The validity of the test depends on the assumptions of the parametric t-test procedure, as discussed here

Preconditions:

  • The observed array length must be at least 2.

Parameters
mu:double

constant value to compare sample mean against

sample:double[]

array of sample data values

Returns:double

p-value

Exceptions
NullArgumentException:
if the sample array is null
NumberIsTooSmallException:
if the length of the array is < 2
MaxCountExceededException:
if an error occurs computing the p-value
tTestback to summary
public boolean tTest(final double mu, final double[] sample, final double alpha) throws NullArgumentException, NumberIsTooSmallException, OutOfRangeException, MaxCountExceededException

Performs a two-sided t-test evaluating the null hypothesis that the mean of the population from which sample is drawn equals mu.

Returns true iff the null hypothesis can be rejected with confidence 1 - alpha. To perform a 1-sided test, use alpha * 2

Examples:

  1. To test the (2-sided) hypothesis sample mean = mu at the 95% level, use
    tTest(mu, sample, 0.05)
  2. To test the (one-sided) hypothesis sample mean < mu at the 99% level, first verify that the measured sample mean is less than mu and then use
    tTest(mu, sample, 0.02)

Usage Note:
The validity of the test depends on the assumptions of the one-sample parametric t-test procedure, as discussed here

Preconditions:

  • The observed array length must be at least 2.

Parameters
mu:double

constant value to compare sample mean against

sample:double[]

array of sample data values

alpha:double

significance level of the test

Returns:boolean

p-value

Exceptions
NullArgumentException:
if the sample array is null
NumberIsTooSmallException:
if the length of the array is < 2
OutOfRangeException:
if alpha is not in the range (0, 0.5]
MaxCountExceededException:
if an error computing the p-value
tTestback to summary
public double tTest(final double mu, final StatisticalSummary sampleStats) throws NullArgumentException, NumberIsTooSmallException, MaxCountExceededException

Returns the observed significance level, or p-value, associated with a one-sample, two-tailed t-test comparing the mean of the dataset described by sampleStats with the constant mu.

The number returned is the smallest significance level at which one can reject the null hypothesis that the mean equals mu in favor of the two-sided alternative that the mean is different from mu. For a one-sided test, divide the returned value by 2.

Usage Note:
The validity of the test depends on the assumptions of the parametric t-test procedure, as discussed here

Preconditions:

  • The sample must contain at least 2 observations.

Parameters
mu:double

constant value to compare sample mean against

sampleStats:StatisticalSummary

StatisticalSummary describing sample data

Returns:double

p-value

Exceptions
NullArgumentException:
if sampleStats is null
NumberIsTooSmallException:
if the number of samples is < 2
MaxCountExceededException:
if an error occurs computing the p-value
tTestback to summary
public boolean tTest(final double mu, final StatisticalSummary sampleStats, final double alpha) throws NullArgumentException, NumberIsTooSmallException, OutOfRangeException, MaxCountExceededException

Performs a two-sided t-test evaluating the null hypothesis that the mean of the population from which the dataset described by stats is drawn equals mu.

Returns true iff the null hypothesis can be rejected with confidence 1 - alpha. To perform a 1-sided test, use alpha * 2.

Examples:

  1. To test the (2-sided) hypothesis sample mean = mu at the 95% level, use
    tTest(mu, sampleStats, 0.05)
  2. To test the (one-sided) hypothesis sample mean < mu at the 99% level, first verify that the measured sample mean is less than mu and then use
    tTest(mu, sampleStats, 0.02)

Usage Note:
The validity of the test depends on the assumptions of the one-sample parametric t-test procedure, as discussed here

Preconditions:

  • The sample must include at least 2 observations.

Parameters
mu:double

constant value to compare sample mean against

sampleStats:StatisticalSummary

StatisticalSummary describing sample data values

alpha:double

significance level of the test

Returns:boolean

p-value

Exceptions
NullArgumentException:
if sampleStats is null
NumberIsTooSmallException:
if the number of samples is < 2
OutOfRangeException:
if alpha is not in the range (0, 0.5]
MaxCountExceededException:
if an error occurs computing the p-value
tTestback to summary
public double tTest(final double[] sample1, final double[] sample2) throws NullArgumentException, NumberIsTooSmallException, MaxCountExceededException

Returns the observed significance level, or p-value, associated with a two-sample, two-tailed t-test comparing the means of the input arrays.

The number returned is the smallest significance level at which one can reject the null hypothesis that the two means are equal in favor of the two-sided alternative that they are different. For a one-sided test, divide the returned value by 2.

The test does not assume that the underlying popuation variances are equal and it uses approximated degrees of freedom computed from the sample data to compute the p-value. The t-statistic used is as defined in t(double[], double[]) and the Welch-Satterthwaite approximation to the degrees of freedom is used, as described here. To perform the test under the assumption of equal subpopulation variances, use homoscedasticTTest(double[], double[]).

Usage Note:
The validity of the p-value depends on the assumptions of the parametric t-test procedure, as discussed here

Preconditions:

  • The observed array lengths must both be at least 2.

Parameters
sample1:double[]

array of sample data values

sample2:double[]

array of sample data values

Returns:double

p-value for t-test

Exceptions
NullArgumentException:
if the arrays are null
NumberIsTooSmallException:
if the length of the arrays is < 2
MaxCountExceededException:
if an error occurs computing the p-value
tTestback to summary
public boolean tTest(final double[] sample1, final double[] sample2, final double alpha) throws NullArgumentException, NumberIsTooSmallException, OutOfRangeException, MaxCountExceededException

Performs a two-sided t-test evaluating the null hypothesis that sample1 and sample2 are drawn from populations with the same mean, with significance level alpha. This test does not assume that the subpopulation variances are equal. To perform the test assuming equal variances, use homoscedasticTTest(double[], double[], double).

Returns true iff the null hypothesis that the means are equal can be rejected with confidence 1 - alpha. To perform a 1-sided test, use alpha * 2

See t(double[], double[]) for the formula used to compute the t-statistic. Degrees of freedom are approximated using the Welch-Satterthwaite approximation.

Examples:

  1. To test the (2-sided) hypothesis mean 1 = mean 2 at the 95% level, use
    tTest(sample1, sample2, 0.05).
  2. To test the (one-sided) hypothesis mean 1 < mean 2 , at the 99% level, first verify that the measured mean of sample 1 is less than the mean of sample 2 and then use
    tTest(sample1, sample2, 0.02)

Usage Note:
The validity of the test depends on the assumptions of the parametric t-test procedure, as discussed here

Preconditions:

  • The observed array lengths must both be at least 2.
  • 0 < alpha < 0.5

Parameters
sample1:double[]

array of sample data values

sample2:double[]

array of sample data values

alpha:double

significance level of the test

Returns:boolean

true if the null hypothesis can be rejected with confidence 1 - alpha

Exceptions
NullArgumentException:
if the arrays are null
NumberIsTooSmallException:
if the length of the arrays is < 2
OutOfRangeException:
if alpha is not in the range (0, 0.5]
MaxCountExceededException:
if an error occurs computing the p-value
tTestback to summary
public double tTest(final StatisticalSummary sampleStats1, final StatisticalSummary sampleStats2) throws NullArgumentException, NumberIsTooSmallException, MaxCountExceededException

Returns the observed significance level, or p-value, associated with a two-sample, two-tailed t-test comparing the means of the datasets described by two StatisticalSummary instances.

The number returned is the smallest significance level at which one can reject the null hypothesis that the two means are equal in favor of the two-sided alternative that they are different. For a one-sided test, divide the returned value by 2.

The test does not assume that the underlying population variances are equal and it uses approximated degrees of freedom computed from the sample data to compute the p-value. To perform the test assuming equal variances, use homoscedasticTTest(StatisticalSummary, StatisticalSummary).

Usage Note:
The validity of the p-value depends on the assumptions of the parametric t-test procedure, as discussed here

Preconditions:

  • The datasets described by the two Univariates must each contain at least 2 observations.

Parameters
sampleStats1:StatisticalSummary

StatisticalSummary describing data from the first sample

sampleStats2:StatisticalSummary

StatisticalSummary describing data from the second sample

Returns:double

p-value for t-test

Exceptions
NullArgumentException:
if the sample statistics are null
NumberIsTooSmallException:
if the number of samples is < 2
MaxCountExceededException:
if an error occurs computing the p-value
tTestback to summary
public boolean tTest(final StatisticalSummary sampleStats1, final StatisticalSummary sampleStats2, final double alpha) throws NullArgumentException, NumberIsTooSmallException, OutOfRangeException, MaxCountExceededException

Performs a two-sided t-test evaluating the null hypothesis that sampleStats1 and sampleStats2 describe datasets drawn from populations with the same mean, with significance level alpha. This test does not assume that the subpopulation variances are equal. To perform the test under the equal variances assumption, use homoscedasticTTest(StatisticalSummary, StatisticalSummary).

Returns true iff the null hypothesis that the means are equal can be rejected with confidence 1 - alpha. To perform a 1-sided test, use alpha * 2

See t(double[], double[]) for the formula used to compute the t-statistic. Degrees of freedom are approximated using the Welch-Satterthwaite approximation.

Examples:

  1. To test the (2-sided) hypothesis mean 1 = mean 2 at the 95%, use
    tTest(sampleStats1, sampleStats2, 0.05)
  2. To test the (one-sided) hypothesis mean 1 < mean 2 at the 99% level, first verify that the measured mean of sample 1 is less than the mean of sample 2 and then use
    tTest(sampleStats1, sampleStats2, 0.02)

Usage Note:
The validity of the test depends on the assumptions of the parametric t-test procedure, as discussed here

Preconditions:

  • The datasets described by the two Univariates must each contain at least 2 observations.
  • 0 < alpha < 0.5

Parameters
sampleStats1:StatisticalSummary

StatisticalSummary describing sample data values

sampleStats2:StatisticalSummary

StatisticalSummary describing sample data values

alpha:double

significance level of the test

Returns:boolean

true if the null hypothesis can be rejected with confidence 1 - alpha

Exceptions
NullArgumentException:
if the sample statistics are null
NumberIsTooSmallException:
if the number of samples is < 2
OutOfRangeException:
if alpha is not in the range (0, 0.5]
MaxCountExceededException:
if an error occurs computing the p-value
tTestback to summary
protected double tTest(final double m, final double mu, final double v, final double n) throws MaxCountExceededException, MathIllegalArgumentException

Computes p-value for 2-sided, 1-sample t-test.

Parameters
m:double

sample mean

mu:double

constant to test against

v:double

sample variance

n:double

sample n

Returns:double

p-value

Exceptions
MaxCountExceededException:
if an error occurs computing the p-value
MathIllegalArgumentException:
if n is not greater than 1
tTestback to summary
protected double tTest(final double m1, final double m2, final double v1, final double v2, final double n1, final double n2) throws MaxCountExceededException, NotStrictlyPositiveException

Computes p-value for 2-sided, 2-sample t-test.

Does not assume subpopulation variances are equal. Degrees of freedom are estimated from the data.

Parameters
m1:double

first sample mean

m2:double

second sample mean

v1:double

first sample variance

v2:double

second sample variance

n1:double

first sample n

n2:double

second sample n

Returns:double

p-value

Exceptions
MaxCountExceededException:
if an error occurs computing the p-value
NotStrictlyPositiveException:
if the estimated degrees of freedom is not strictly positive