#correlation #statistics

kendalls

Kendall's tau rank correlation

10 releases (1 stable)

Uses new Rust 2024

1.0.0 May 27, 2025
0.2.2 Jul 8, 2024
0.2.1 Feb 8, 2022
0.2.0 May 17, 2021
0.1.1 Aug 29, 2018

#674 in Algorithms

Download history 4/week @ 2025-12-29 18/week @ 2026-01-05 17/week @ 2026-01-12 39/week @ 2026-01-19 55/week @ 2026-01-26 67/week @ 2026-02-02 122/week @ 2026-02-09 64/week @ 2026-02-16 2/week @ 2026-02-23 8/week @ 2026-03-02 17/week @ 2026-03-09 58/week @ 2026-03-16 97/week @ 2026-03-23 394/week @ 2026-03-30 443/week @ 2026-04-06 450/week @ 2026-04-13

1,394 downloads per month
Used in 2 crates

MIT license

18KB
328 lines

Kendall's tau rank correlation. Initially the library was based on Apache Commons Math library with some additions taken from scipy and R cor.test function.

Example usage:

let (tau_b, significance) = kendalls::tau_b(&[1, 2, 3], &[3, 4, 5]).unwrap();
assert_eq!(tau_b, 1.0);
assert_eq!(significance, 1.5666989036012806);

If you want to compute correlation, let's say, for f64 type, then you will have to provide either a custom comparator function or declare Ord trait for your custom floating point numbers type (see float crate).

use std::cmp::Ordering;

let (tau_b, _significance) = kendalls::tau_b_with_comparator(
    &[1.0, 2.0],
    &[3.0, 4.0],
    |a: &f64, b: &f64| a.partial_cmp(&b).unwrap_or(Ordering::Greater),
).unwrap();
assert_eq!(tau_b, 1.0);

The function will return an error if you pass empty arrays into it or x and y arrays' dimensions are not equal.


kendalls

crates.io docs.rs codecov

Kendall's rank correlation coefficient

Usage

Add this to your Cargo.toml:

[dependencies]
kendalls = "1.0.0"

and this to your crate root:

extern crate kendalls;

Example:

fn main() -> Result<(), kendalls::Error> {
    let (tau_b, significance) = kendalls::tau_b(&[1, 2, 3], &[3, 4, 5])?;
    assert_eq!(tau_b, 1.0);
    assert_eq!(significance, 1.5666989036012806);

    Ok(())
}

No runtime deps