netneurotools.stats.residualize

netneurotools.stats.residualize(X, Y, Xc=None, Yc=None, normalize=True, add_intercept=True)[source]

Return residuals of regression equation from Y ~ X.

Parameters:
  • X ((N[, R]) array_like) – Coefficient matrix of R variables for N subjects

  • Y ((N[, F]) array_like) – Dependent variable matrix of F variables for N subjects

  • Xc ((M[, R]) array_like, optional) – Coefficient matrix of R variables for M subjects. If not specified then X is used to estimate betas. Default: None

  • Yc ((M[, F]) array_like, optional) – Dependent variable matrix of F variables for M subjects. If not specified then Y is used to estimate betas. Default: None

  • normalize (bool, optional) – Whether to normalize (i.e., z-score) residuals. Will use residuals from Yc ~ Xc for generating mean and variance. Default: True

  • add_intercept (bool, optional) – Whether to add intercept to X (and Xc, if provided). The intercept will not be removed, just used in beta estimation. Default: True

Returns:

Yr – Residuals of Y ~ X

Return type:

(N, F) numpy.ndarray

Notes

If both Xc and Yc are provided, these are used to calculate betas which are then applied to X and Y.