compute_lambda: Compute the lambda index for determining a need for batch...

View source: R/lambda_statistic.R

compute_lambdaR Documentation

Compute the lambda index for determining a need for batch correction

Description

This function calculates the proportions of variation explained by batch, group, and residual for each gene using two-way ANOVA and computes the lambda index based on these three proportions.

Usage

compute_lambda(dat, batchind, groupind)

Arguments

dat

Numeric matrix of dimension (genes x samples) where each row represents one gene's expression across samples.

batchind

Factor or numeric vector of length = ncol(dat); batch indicator for each sample

groupind

Factor or numeric vector of length = ncol(dat); biological group label/indicator for each sample.

Value

Named numeric vector with elements:

BatchV

Proportion of total variance explained by batch effects.

GroupV

Proportion of total variance explained by group effects.

ResidV

Proportion of total variance that is residual noise.

lambda_raw

Raw lambda index = total SS_batch / total SS_group.

lambda_adj

Adjusted lambda = lambda_raw * ResidV/(1-ResidV).

Examples


library(scran)
se <- mockSCE()
res <- BatchQC::compute_lambda(assays(se)[["counts"]],
  colData(se)$Mutation_Status,
  colData(se)$Treatment)
print(res)


compbiomed/BatchQC documentation built on June 10, 2025, 8:32 p.m.