plot::stat
The statistics a few plot types draw: histogram bins (NumPy's rules), box plot quartiles (linear interpolation, NumPy's default) and Gaussian kernel density estimates (Scott's bandwidth) for violins.
Enums
BinsSource
pub enum BinsHow a histogram picks its bins. The rules are NumPy's
histogram_bin_edges: each gives a width, and the data range is cut
into ceil(range / width) equal bins.
use plot::stat::{Bins, edges};
assert(edges([1.0, 2.0, 3.0, 4.0], Bins::Count(3)) == [1.0, 2.0, 3.0, 4.0]);
assert(edges([0.0, 10.0], Bins::Width(5.0)) == [0.0, 5.0, 10.0]);
This many equal bins.
Bins of this width from the minimum.
These edges, rising.
The smaller width of
SturgesandFd(NumPy's"auto").range / (log2(n) + 1).Freedman-Diaconis:
2 iqr / n^(1/3).range / sqrt(n).
Functions
quantileSource
pub fn quantile(sorted: List<f64>, q: f64) -> f64 The q quantile of sorted values by linear interpolation (NumPy's
default, Hyndman and Fan type 7).
assert(plot::stat::quantile([1.0, 2.0, 3.0, 4.0], 0.25) == 1.75);
edgesSource
pub fn edges(xs: List<f64>, bins: Bins) -> List<f64> Bin edges for xs (NaN and infinities ignored).
assert(plot::stat::edges([0.0, 1.0, 2.0, 3.0], plot::Bins::Count(3)) == [0.0, 1.0, 2.0, 3.0]);
countsSource
pub fn counts(xs: List<f64>, edges: List<f64>) -> List<f64> Counts of xs in the bins of edges: [e_i, e_i+1), the last bin
closed on the right.
assert(plot::stat::counts([0.5, 1.5, 1.7, 2.5], [0.5, 1.5, 2.5]) == [1.0, 3.0]);
box_statsSource
pub fn box_stats(xs: List<f64>) -> BoxStats Box plot numbers: quartiles, whiskers at the most extreme values within 1.5 IQR of the box (Tukey), and the values beyond them.
let s = plot::stat::box_stats([1.0, 2.0, 3.0, 4.0, 100.0]);
assert(s.median == 3.0 && s.hi == 4.0 && s.fliers == [100.0]);
kdeSource
pub fn kde(xs: List<f64>, points: usize) -> (List<f64>, List<f64>) A Gaussian kernel density estimate of xs at points evenly spaced
values over the data range, with Scott's bandwidth n^(-1/5) std.
Returns the positions and densities.
let (at, d) = plot::stat::kde([0.0, 1.0, 2.0], 5);
assert(at.len() == 5 && d[2] > d[0]);