Skip to main content
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. The statistic 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 α=0.05\alpha = 0.05. 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.
Use Alternative.GREATER or Alternative.LESS for directional hypotheses instead of halving a two-sided p-value. The confidence interval adjusts accordingly.

Are two groups different?

Two-sample t-test

Compares the means of two independent samples. Welch’s t-test (unequal variances) is the default.
equalVariances is false by default, meaning Welch’s t-test is used. Set equalVariances = true only after confirming equal variances with leveneTest() or bartlettTest().

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. Returns AnovaResult 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 a TestResult — a significant result (low p-value) indicates evidence against normality.
Shapiro-Wilk is the most common choice and generally the most powerful for small-to-moderate samples (n < 5000). Anderson-Darling is more sensitive to deviations in the tails. D’Agostino-Pearson and Jarque-Bera are faster for large samples.

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.
Fisher exact test is designed for small contingency tables. For larger tables, use chiSquaredTest() with a chi-squared test of independence.

Do my groups have equal variances?

Variance homogeneity is an assumption of ANOVA and some t-test variants. Three tests are available:
Levene’s test is the safest default — it is robust to non-normality. Use Bartlett’s test only when the data within each group is approximately normal (Bartlett is more powerful in that case). Fligner-Killeen is the most robust to outliers.

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 G=maxixixˉs,G = \frac{\max_{i} |x_i - \bar{x}|}{s}, converted to a Student-tt statistic on N2N - 2 degrees of freedom and Bonferroni-corrected for having tested every observation.
Use Alternative.GREATER or Alternative.LESS to test a single tail when you only care about a suspiciously large or small value:
For multiple outliers, grubbsTestIterative() reapplies the test and removes one significant outlier at a time until none remain or the sample shrinks below three observations.
Grubbs’ test assumes the data is approximately normal apart from the outlier. Validate with shapiroWilkTest() on the data with the suspected extreme removed before reporting a significant result.
The iterative procedure can mask outliers when several extremes cluster together — each test may be diluted by its peers. For large clusters prefer a dedicated multiple-outlier test (e.g. generalized ESD) or a robust estimator.

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.
Last modified on April 23, 2026