Medians

GitHub last commit crates.io crates.io docs.rs

Fast new algorithm(s) for finding 1D medians, implemented in Rust.

Usage

rust use medians::{Med,Median};

Introduction

Finding the medians is a common task in statistics and general data analysis. At least it should be, if only it would not take so long. We argue in rstats that using the Geometric Median is the most stable way to characterise multidimensional data (nd). That leaves the one dimensional (1d) medians, addressed here. Medians are more stable measure of central tendency than means but they are not used nearly enough. One suspects that this is due only to being slower to compute than the arithmetic mean.

The Algorithms

Floyd-Rivest with the 'Median of Medians' approximation is currently considered to be the best algorithm. Here we explore some alternatives:

Struct Med

Holds the median, lower and upper quartiles and MAD (median of absolute differences from median). MAD is the most stable measure of data spread.

Trait Median

rust pub trait Median<T> { /// Finds the median of `&[T]`, fast fn median(&self) -> f64; /// Median of absolute differences (MAD). fn mad(self,m:f64) -> f64; /// Median, quartiles and MAD fn medinfo(self) -> Med; }

Release Notes

Version 0.1.2 - The public methods are now in trait Median.