wilcoxonSignedRankTest

fun wilcoxonSignedRankTest(sample1: DoubleArray, sample2: DoubleArray? = null, alternative: Alternative = Alternative.TWO_SIDED): TestResult(source)

Performs the Wilcoxon signed-rank test.

In one-sample mode (when sample2 is null), tests whether the median of sample1 differs from zero. In paired mode (when sample2 is provided), tests whether the median of the paired differences is zero. This is a non-parametric alternative to the paired t-test that does not assume normality. Uses a normal approximation for computing the p-value.

Zero differences are removed before ranking. The test statistic W is the sum of positive signed ranks.

Example:

val before = doubleArrayOf(10.0, 12.0, 14.0, 16.0, 18.0)
val after = doubleArrayOf(8.0, 9.0, 11.0, 12.0, 13.0)
val result = wilcoxonSignedRankTest(before, after)
result.statistic // W+ (sum of positive ranks)
result.pValue // p-value
result.additionalInfo["wPlus"] // sum of positive signed ranks
result.additionalInfo["wMinus"] // sum of negative signed ranks
result.additionalInfo["z"] // z-score from normal approximation

Return

a TestResult containing the W+ statistic, p-value, and additional info with "wPlus", "wMinus", and "z".

Parameters

sample1

the first sample, or the only sample in one-sample mode.

sample2

the second sample for paired mode. Must have the same size as sample1 if provided. Defaults to null (one-sample mode).

alternative

the direction of the alternative hypothesis. Defaults to Alternative.TWO_SIDED.

Throws

if all differences are zero after pairing or in one-sample mode.