Stats 0.5.0 ttest onesample - CyrilB1531/lodestar GitHub Wiki

Lodestar.Stats 0.5.0. This page is frozen at that release. Read the current documentation for what main says now. A link to a decision or a migration page follows main, and leaves the archive.

Home › Hypothesis tests

TTest.OneSample

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;                        // => 6

Remarks — 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.

⚠️ **GitHub.com Fallback** ⚠️