chiSquaredIndependenceTest
Performs a chi-squared test of independence for a contingency table.
The null hypothesis is that the row and column variables are independent — that is, knowing the row category does not help predict the column category. The test compares the observed cell counts to the counts expected under independence.
Example:
// 2x2 contingency table: treatment vs outcome
val table = arrayOf(
intArrayOf(10, 30),
intArrayOf(20, 40)
)
val result = chiSquaredIndependenceTest(table)
result.statistic // chi-squared statistic
result.pValue // p-value
result.degreesOfFreedom // 1.0 ((2-1) * (2-1))Content copied to clipboard
Return
a TestResult containing the chi-squared statistic, p-value, and degrees of freedom ((rows - 1) * (columns - 1)).
Parameters
contingencyTable
a matrix of observed frequency counts with at least 2 rows and 2 columns. All rows must have the same number of columns.