Run ComBat on a SCtkExperiment object

ComBatSCE(
  inSCE,
  batch,
  useAssay = "logcounts",
  par.prior = "Parametric",
  covariates = NULL,
  mean.only = FALSE,
  ref.batch = NULL
)

Arguments

inSCE

Input SCtkExperiment object. Required

batch

The name of a column in colData to use as the batch variable. Required

useAssay

The assay to use for ComBat. The default is "logcounts"

par.prior

TRUE indicates parametric adjustments will be used, FALSE indicates non-parametric adjustments will be used. Accepted parameters: "Parametric" or "Non-parametric"

covariates

List of other column names in colData to be added to the ComBat model as covariates

mean.only

If TRUE ComBat only corrects the mean of the batch effect

ref.batch

If given, will use the selected batch as a reference for batch adjustment.

Value

ComBat matrix based on inputs. You can save this matrix into the SCtkExperiment with assay()

Examples

if(requireNamespace("bladderbatch", quietly = TRUE)) {
  library(bladderbatch)
  data(bladderdata)

  #subset for testing
  dat <- bladderEset[1:50,]
  dat <- as(as(dat, "SummarizedExperiment"), "SCtkExperiment")
  mod <- stats::model.matrix(~as.factor(cancer), data = colData(dat))

  # parametric adjustment
  combat_edata1 <- ComBatSCE(inSCE = dat, useAssay = "exprs",
                             batch = "batch", covariates = NULL)
  assay(dat, "parametric_combat") <- combat_edata1

  # non-parametric adjustment, mean-only version
  combat_edata2 <- ComBatSCE(inSCE = dat, useAssay = "exprs",
                             batch = "batch", par.prior = "Non-parametric",
                             mean.only = TRUE, covariates = NULL)
  assay(dat, "nonparametric_combat_meanonly") <- combat_edata2

  # reference-batch version, with covariates
  combat_edata3 <- ComBatSCE(inSCE = dat, useAssay = "exprs",
                             batch = "batch", covariates = "cancer",
                             ref.batch = 3)
  assay(dat, "refbatch_combat_wcov") <- combat_edata3
  assays(dat)
}
#> Found5batches
#> Adjusting for0covariate(s) or covariate level(s)
#> Standardizing Data across genes
#> Fitting L/S model and finding priors
#> Finding parametric adjustments
#> Adjusting the Data
#> Using the 'mean only' version of ComBat
#> Found5batches
#> Adjusting for0covariate(s) or covariate level(s)
#> Standardizing Data across genes
#> Fitting L/S model and finding priors
#> Finding nonparametric adjustments
#> Adjusting the Data
#> Using batch =3as a reference batch (this batch won't change)
#> Found5batches
#> Adjusting for2covariate(s) or covariate level(s)
#> Standardizing Data across genes
#> Fitting L/S model and finding priors
#> Finding parametric adjustments
#> Adjusting the Data
#> List of length 5
#> names(5): exprs se.exprs parametric_combat nonparametric_combat_meanonly refbatch_combat_wcov