Entering edit mode
I'd like to use ComBat() from the sva library for batch effect correction. Let's say I have this data frame:
gene_data <- data.frame(
Gene1 = c(5.2, 5.5, 6.1, 6.4, 5.0, 5.3, 6.0, 6.2),
Gene2 = c(4.8, 4.7, 5.5, 5.8, 4.9, 5.0, 5.6, 5.7),
Gene3 = c(7.1, 6.8, 7.5, 7.9, 7.3, 7.0, 7.6, 7.8),
Gene4 = c(8.2, 8.1, 8.4, 8.7, 8.3, 8.2, 8.5, 8.6),
Gene5 = c(6.0, 6.3, 6.6, 6.7, 6.1, 6.2, 6.7, 6.8)
)
batch <- factor(c(1, 1, 2, 2, 1, 1, 2, 2))
subjects <- factor(rep(1:4, each = 2)) # 4 subjects, with 2 conditions each
conditions <- factor(rep(c("A", "B"), times = 4)) # Two conditions (A and B) per subject
If I understood correctly, ComBat works for independent observations, but in this case, I have a repeated measures factor.
Will I still be able to use ComBat? For example, is this statistically valid?
gene_matrix <- as.matrix(gene_data)
mod <- model.matrix(~ conditions + subjects)
combat_corrected <- ComBat(dat = gene_matrix, batch = batch, mod = mod)
Thank you!
It looks to me that you do not need the batch information since subject is nested with batch so correcting for subject will do a paired analysis (which is within batch). In your linear model, or whatever you use, simply do
~subjects+conditions
.