commonstats
WASM-first Rust statistical core: special functions, mergeable accumulators,
descriptives, and hypothesis tests. &[f64] in, structs out — no binding glue.
Status
Base: special functions, the Mergeable/Accumulator core, descriptives,
moment/count-based tests (t / Welch / paired / ANOVA / F / χ² / Pearson), kernel
density + auto-histograms, and distribution-free transforms (rank, normal-scores,
PIT, power, quantile-normalize). Feature-gated: rng (Philox), resample
(null/bootstrap), and dist (continuous + discrete distribution objects).
Example
use ;
let a = ;
let b = ;
let m = mean.unwrap;
let result = t_test_two.unwrap;
println!;
API reference
&[f64] in, value or struct out. NaNs are dropped by default (the Omit
policy). Fallible items return Result<T, StatError>, abbreviated Result<T>
below; everything is two-sided unless noted.
A. Descriptives & moments
count // count of finite values
sum // Neumaier-compensated sum
min // minimum finite value
max // maximum finite value
range // max − min
median // type-7 sample median
mean // arithmetic mean
var // variance; ddof = Sample (n−1) | Population (n)
sd // standard deviation; ddof = Sample | Population
skewness // Fisher–Pearson g1 (no bias corr.)
kurtosis // excess kurtosis (Fisher)
cov // sample covariance (ddof = 1)
pearson // Pearson correlation r
describe // 5-number summary + moments
B. Hypothesis tests
All return TestResult { statistic, df, df2, p_value, effect_size, ci }.
t_test_one // one-sample t
t_test_two // two-sample t; va = Equal (pooled Student) | Welch
t_test_paired // paired t on a−b
anova_one_way // one-way ANOVA F
f_test_var // F-test, equal variances
chi2_gof // χ² goodness-of-fit
chi2_independence // χ² independence (r×c)
cor_test // correlation test (Pearson)
C. Effect sizes & confidence intervals
cohen_d // pooled-SD standardized mean diff
eta_squared // η² for one-way ANOVA
cramers_v // Cramér's V for an r×c table
ci_mean // mean CI (Student t)
ci_mean_diff // mean-diff CI (pooled)
ci_mean_diff_welch // mean-diff CI (Welch)
ci_proportion // Wald proportion CI
ci_correlation // Pearson r CI (Fisher z)
D. Distributions (requires feature dist)
Each constructor returns Result<Self>. All implement .cdf(x), .sf(x),
.quantile(p) -> Result<_>, the moment accessors (.mean(), .variance(),
.std_dev(), .skewness(), .kurtosis(), .entropy()), plus .density(x) /
.log_density(x) (continuous) or .mass(k) / .log_mass(k) (discrete).
// continuous
new // N(μ, σ)
new // Student's t
new // χ²(k)
new // F(d1, d2)
new // Uniform[a, b]
new // Exp(λ)
new // Cauchy (no moments)
new // Weibull
new // Log-normal
new // Γ(α, β)
new // Beta on [0, 1]
// discrete
new // Bernoulli(p)
new // Binom(n, p)
new // Poisson(λ)
new // trials until first success
new // negative binomial
new // hypergeometric
E. Transforms
rank // 1-based ranks; ties = Average|Min|Max|Dense|Ordinal
normal_scores // Blom (1958) rankits
box_cox // Box–Cox power (positive data)
yeo_johnson // Yeo–Johnson power (all reals)
quantile_normalize // column rank-averaging
// PIT (requires feature `dist`)
pit // probability-integral transform
inv_pit // inverse PIT
quantile_map // transport between scales
F. Density & histograms
kde // kernel = Gaussian|Epanechnikov; bandwidth = Silverman|Scott|Fixed(h)
// -> Kde { .density(x), .evaluate(xs), .bandwidth(), .n() }
histogram_auto // (edges, values); bins = Rule(Sturges|FreedmanDiaconis|…)|Fixed(k)|Width(w)|Edges
// norm = Count|Density|Probability
new // fixed-bin accumulator
// .counts(), .edges(), .underflow(), .overflow(), .ecdf()
Feature flags
| Flag | Adds |
|---|---|
dist |
continuous + discrete distribution objects (CDF/SF/PDF/quantile) and PIT |
rng |
counter-based Philox RNG (CommonStatsRng) |
resample |
permutation/bootstrap index generation + NullDist / BootDist (implies rng) |