nispace.stats.coloc.partialcorr
- nispace.stats.coloc.partialcorr(x, y, z, rank=False)[source]
Closed-form partial correlation between x and y, controlling for z.
Computed via inversion of the 3-variable correlation matrix, not by residualization.
- Parameters:
x (np.ndarray, shape (n,), dtype float) – Numba-jitted: must be plain 1D
np.ndarrayinstances of equal length. Does not handle NaN – strip/mask NaN entries before calling.y (np.ndarray, shape (n,), dtype float) – Numba-jitted: must be plain 1D
np.ndarrayinstances of equal length. Does not handle NaN – strip/mask NaN entries before calling.z (np.ndarray, shape (n,), dtype float) – Numba-jitted: must be plain 1D
np.ndarrayinstances of equal length. Does not handle NaN – strip/mask NaN entries before calling.rank (bool, default False) – If True, rank x/y/z via rank1d first (partial Spearman); if False, use raw values (partial Pearson).
- Returns:
rp – (Ranked) partial correlation coefficient between x and y.
- Return type:
float
Notes
Not on NiSpace’s live colocalize() code path: method=”partialpearson”/ “partialspearman” there is computed by residualizing X/Y against Z first (core/colocalize.py’s _rank_regress -> residuals_nan) and then correlating the residuals with plain pearson, not by this closed-form formula. Provided as a standalone utility.