Skip to main content
Start with the end-to-end scenario below, or jump to the per-module snippets at the bottom.

End-to-End Scenario

Define a sample

val sample = doubleArrayOf(2.0, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0)

Summarize

import org.oremif.kstats.descriptive.describe

val stats = sample.describe()
stats.mean              // 5.0
stats.median            // 4.5
stats.standardDeviation // 2.1380
stats.skewness          // 0.6563
stats.interquartileRange // 1.5
describe() returns count, center, spread, quartiles, shape, and standard error in a single object.

Check normality

import org.oremif.kstats.hypothesis.shapiroWilkTest

val normality = shapiroWilkTest(sample)
normality.statistic          // W statistic
normality.pValue             // > 0.05 → no evidence against normality
normality.isSignificant()    // false

Fit a distribution

import org.oremif.kstats.distributions.NormalDistribution

val normal = NormalDistribution(mu = stats.mean, sigma = stats.standardDeviation)
normal.cdf(6.0)          // probability that X ≤ 6.0
normal.quantile(0.95)    // value below which 95% of the distribution falls

Test a hypothesis

import org.oremif.kstats.hypothesis.tTest

val result = tTest(sample, mu = 5.0)
result.statistic         // 0.0
result.pValue            // 1.0
result.isSignificant()   // false — cannot reject H₀: μ = 5.0
result.confidenceInterval // (3.21, 6.79)

Measure association

import org.oremif.kstats.correlation.pearsonCorrelation
import org.oremif.kstats.correlation.simpleLinearRegression

val x = doubleArrayOf(1.0, 2.0, 3.0, 4.0, 5.0)
val y = doubleArrayOf(2.1, 3.9, 6.2, 7.8, 10.1)

val r = pearsonCorrelation(x, y)
r.coefficient            // 0.9987
r.pValue                 // 0.0001

val model = simpleLinearRegression(x, y)
model.slope              // 1.99
model.rSquared           // 0.9973
model.predict(6.0)       // 11.99

Per-Module Snippets

import org.oremif.kstats.descriptive.describe
import org.oremif.kstats.descriptive.mean
import org.oremif.kstats.descriptive.median
import org.oremif.kstats.descriptive.standardDeviation

val data = doubleArrayOf(2.0, 4.0, 4.0, 5.0, 7.0, 9.0)
data.mean()               // 5.1667
data.median()             // 4.5
data.standardDeviation()  // 2.4833
val summary = data.describe()
summary.skewness          // 0.3942

Next Steps

Descriptive Statistics

Full guide to summaries, moments, quantiles, and streaming stats.

Hypothesis Tests

Choose the right test and interpret TestResult.

First Analysis Tutorial

End-to-end example with summaries and inference.