friedmanTest

Performs the Friedman test for differences among repeated measures.

The Friedman test is a non-parametric alternative to one-way repeated measures ANOVA. It tests whether k related treatments (measured on the same n subjects or blocks) have identical effects. The test ranks the treatment values within each block using average tie-breaking, sums the ranks per treatment, and computes a chi-squared statistic from the rank sums. Under the null hypothesis of no treatment effect, the statistic follows a chi-squared distribution with k - 1 degrees of freedom.

Example:

val treatment1 = doubleArrayOf(7.0, 9.8, 6.5, 7.2, 8.3)
val treatment2 = doubleArrayOf(5.4, 6.8, 5.0, 4.8, 6.1)
val treatment3 = doubleArrayOf(8.2, 10.5, 7.1, 8.5, 9.0)
val result = friedmanTest(treatment1, treatment2, treatment3)
result.statistic // chi-squared test statistic Q
result.pValue // p-value from chi-squared distribution
result.degreesOfFreedom // k - 1

Return

a TestResult containing the chi-squared statistic, p-value, degrees of freedom (k - 1), and additional info with "numGroups" and "numBlocks".

Parameters

groups

two or more treatment groups, each with the same number of observations (one per block).