Skip to main content

Crate use_statistics

Crate use_statistics 

Source
Expand description

§use-statistics

Small statistical summary helpers for `RustUse`.
Explicit mean, median, variance, and standard-deviation helpers over numeric slices.

Rust 1.95.0+ Edition 2024 Summary helpers License MIT or Apache-2.0

§Install

[dependencies]
use-statistics = "0.0.1"

§Foundation

use-statistics provides a deliberately small descriptive-statistics surface over f64 slices. The crate currently exposes arithmetic mean, median, population variance, sample variance, and matching standard-deviation helpers, along with an explicit StatisticsError for empty inputs and too-small samples. The first slice stays simple and direct instead of introducing a full dataframe or distribution framework.

Central tendency
mean and median cover the two common location summaries directly.
Dispersion
population_variance, sample_variance, population_std_dev, and sample_std_dev keep the estimator choice explicit.
Explicit invalid-input handling
StatisticsError distinguishes empty-input cases from undersized sample calculations.
Helper groupPrimary itemsBest fit
Central tendencymean, medianSmall apps and utilities that need direct descriptive summaries
Dispersionpopulation_variance, sample_variance, population_std_dev, sample_std_devCall sites that should remain explicit about population vs. sample summaries
Error handlingStatisticsErrorCode that needs predictable handling for empty or undersized inputs

§When to use directly

Choose use-statistics directly when statistical summaries or distributions are the only surface you need and you want to keep that concern narrower than the full facade.

ScenarioUse use-statistics directly?Why
You need descriptive summaries over f64 slicesYesThe current API already covers the common location and dispersion cases directly
You want explicit population-vs-sample summary functionsYesThe function names keep estimator choice visible at the call site
You also need probability, calculus, or other math domainsUsually nouse-math can compose the concrete surfaces behind features

§Scope

  • The current surface is intentionally small and concrete.
  • Helpers operate over borrowed f64 slices instead of introducing dataset wrapper types.
  • Probability primitives and broader numerical analysis belong in adjacent focused crates.

§Examples

§Central tendency and population summaries

use use_statistics::{mean, median, population_std_dev, population_variance};

let values = [2.0, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0];

assert!((mean(&values)? - 5.0).abs() < 1.0e-12);
assert!((median(&values)? - 4.5).abs() < 1.0e-12);
assert!((population_variance(&values)? - 4.0).abs() < 1.0e-12);
assert!((population_std_dev(&values)? - 2.0).abs() < 1.0e-12);

§Sample summaries

use use_statistics::{sample_std_dev, sample_variance};

let sample = [1.0, 2.0, 3.0, 4.0];

assert!((sample_variance(&sample)? - 1.666_666_666_666_666_7).abs() < 1.0e-12);
assert!((sample_std_dev(&sample)? - 1.290_994_448_735_805_6).abs() < 1.0e-12);

§Status

use-statistics is a concrete pre-1.0 crate in the RustUse docs surface. The API remains intentionally small while adjacent probability and numeric-analysis crates continue to grow around it. Statistical utilities for RustUse.

Modules§

prelude
Common ergonomic imports for use-statistics.

Enums§

StatisticsError
Errors returned by statistics helpers when the input cannot support the requested summary.

Functions§

mean
Returns the arithmetic mean of values.
median
Returns the median of values.
population_std_dev
Returns the population standard deviation of values.
population_variance
Returns the population variance of values.
sample_std_dev
Returns the sample standard deviation of values using Bessel’s correction.
sample_variance
Returns the sample variance of values using Bessel’s correction.