kstats-hypothesis provides statistical tests organized by the question they answer. Most functions return a TestResult; oneWayAnova() returns an AnovaResult with the full ANOVA table.
Reading a Test Result
Every test produces a result with a consistent shape. Thestatistic is the computed test value, pValue is the probability of observing a result at least as extreme under the null hypothesis, and isSignificant() compares the p-value to a threshold.
isSignificant() defaults to . Pass a different threshold explicitly: result.isSignificant(alpha = 0.01).Set
alternative explicitly for one-sided tests. The default is Alternative.TWO_SIDED. Using Alternative.GREATER tests whether the sample mean exceeds the reference value; Alternative.LESS tests whether it falls below.Is my sample mean different from a reference value?
The one-sample t-test compares the mean of a single sample against a known or hypothesized value.Are two groups different?
Two-sample t-test
Compares the means of two independent samples. Welch’s t-test (unequal variances) is the default.Paired t-test
Compares two related measurements (before/after, left/right) on the same subjects.Mann-Whitney U test
Non-parametric alternative to the two-sample t-test. Compares ranks instead of means.Wilcoxon signed-rank test
Non-parametric alternative to the paired t-test. Tests whether paired differences are symmetrically distributed around zero.Are three or more groups different?
One-way ANOVA
Tests whether the means of three or more groups differ. ReturnsAnovaResult with the full ANOVA table.
ANOVA assumes normality within each group and equal variances across groups. Check normality with
shapiroWilkTest() and equal variances with leveneTest() or bartlettTest() before running ANOVA.Friedman test
Non-parametric alternative to repeated-measures ANOVA. Compares ranks across matched groups.Is my data normally distributed?
Four normality tests are available. Each returns aTestResult — a significant result (low p-value) indicates evidence against normality.
Do my observed counts match expected proportions?
Chi-squared goodness-of-fit
Tests whether observed counts match expected frequencies.G-test
Likelihood-ratio alternative to the chi-squared test. Often preferred for small expected counts.Binomial test
Tests whether the observed proportion of successes matches a hypothesized probability.Fisher exact test
Exact test for 2×2 contingency tables. Preferred over chi-squared for small samples.Do my groups have equal variances?
Variance homogeneity is an assumption of ANOVA and some t-test variants. Three tests are available:Does my sample match a reference distribution?
Kolmogorov-Smirnov test
The two-sample KS test compares whether two samples come from the same continuous distribution.Are any observations outliers?
Grubbs’ test
Grubbs’ test (the extreme studentized deviate test) formally checks whether the observation farthest from the mean is an outlier, assuming the remaining data is approximately normal. The test statistic is converted to a Student- statistic on degrees of freedom and Bonferroni-corrected for having tested every observation.Alternative.GREATER or Alternative.LESS to test a single tail when you only care about a suspiciously large or small value:
grubbsTestIterative() reapplies the test and removes one significant outlier at a time until none remain or the sample shrinks below three observations.
The Alternative Enum
Alternative controls the direction of the test:
Directional alternatives are supported by
tTest, pairedTTest, mannWhitneyUTest, wilcoxonSignedRankTest, and binomialTest.
API Reference
Full API Reference
Browse all test functions, result types, and parameter overloads in the Dokka-generated reference.