Stats
Stats module: descriptive statistics on List(Float).
All functions are pure — no side effects. Primary input type: List(Float).
Functions that require non-empty input panic on empty list. sum and count always succeed (return 0.0 / 0 for empty).
Design: all sorting uses List.sort_by with Float comparison. Variance uses Welford's online algorithm for numerical stability.
Types
Functions
Pearson correlation coefficient. Returns value in [-1, 1]. Panics if lists have different lengths, fewer than 2 elements, or if either list has zero standard deviation.
Number of elements.
Sample covariance of two equal-length lists. Panics if lengths differ or if either list has fewer than 2 elements.
Five-number summary with selectable method: (min, Q1, median, Q3, max). Panics on empty list.
Interquartile range: Q3 − Q1 using the given method.
Uses the same sorted list for both quartiles (one sort, not two).
Panics on empty input.Interquartile range using Linear (Type 7) interpolation.
Simple linear regression: y = slope * x + intercept. Returns (slope, intercept). Panics if lists have different lengths or fewer than 2 elements, or if xs has zero variance (vertical line).
Maximum value, returning Err on empty list.
Maximum value. Panics on empty list.
Arithmetic mean. Panics on empty list.
Mean, returning Err on empty list instead of panicking.
Median (50th percentile). Panics on empty list.
Minimum value, returning Err on empty list.
Minimum value. Panics on empty list.
Mode: the most frequently occurring value. When there are ties, returns the first value encountered (in sorted order). Panics on empty list.
Percentile using linear interpolation. p must be in [0.0, 100.0]. Panics on empty list or out-of-range p.
Quantile at probability q ∈ [0.0, 1.0] using the given interpolation method. Panics on empty list or out-of-range q.
For a percentile-style API (q in 0..100), see `percentile`. The
existing `percentile(xs, p)` is equivalent to
`quantile(xs, p / 100.0, Linear)`.Quantile with Linear interpolation (Type 7, R/numpy default). Convenience alias for quantile(xs, q, Linear).
Batched quantiles: returns [quantile(xs, q, method) for q in qs]. Sorts the input once and reuses it for each q.
Sample standard deviation. Returns 0.0 for single element. Panics on empty.
Population standard deviation.
Sample standard deviation, returning Err on empty or single-element list.
Sum of all elements. Returns 0.0 for empty list.
Sample variance (denominator n-1). Returns 0.0 for a single element. Panics on empty list.
Uses Welford's online algorithm for numerical stability on inputs
where the naive two-pass sum-of-squares would suffer catastrophic
cancellation (near-constant data, shifted distributions).Population variance (denominator n). Returns 0.0 for a single element or empty list.
Uses Welford's online algorithm (same stability benefit as `variance`).Sample variance, returning Err on empty list.