Skip to main content
kstats is a Kotlin Multiplatform statistics library. It covers descriptive statistics, probability distributions, hypothesis testing, correlation and regression, and sampling — everything needed for quantitative analysis in Kotlin.
val sample = doubleArrayOf(2.0, 4.0, 4.0, 5.0, 7.0, 9.0)

val summary = sample.describe()
summary.mean              // 5.1667
summary.standardDeviation // 2.4833

val normality = shapiroWilkTest(sample)
normality.pValue          // 0.8933

val fitted = NormalDistribution(mu = summary.mean, sigma = summary.standardDeviation)
fitted.cdf(6.0)           // 0.6335

Modules

Descriptive Statistics

Mean, median, variance, quantiles, moments, frequency tables, streaming stats, and describe() summaries.

Probability Distributions

18 continuous and 10 discrete distributions with a shared API: pdf/pmf, cdf, quantile, and sampling.

Hypothesis Tests

t-tests, ANOVA, chi-squared, Fisher exact, Mann-Whitney, Wilcoxon, Shapiro-Wilk, and more.

Correlation & Regression

Pearson, Spearman, Kendall tau, partial correlation, matrices, and simple linear regression.

Sampling & Transformation

Ranking, z-score normalization, min-max scaling, binning, bootstrap, and weighted sampling.

Supported Targets

PlatformTargets
JVMjvm
Androidandroid
Android NativeandroidNativeArm32, androidNativeArm64, androidNativeX86, androidNativeX64
iOSiosX64, iosArm64, iosSimulatorArm64
macOSmacosArm64
LinuxlinuxArm64, linuxX64
WindowsmingwX64
watchOSwatchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64
tvOStvosArm64, tvosSimulatorArm64
JSjs (browser, Node.js)
WasmwasmJs, wasmWasi

Next Steps

Installation

Add the BOM or a single module to a Gradle KTS project.

Quick Start

Run a summary, fit a distribution, and execute a hypothesis test.

A/B Testing

Walk through a complete A/B test with assumption checks and group comparison.
Last modified on April 23, 2026