cb.correct.apply_cComBat: Adjust for batch effects using an empirical Bayes framework

View source: R/combat_helpers.R

cb.correct.apply_cComBatR Documentation

Adjust for batch effects using an empirical Bayes framework

Description

ComBat allows users to adjust for batch effects in datasets where the batch covariate is known, using methodology described in Johnson et al. 2007. It uses either parametric or non-parametric empirical Bayes frameworks for adjusting data for batch effects. Users are returned an expression matrix that has been corrected for batch effects. The input data are assumed to be cleaned and normalized before batch effect removal.

Usage

cb.correct.apply_cComBat(Ys, Ts, Xs, Model)

Arguments

Ys

an [n, d] matrix, for the outcome variables with n samples in d dimensions.

Ts

[n] the labels of the samples, with K < n levels, as a factor variable.

Xs

[n, r] the r covariates/confounding variables, for each of the n samples, as a data frame with named columns.

Model

a list containing the following parameters:

  • Var the pooled variance

  • Grand.mean the overall mean of the data

  • B.hat the fit regression coefficients

  • Gamma additive batch effects

  • Delta multiplicative batch effects

  • Levels the order of levels for each batch

  • Covar.Mod the covariate model for adjustment

This model is output after fitting with cb.correct.matching_cComBat.

Details

Note: this code is adapted directly from the ComBat algorithm featured in the 'sva' package.

Value

an [n, d] matrix, the batch-effect corrected data.

Examples

library(causalBatch)
sim <- cb.sims.sim_linear(a=-1, n=200, err=1/8, unbalancedness=3)
# fit batch effect correction for first 100 samples
cb.fit <- cb.correct.matching_cComBat(sim$Ys[1:100,,drop=FALSE], sim$Ts[1:100], 
                                  data.frame(Covar=sim$Xs[1:100,,drop=FALSE]), "Covar")
# apply to all samples
cor.dat <- cb.correct.apply_cComBat(sim$Ys, sim$Ts, data.frame(Covar=sim$Xs), cb.fit$Model)


causalBatch documentation built on April 3, 2025, 8:38 p.m.