Click or drag to resize

UnivariateStudentTTest Method (IReadOnlyCollectionDouble, Double)

Tests whether the sample mean is compatible with the reference mean.

Namespace:  Meta.Numerics.Statistics
Assembly:  Meta.Numerics (in Meta.Numerics.dll) Version: 4.1.4
Syntax
public static TestResult StudentTTest(
	this IReadOnlyCollection<double> sample,
	double referenceMean
)

Parameters

sample
Type: System.Collections.GenericIReadOnlyCollectionDouble
The sample.
referenceMean
Type: SystemDouble
The reference mean.

Return Value

Type: TestResult
The result of the test. The test statistic is a t-value. If t > 0, the one-sided likelihood to obtain a greater value under the null hypothesis is the (right) probability of that value. If t < 0, the corresponding one-sided likelihood is the (left) probability of that value. The two-sided likelihood to obtain a t-value as far or farther from zero as the value obtained is just twice the one-sided likelihood.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IReadOnlyCollectionDouble. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Exceptions
ExceptionCondition
ArgumentNullExceptionsample is .
InsufficientDataExceptionThere are fewer than two data points in the sample.
Remarks

The test statistic of Student's t-test is the difference between the sample mean and the reference mean, measured in units of the sample mean uncertainty. Under the null hypothesis that the sample was drawn from a normally distributed population with the given reference mean, this statistic can be shown to follow a Student distribution (StudentDistribution). If t is far from zero, with correspondingly small left or right tail probability, then the sample is unlikely to have been drawn from a population with the given reference mean.

Because the distribution of a t-statistic assumes a normally distributed population, this test should only be used only on sample data compatible with a normal distribution. The sign test (SignTest(IReadOnlyCollectionDouble, Double)) is a non-parametric alternative that can be used to test the compatibility of the sample median with an assumed population median.

Examples

In some country, the legal limit blood alcohol limit for drivers is 80 on some scale. Because they have noticed that the results given by their measuring device fluctuate, the police perform three separate measurements on a suspected drunk driver. They obtain the results 81, 84, and 93. They argue that, because all three results exceed the limit, the court should be very confident that the driver's blood alcohol level did, in fact, exceed the legal limit. You are the driver's lawyer. Can you make an argument to that the court shouldn't be so sure?

Here is some code that computes the probability of obtaining such high measured values, assuming that the true level is exactly 80.

C#
Sample values = new Sample();
values.Add(81, 84, 93);
TestResult result = values.StudentTTest(80);
return(result.RightProbability);

What level of statistical confidence do you think should a court require in order to pronounce a defendant guilty?

See Also