nispace.stats.misc.residuals_nan

nispace.stats.misc.residuals_nan(x, y, decenter=False)[source]

OLS residuals of y on x (plus intercept), NaN-tolerant.

NaN-tolerant sibling of residuals(): rows where any of x/y is NaN are dropped before fitting (via np_any_axis1()), and NaN is restored at those positions in the output. Numba-compiled; requires plain np.ndarray inputs (no pandas). This is the version actually used throughout NiSpace: by core/clean_y.py for covariate regression and by core/colocalize.py’s _rank_regress to residualize X/Y against Z before correlating (the real mechanism behind method="partialpearson"/"partialspearman" in colocalize() — see nispace.stats.coloc.partialcorr() for the closed-form alternative that is not on this code path).

Parameters:
  • x (numpy.ndarray) – shape (n_values, n_predictors)

  • y (numpy.ndarray) – shape (n_values, 1) or (n_values,)

  • decenter (bool, optional) – add mean of y to residuals before return

Returns:

1D array of residuals w or w/o added mean of y, NaN where input had NaN

Return type:

numpy.ndarray