scib.metrics.pcr.linreg_multiple_np
- scib.metrics.pcr.linreg_multiple_np(X_pca, covariate, n_jobs=None)
Compute per-PC \(R^2\) with a dense numpy regression backend.
- Execution has two paths:
If exactly one non-numeric covariate is provided, use a fast one-way ANOVA formulation based on between-group variance. This is automatically used for one non-numeric covariate.
Otherwise, run dense least-squares regression using an intercept and pseudo-inverse.
- One-way ANOVA path:
For a single categorical covariate, compute per-PC
R2 = SS_between / SS_totalwhereSS_between = sum_g n_g * (mu_g - mu)^2andSS_total = sum_i (y_i - mu)^2. This is algebraically equivalent to linear regression with categorical indicators and an intercept, but avoids explicit design-matrix solves.- Thread control:
If
n_jobsis provided andthreadpoolctlis installed, BLAS/LAPACK thread pools are limited for the full function scope (including shortcut checks and dense regression). This keeps runtime behavior reproducible across environments and avoids BLAS oversubscription.
Used by
linreg_method='numpy'inpc_regression().- Parameters:
n_jobs – Preferred number of BLAS/LAPACK threads for numpy linalg calls. If
None, keep the runtime default. Ifthreadpoolctlis unavailable, this hint is ignored.