Stats wilcoxon onesample - CyrilB1531/lodestar GitHub Wiki
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
Compares a sample of differences against a median of zero.
public static TestResult OneSample(ReadOnlySpan<double> differences, ZeroMethod zeroMethod = ZeroMethod.Wilcox, Alternative alternative = Alternative.TwoSided, Continuity continuity = Continuity.None, ExactMethod method = ExactMethod.Auto, NanPolicy nanPolicy = NanPolicy.Propagate)Parameters — differences is the sample, at least one value; the span is read, never
modified. zeroMethod says what to do with differences that are exactly zero. alternative says
which tail the p-value covers. continuity says whether the normal approximation gets the
half-unit correction. method chooses the exact null distribution, the exhaustive permutation
test, its normal approximation, or a choice between them by the number of non-zero differences.
nanPolicy says what to do with a NaN; scipy's nan_policy, defaulting to
NanPolicy.Propagate.
Returns — TestResult: the signed-rank statistic and the p-value. Two-sided, the statistic is the
smaller of the two rank sums; under Alternative.Less or Alternative.Greater it is the sum of the
positive ranks, which can be the larger one — scipy's wilcoxon reports the same.
Exceptions — ArgumentException when differences is empty, or nanPolicy is
NanPolicy.Raise and the sample holds a NaN. ArgumentOutOfRangeException when method is
ExactMethod.Exact and the zero-method-processed sample exceeds 500 values.
Example — seven differences, two of them exactly zero.
using Lodestar.Stats;
double[] differences = [2.0, 0.0, 3.0, 0.0, 2.0, 3.0, 3.0];
TestResult result = Wilcoxon.OneSample(differences);
double w = result.Statistic; // => 0
double p = result.PValue; // => 0.0625Remarks — every difference tied at zero is a defined answer, not an error. When
zeroMethod leaves nothing to rank — ZeroMethod.Wilcox drops every value — there is no evidence
either way, and this returns a statistic of 0.0 and a p-value of 1.0 rather than throwing;
scipy answers the same way on the same input.
Under NanPolicy.Propagate, a NaN reaches the statistic and the p-value. The check runs
before ranking — a NaN difference is neither greater than, less than nor equal to zero, so
unguarded it would fall into the zero group along with every genuine tie at zero.
The exact route has a size bound this package added. scipy's own signed-rank table is exact
for any n, but its total, 2^n, overflows a double to +Infinity past n = 1023, and every
p-value it then divides would silently come out as exactly 0.0. ExactMethod.Exact above 500
ranked values is refused with ArgumentOutOfRangeException instead, comfortably inside that
margin; ExactMethod.Auto never reaches the bound on its own, since it turns unconditionally
asymptotic above 50 values.
Applies to — net10.0, netstandard2.0.
See also — Wilcoxon.Paired, TTest.OneSample
for the parametric counterpart, ZeroMethod, ExactMethod,
the Python equivalence table.