stemangiola / tidybulk

Brings bulk and pseudobulk transcriptomics to the tidyverse
https://stemangiola.github.io/tidybulk/
164 stars 25 forks source link

Remove batch effect in test_differential_abundance #270

Closed jianwu1 closed 1 year ago

jianwu1 commented 1 year ago

Hi @stemangiola ,

Can I ask how to remove batch effect for DE analysis using tidybulk? I try to include batch factor in the linear model for test_differential_abundance but the code gives error. I have a design matrix:

Screen Shot 2023-05-29 at 11 01 55 am

from which I want to do DE between different conditions, but want to remove batch effect considering the batch column

  test_differential_abundance(
   .formula = ~ 0 + condition + batch,
   .contrasts = mean_contrast(counts, condition),
   method = "edgeR_quasi_likelihood", 
   action = "only" )

mean_contrast outputs a vector of comparisons that I want to make:

Screen Shot 2023-05-28 at 3 22 02 pm

However, running this code gives the error:

Screen Shot 2023-05-28 at 3 23 04 pm

Best wishes,

Jian