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.ndarrayinputs (no pandas). NaN-tolerant: rows where any input is NaN are dropped before fitting (vianp_any_axis1()), and NaN is restored at those positions in the output. Used bycore/clean_y.py’s “protect” covariate-regression mode (protected OLS), wherex_protectholds variables whose effect should be kept inywhilex_nuisanceis 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