Expand description
§use-statistics
Small statistical summary helpers for `RustUse`.
Explicit mean, median, variance, and standard-deviation helpers over numeric slices.
§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 tendencymean and median cover the two common location summaries directly.
|
Dispersionpopulation_variance, sample_variance, population_std_dev, and sample_std_dev keep the estimator choice explicit.
|
Explicit invalid-input handlingStatisticsError distinguishes empty-input cases from undersized sample calculations.
|
| Helper group | Primary items | Best fit |
|---|---|---|
| Central tendency | mean, median | Small apps and utilities that need direct descriptive summaries |
| Dispersion | population_variance, sample_variance, population_std_dev, sample_std_dev | Call sites that should remain explicit about population vs. sample summaries |
| Error handling | StatisticsError | Code 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.
| Scenario | Use use-statistics directly? | Why |
|---|---|---|
You need descriptive summaries over f64 slices | Yes | The current API already covers the common location and dispersion cases directly |
| You want explicit population-vs-sample summary functions | Yes | The function names keep estimator choice visible at the call site |
| You also need probability, calculus, or other math domains | Usually no | use-math can compose the concrete surfaces behind features |
§Scope
- The current surface is intentionally small and concrete.
- Helpers operate over borrowed
f64slices 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§
- Statistics
Error - 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
valuesusing Bessel’s correction. - sample_
variance - Returns the sample variance of
valuesusing Bessel’s correction.