nispace.stats.misc.partial_residuals_nan

nispace.stats.misc.partial_residuals_nan(x_nuisance, x_protect, y)[source]

Partial residuals: regress x_nuisance from y while controlling for x_protect.

Fits a joint model [x_nuisance | x_protect | intercept] so that nuisance coefficients are estimated controlling for the protected variables, then removes only the nuisance component. The protected effects (e.g. group differences) are preserved in the returned values.

Numba-compiled; requires plain np.ndarray inputs (no pandas). NaN-tolerant: rows where any input is NaN are dropped before fitting (via np_any_axis1()), and NaN is restored at those positions in the output. Used by core/clean_y.py’s “protect” covariate-regression mode (protected OLS), where x_protect holds variables whose effect should be kept in y while x_nuisance is removed.

Parameters:
  • x_nuisance (numpy.ndarray) – shape (n, p) — confounds to remove

  • x_protect (numpy.ndarray) – shape (n, q) — variables to control for but keep

  • y (numpy.ndarray) – shape (n,)

Returns:

shape (n,), NaN where input had NaN

Return type:

numpy.ndarray