Descriptive Statistics
Arithmetic mean: μ = (1/n) Σᵢ xᵢ. Supports axis-wise reduction with optional dimension preservation.
Middle value when data is sorted. For even-sized arrays, returns the average of the two middle values. More robust to outliers than mean.
Most frequently occurring value. For multiple modes, returns the smallest.
Standard deviation: σ = √(Var(x)). Measures the spread of values around the mean. ddof=0 for population, ddof=1 for sample.
Variance: σ² = (1/n) Σᵢ (xᵢ − μ)². Square of the standard deviation.
Third standardized moment. Measures asymmetry. Positive = right-skewed, negative = left-skewed, 0 = symmetric.
Fourth standardized moment (excess kurtosis by default). Measures tail heaviness. >0 = heavy tails, <0 = light tails, 0 = normal-like.
Value below which q% of data falls. q must be in [0, 100]. percentile(t, 50) equals the median.
Same as percentile but q is in [0, 1]. quantile(t, 0.5) equals the median.
Compute the nth central moment about the mean. moment(t, 2) is the variance, moment(t, 3) relates to skewness.
Geometric mean: (∏ xᵢ)^(1/n). Appropriate for data that is multiplied together or grows exponentially. All values must be positive.
Harmonic mean: n / Σ(1/xᵢ). Appropriate for rates and ratios. All values must be positive. Always ≤ geometric mean ≤ arithmetic mean.
Trimmed mean: compute the mean after removing a fraction of the smallest and largest values. proportiontocut in [0, 0.5). Robust to outliers.
import { mean, median, std, variance, skewness, kurtosis, percentile, geometricMean, trimMean } from "deepbox/stats";import { tensor } from "deepbox/ndarray";const data = tensor([2, 4, 4, 4, 5, 5, 7, 9]);mean(data); // 5.0median(data); // 4.5std(data); // population stdstd(data, undefined, false, 1); // sample std (ddof=1)variance(data); // population varianceskewness(data); // asymmetry measurekurtosis(data); // excess kurtosispercentile(data, 75); // 75th percentile// Robust statisticsgeometricMean(data); // geometric meantrimMean(data, 0.1); // trim 10% from each end