Skip to main content

Crate tukey_test

Crate tukey_test 

Source
Expand description

Statistical tests for pairwise group comparisons.

This crate provides:

  • one_way_anova — one-way analysis of variance (F-test) with η²/ω² effect sizes
  • tukey_hsd — Tukey HSD test (assumes equal variances); any k ≥ 2
  • games_howell — Games-Howell test (does not assume equal variances); any k ≥ 2
  • dunnett — Dunnett’s test (compare treatments against a control)
  • levene_test — Brown-Forsythe/Levene test for equality of variances
  • ptukey_cdf — exact CDF of the studentized range distribution
  • q_critical — critical value lookup (any k ≥ 2, any alpha ∈ (0, 1))
  • dunnett_critical — Dunnett’s critical value lookup
  • parse_csv — load grouped data from CSV (wide format)

All test functions accept any type implementing AsRef<[f64]> for groups, so you can pass &[Vec<f64>], &[&[f64]], or &[[f64; N]].

§Example

use tukey_test::{one_way_anova, tukey_hsd};

let data = vec![
    vec![23.0, 25.0, 21.0, 24.0],  // Group A
    vec![30.0, 28.0, 33.0, 31.0],  // Group B
    vec![22.0, 24.0, 20.0, 23.0],  // Group C
];

// Step 1: check if there is an overall difference
let anova = one_way_anova(&data).unwrap();
println!("{anova}");

// Step 2: find which pairs differ
let result = tukey_hsd(&data, 0.05).unwrap();
println!("{result}");

for pair in result.significant_pairs() {
    println!("Groups {} and {} differ significantly (q = {:.4})",
        pair.group_i, pair.group_j, pair.q_statistic);
}

Structs§

AnovaResult
Results of a one-way ANOVA.
DunnettComparison
A single comparison of a treatment group against the control.
DunnettResult
Full results of a Dunnett’s test.
GamesHowellResult
Full results of a Games-Howell test.
LeveneResult
Results of a Levene / Brown-Forsythe test for equality of variances.
PairwiseComparison
A single pairwise comparison between two groups.
TukeyResult
Full results of a Tukey HSD test.

Enums§

TukeyError
Errors that can occur during Tukey test operations.

Functions§

dunnett
Perform Dunnett’s test (two-sided) comparing each treatment group against a control group.
dunnett_critical
Look up the critical value from the Dunnett distribution (two-sided).
games_howell
Perform a Games-Howell post-hoc test.
levene_test
Test whether group variances are equal (Brown-Forsythe variant, median-based).
one_way_anova
Perform a one-way analysis of variance (ANOVA).
parse_csv
Parse CSV data in wide format (each column is a group).
parse_csv_file
Convenience wrapper: parse CSV from a file path.
ptukey_cdf
CDF of the studentized range distribution P(Q ≤ q; k, df).
q_critical
Look up the critical q value from the studentized range distribution.
tukey_hsd
Perform a Tukey HSD test on grouped data.