Stats 0.2.0 ttest onesample - CyrilB1531/lodestar GitHub Wiki

Lodestar.Stats 0.2.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.

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)

Parameterssample 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.

ReturnsTTestResult: the t statistic, the p-value, and the degrees of freedom, sample.Length - 1.

ExceptionsArgumentException when sample holds fewer than two values. 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 alsoTTest.Independent, TTest.Paired, TTestResult.ConfidenceInterval, the Python equivalence table.

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