Stats friedman test - CyrilB1531/lodestar GitHub Wiki

Development build. This page describes main, not a released package. The latest published Lodestar.Stats is 0.5.0 — read its documentation.

Home › Stats › Hypothesis tests

Friedman.Test

Compares three or more treatments measured on the same blocks.

public static TestResult Test(double[][] treatments)
public static TestResult Test(NanPolicy nanPolicy, double[][] treatments)

The policy comes first because the treatments are a params array and C# allows no parameter after one.

Parameters — treatments is one array per treatment, all the same length; entry i of each is the measurement on block i. At least three treatments, as scipy.stats.friedmanchisquare requires. nanPolicy says what to do with a NaN; scipy's nan_policy, defaulting to NanPolicy.Propagate.

Returns — TestResult: the Q statistic, and the upper-tail p-value.

Exceptions — ArgumentException when there are fewer than three treatments, the treatments have different lengths, or nanPolicy is NanPolicy.Raise and a measurement is NaN. No block, given or left by omission, answers NaN for both (decision 0010). ArgumentOutOfRangeException when an option is outside its enumeration.

Example — six wines scored by three judges, and what pairing buys. Each judge is harsh or generous in their own way, and ranking within a wine removes that before the treatments are compared. The between-subjects test on the same numbers cannot.

using Lodestar.Stats;

double[] strict = [7.0, 5.0, 8.0, 6.0, 9.0, 7.0];
double[] stricter = [6.0, 4.0, 7.0, 5.0, 8.0, 6.0];
double[] generous = [8.0, 7.0, 9.0, 8.0, 9.0, 8.0];

double paired = Math.Round(Friedman.Test(strict, stricter, generous).PValue, 6);      // => 0.003081
double unpaired = Math.Round(KruskalWallis.Test(strict, stricter, generous).PValue, 4); // => 0.0361

Both see a difference; the paired test sees it an order of magnitude more clearly, because the spread between wines is noise to the question "do the judges differ" and ranking inside each wine throws it away.

Remarks — omission drops the whole block, not the measurement. The treatments are paired across blocks, so a block missing one treatment can no longer be ranked, and ranking the rest would compare treatments on different subjects. Under NanPolicy.Omit the block leaves entirely; under NanPolicy.Propagate the statistic and the p-value are both NaN, because a NaN sorted into a ranking would otherwise take a finite rank like any other value.

Treatments that agree exactly on every block answer NaN. Every rank is then tied, the tie correction is exactly zero, and the statistic is 0/0, which Friedman's paper leaves undefined: NaN, as scipy answers and as KruskalWallis.Test answers its analogous input (decision 0010). So does no block at all, given or left by omission.

Applies to — net10.0, netstandard2.0.

See also — KruskalWallis.Test for the unpaired counterpart, Wilcoxon.Paired for two treatments rather than three, the Python equivalence table.