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
rovernobservations, via the t statistict = r·√((n−2)/(1−r²))withdf = n−2.Noneifn < 3. A perfect|r| = 1yieldsp = 0. - kendall
- Kendall’s correlation (concordant−discordant over total pairs). O(n²), no
allocation.
Noneif the lengths differ or n < 2;Some(0.0)if no pairs differ. - pearson
- Pearson product-moment correlation.
Noneif the lengths differ or n < 2. ReturnsSome(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-ownedranks_out.idx_scratchis a caller-owned index buffer; both must equalvalues.len(). ReturnsNoneon a length mismatch. No allocation. - spearman
- Spearman rank correlation: Pearson on the (tie-averaged) ranks.
Noneif the lengths differ or n < 2. Convenience wrapper overrank_into+pearson; it allocates twon-length rank buffers (userank_intodirectly for a zero-allocation path).