Skip to main content

mann_kendall_test

Function mann_kendall_test 

Source
pub fn mann_kendall_test(data: &[f64]) -> Option<MannKendallResult>
Expand description

Mann-Kendall non-parametric trend test with Sen’s slope estimator.

Tests H₀: no monotonic trend vs H₁: monotonic trend exists. Assumes serially independent observations (no autocorrelation).

§Algorithm

  1. S = Σᵢ<ⱼ sign(xⱼ - xᵢ)
  2. Var(S) = [n(n-1)(2n+5) - Σ tₖ(tₖ-1)(2tₖ+5)] / 18 (tie-corrected)
  3. Z = (S-1)/√Var(S) if S>0, 0 if S=0, (S+1)/√Var(S) if S<0
  4. Sen’s slope = median of all pairwise slopes (xⱼ - xᵢ)/(j - i)

References:

  • Mann (1945), “Nonparametric tests against trend”
  • Kendall (1975), “Rank Correlation Methods”
  • Sen (1968), “Estimates of the regression coefficient based on Kendall’s tau”

§Complexity

O(n² log n) — pairwise comparisons O(n²) plus median finding O(n² log n²).

§Returns

None if fewer than 4 data points, non-finite values, or zero variance.

§Examples

use u_analytics::testing::mann_kendall_test;

// Clear upward trend
let data = [1.0, 2.3, 3.1, 4.5, 5.2, 6.8, 7.1, 8.9, 9.5, 10.2];
let r = mann_kendall_test(&data).unwrap();
assert!(r.p_value < 0.01);
assert!(r.kendall_tau > 0.8);
assert!(r.sen_slope > 0.0);