-
Notifications
You must be signed in to change notification settings - Fork 0
Stats ttest onesample
Development build. This page describes
main, not a released package. The latest published Lodestar.Stats is 0.4.0 — read its documentation.
Home › Stats › Hypothesis tests
The one-sample t-test against a stated population mean.
public static TTestResult OneSample(ReadOnlySpan<double> sample, double populationMean, Alternative alternative = Alternative.TwoSided, NanPolicy nanPolicy = NanPolicy.Propagate)Parameters — sample is the data, at least two values; the span is read, never modified.
populationMean is the mean the null hypothesis states. alternative says which tail the
p-value covers. nanPolicy says what to do with a NaN; scipy's nan_policy, defaulting to
NanPolicy.Propagate.
Returns — TTestResult: the t statistic, the p-value, and the degrees of freedom — one less
than the count of values actually tested. That is sample.Length - 1 under the default
NanPolicy.Propagate, and one less than the filtered length under
NanPolicy.Omit.
Exceptions — ArgumentException when sample holds fewer than two values, or nanPolicy
is NanPolicy.Raise and the sample holds a NaN. ArgumentOutOfRangeException when
populationMean is NaN or infinite.
Example — a sample tested against a stated mean of 10.0.
using Lodestar.Stats;
double[] sample = [12.1, 9.4, 15.0, 11.2, 8.8, 13.9, 10.5];
TTestResult result = TTest.OneSample(sample, populationMean: 10.0);
double t = Math.Round(result.Statistic, 4); // => 1.8085
double df = result.Df; // => 6Remarks — the confidence interval TTestResult.ConfidenceInterval
returns brackets the population mean itself, not the statistic's offset from it — scipy does the
same. populationMean may be any finite number, including one nowhere near the sample: the test
answers "how surprising is this sample if the true mean were this?", and a wildly wrong guess
just produces a wildly small p-value.
Applies to — net10.0, netstandard2.0.
See also — TTest.Independent, TTest.Paired,
TTestResult.ConfidenceInterval, the
Python equivalence table.