shapiroWilkTest
Performs the Shapiro-Wilk test for normality.
The null hypothesis is that sample was drawn from a normal distribution. The W statistic measures how well the ordered sample values match the expected normal order statistics — values close to 1.0 indicate normality, while values significantly below 1.0 suggest non-normality. Uses Royston's AS R94 algorithm for both the W statistic and p-value approximation. Valid for sample sizes from 3 to 5000.
If all values are identical (zero variance), returns W = 1.0 and p-value = 1.0.
Example:
val data = doubleArrayOf(-1.2, -0.5, 0.1, 0.3, 0.7, 1.0, 1.5)
val result = shapiroWilkTest(data)
result.statistic // W statistic (~0.984 for this data)
result.pValue // p-value (~0.978, fails to reject normality)
result.isSignificant() // false (data is consistent with normality)Content copied to clipboard
Return
a TestResult containing the W statistic and p-value.
Parameters
sample
the observed values. Must have between 3 and 5000 elements.