pub fn remove_batch_effect<T: EdgeFloat>(
x: &[T],
n_genes: usize,
n_samples: usize,
batch: Option<&[usize]>,
batch2: Option<&[usize]>,
covariates: Option<(&[f64], usize)>,
design: Option<(&[f64], usize)>,
weights: Option<&Recycled<f64>>,
) -> Result<Vec<f64>, EdgeErrors>Expand description
Removes batch effects and covariates from a log-expression matrix.
Port of limma’s removeBatchEffect without group. Fits
cbind(design, X_batch) per gene with lm_fit, where
X_batch = cbind(contr.sum(batch), contr.sum(batch2), covariates), and
returns x - beta_batch %*% t(X_batch). As in limma, covariates are
column-centred first, aliased coefficients count as zero, and with no
batch, second batch or covariates the input comes back unchanged.
§Params
x- Log-expression, row-majorn_genes * n_samples. Non-finite entries are treated as missing by the fit and stay non-finite in the output.n_genes- Number of genesn_samples- Number of samplesbatch- Optional batch label per samplebatch2- Optional second batch label per samplecovariates- Optional numeric covariates, row-majorn_samples * n_cov, withn_covdesign- Optional design of interest, row-majorn_samples * n_coef, withn_coef.Noneis an intercept only.weights- Optional observation weights, forwarded tolm_fitas limma’s...does
§Returns
The corrected matrix, row-major n_genes * n_samples, or EdgeErrors if a
shape disagrees or a batch factor has fewer than two levels.
§References
Smyth, Statistical Applications in Genetics and Molecular Biology 3(1), 2004