pub fn bartlett_test(groups: &[&[f64]]) -> Option<TestResult>Expand description
Bartlett test for equality of variances: H₀: all groups have equal variance.
Assumes data are from normal distributions. For non-normal data, prefer
levene_test (Brown-Forsythe variant).
§Algorithm
- Compute pooled variance: s²ₚ = Σ(nᵢ-1)s²ᵢ / (N-k)
- Numerator: (N-k) ln(s²ₚ) - Σ(nᵢ-1) ln(s²ᵢ)
- Correction factor: C = 1 + [1/(3(k-1))] × [Σ 1/(nᵢ-1) - 1/(N-k)]
- Statistic: T = numerator / C ~ χ²(k-1)
§Returns
None if fewer than 2 groups, any group < 2 observations, any group has
zero variance, or non-finite values.
§References
- Bartlett (1937). “Properties of sufficiency and statistical tests”. Proceedings of the Royal Society A, 160(901), 268–282.
§Examples
use u_analytics::testing::bartlett_test;
let g1 = [2.0, 3.0, 4.0, 5.0, 6.0]; // variance ~2.5
let g2 = [10.0, 20.0, 30.0, 40.0, 50.0]; // variance ~250
let r = bartlett_test(&[&g1, &g2]).unwrap();
assert!(r.p_value < 0.01); // strongly different variances