Skip to main content

Module correlation

Module correlation 

Source
Expand description

Correlation kernels — zero-allocation over caller-owned slices.

Canonical home for Pearson / Spearman / Kendall correlation. Specialized libraries call these rather than re-implementing them. Ranking (for Spearman) writes into a caller-owned buffer so this layer allocates nothing.

Functions§

correlation_p_value
Two-sided p-value for a Pearson/Spearman correlation coefficient r over n observations, via the t statistic t = r·√((n−2)/(1−r²)) with df = n−2. None if n < 3. A perfect |r| = 1 yields p = 0.
kendall
Kendall’s correlation (concordant−discordant over total pairs). O(n²), no allocation. None if the lengths differ or n < 2; Some(0.0) if no pairs differ.
pearson
Pearson product-moment correlation. None if the lengths differ or n < 2. Returns Some(0.0) when either series has zero variance (matches the historical call sites this replaced).
rank_into
Rank values (1-based, ties averaged) into the caller-owned ranks_out. idx_scratch is a caller-owned index buffer; both must equal values.len(). Returns None on a length mismatch. No allocation.
spearman
Spearman rank correlation: Pearson on the (tie-averaged) ranks. None if the lengths differ or n < 2. Convenience wrapper over rank_into + pearson; it allocates two n-length rank buffers (use rank_into directly for a zero-allocation path).