kstats-core provides descriptive statistics as extension functions on DoubleArray and Iterable<Double>. It also includes Int and Long overloads for the most common operations.
Summary Snapshot
describe() is the fastest way to get a complete picture of a sample. It returns a DescriptiveStatistics object combining count, center, spread, quartiles, shape, and standard error.
variance() and standardDeviation() use the sample formula (dividing by ) by default. Pass PopulationKind.POPULATION to use the population formula (dividing by ).Central Tendency
Different notions of “center” suit different data shapes.mean() is the arithmetic average, median() is the positional center, mode() returns the most frequent values, and the trimmed and weighted variants handle outliers and importance weights.
- Geometric mean — use for growth rates and ratios. Requires all positive values.
- Harmonic mean — use for rates and speed averages. Requires all positive values.
- Trimmed mean — drops a proportion from each tail before averaging. Robust to outliers.
- Weighted mean — each observation contributes proportionally to its weight.
Math details
Math details
The trimmed mean drops observations from each end of the sorted sample, then computes the arithmetic mean of the remaining values.
Dispersion
Spread measures describe how far values deviate from the center.semiVariance measures variability on one side of a threshold. DOWNSIDE captures risk below the threshold; UPSIDE captures variability above it.Math details
Math details
Quantiles and Position
Quantiles split the data at specified probability thresholds.percentile() takes a value on the 0–100 scale; quantile() takes a value on the 0–1 scale.
Math details
Math details
With linear interpolation (the default), the quantile at probability for sorted data is computed as:where .
Shape and Moments
Shape measures describe asymmetry and tail weight beyond what the mean and variance capture.Math details
Math details
The -th central moment is . K-statistics () are unbiased estimators of the corresponding cumulants.
Frequency Analysis
TheFrequency class counts occurrences, proportions, and cumulative frequencies for any Comparable type. frequencyTable() groups numeric data into equal-width bins.
Streaming Statistics
OnlineStatistics computes mean, variance, skewness, and kurtosis incrementally without storing the full sample. Values can be added one at a time or in batches.
OnlineStatistics when data arrives incrementally (streaming, event-driven systems) or when buffering the full sample in memory is impractical.
Math details
Math details
OnlineStatistics uses Welford’s algorithm with the Terriberry extension for numerically stable single-pass computation of higher-order moments. The algorithm updates running sums of powers of deviations from the current mean, avoiding the catastrophic cancellation that affects naive two-pass formulas on large datasets.Process Capability
Process capability indices quantify how well a process fits within its .processCapability(lsl, usl) returns four Statistical Process Control (SPC) indices in one call:
- Cp, Cpk — potential and actual capability using the sample standard deviation (short-term, within-subgroup spread).
- Pp, Ppk — the same formulas using the population standard deviation (long-term, overall spread).
-k variants penalize a process that is off-center relative to the midpoint of the spec, so Cpk is never larger than Cp.
Use these indices only on a process that is already in statistical control (stable over time — see Shewhart Control Charts below). For an unstable process the measured spread is not a fixed property of the process.
≥ 1.33 are usually considered capable; ≥ 1.67 highly capable. When Cpk ≪ Cp, re-center the process before trying to reduce variance.
Math details
Math details
Pp and Ppk use the population standard deviation (divisor ) in place of the sample standard deviation (divisor ).
processCapability computes both in a single numerically stable Welford pass.Shewhart Control Charts
Shewhart plot subgroup statistics over time with three-sigma control limits.xBarRChart() monitors the process mean together with the range within each subgroup; xBarSChart() uses the sample standard deviation instead — more efficient for subgroup sizes above 10. Both require equal-sized subgroups of 2–25 observations.
spcConstants(n).
Math details
Math details
For subgroups of size with subgroup means , ranges , and standard deviations :
CUSUM Chart
A Shewhart chart reacts slowly to drifts of less than 2σ because every point is judged in isolation.cusum() accumulates deviations from target over time, so a 0.5σ–1σ drift is detected within a few observations. The two-sided tabular form tracks an upper sum that catches upward shifts and a lower sum for downward shifts. An alarm fires on the first index where either sum exceeds the decision interval .
Math details
Math details
starting from , with an alarm the first time or .
EWMA Chart
EWMA (Roberts, 1959) is the other classic small-shift detector. Instead of an unbounded cumulative sum,ewma() maintains a weighted moving average that gives recent observations more influence while retaining memory of the past. Control limits widen with time until they reach a steady state, so the chart is most sensitive early — useful for catching an initial shift.
Math details
Math details
Western Electric Rules
westernElectricRules() extends a Shewhart chart beyond the basic ±3σ check with four run-length heuristics that catch trends, clusters, and prolonged one-sided runs.
Each rule’s array contains the trigger indices — the observation whose arrival completes the offending pattern.
Error Handling
API Reference
Full API Reference
Browse all public types, functions, parameter overloads, and return types in the Dokka-generated reference.