Testing KO vs WT at day4/day14 with interactions in edgeR
1
0
Entering edit mode
Noah • 0
@fa72d297
Last seen 8 weeks ago
Germany

dge$samples$treatment <- factor(dge$samples$treatment, levels = c("WT", "KO"))
dge$samples$timepoint <- factor(dge$samples$timepoint, levels = c("bl", "day4", "day14"))

design <- model.matrix(~ batch + treatment * timepoint, data = dge$samples)

contr.mat <- makeContrasts(
  treatment_KOvsWT = treatmentKO,
  time_day4vsbl = timepointday4,
  time_day14vsbl = timepointday14,
  interaction_day4 = treatmentKO.timepointday4,
  interaction_day14 = treatmentKO.timepointday14,
  KO4_vs_WT4 = treatmentKO + treatmentKO.timepointday4,
  KO14_vs_WT14 = treatmentKO + treatmentKO.timepointday14,
  levels = design
)

> sessionInfo()
R version 4.5.0 (2025-04-11 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 22621)

Matrix products: default
  LAPACK version 3.12.1

locale:
[1] LC_COLLATE=German_Germany.utf8  LC_CTYPE=German_Germany.utf8   
[3] LC_MONETARY=German_Germany.utf8 LC_NUMERIC=C                   
[5] LC_TIME=German_Germany.utf8    

time zone: Europe/Berlin
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
  [1] mnormt_2.1.1           deldir_2.0-4           pbapply_1.7-4          gridExtra_2.3         
  [5] rlang_1.1.6            magrittr_2.0.3         RcppAnnoy_0.0.22       matrixStats_1.5.0     
  [9] ggridges_0.5.6         compiler_4.5.0         spatstat.geom_3.5-0    png_0.1-8             
 [13] vctrs_0.6.5            reshape2_1.4.4         stringr_1.5.1          pkgconfig_2.0.3       
 [17] fastmap_1.2.0          promises_1.3.3         purrr_1.1.0            jsonlite_2.0.0        
 [21] goftest_1.2-3          later_1.4.2            spatstat.utils_3.1-5   psych_2.5.6           
 [25] irlba_2.3.5.1          parallel_4.5.0         cluster_2.1.8.1        R6_2.6.1              
 [29] ica_1.0-3              stringi_1.8.7          RColorBrewer_1.1-3     spatstat.data_3.1-6   
 [33] limma_3.64.3           reticulate_1.43.0      parallelly_1.45.1      spatstat.univar_3.1-4 
 [37] lmtest_0.9-40          scattermore_1.2        Rcpp_1.0.14            tensor_1.5.1          
 [41] future.apply_1.20.0    zoo_1.8-14             sctransform_0.4.2      httpuv_1.6.16         
 [45] Matrix_1.7-3           splines_4.5.0          igraph_2.1.4           tidyselect_1.2.1      
 [49] abind_1.4-8            codetools_0.2-20       spatstat.random_3.4-1  miniUI_0.1.2          
 [53] spatstat.explore_3.5-2 listenv_0.9.1          lattice_0.22-6         tibble_3.2.1          
 [57] plyr_1.8.9             shiny_1.11.1           ROCR_1.0-11            Rtsne_0.17            
 [61] future_1.67.0          fastDummies_1.7.5      survival_3.8-3         polyclip_1.10-7       
 [65] fitdistrplus_1.2-4     BiocManager_1.30.26    pillar_1.11.0          Seurat_5.3.0          
 [69] KernSmooth_2.23-26     plotly_4.11.0          generics_0.1.4         RcppHNSW_0.6.0        
 [73] sp_2.2-0               ggplot2_3.5.2          scales_1.4.0           globals_0.18.0        
 [77] xtable_1.8-4           glue_1.8.0             lazyeval_0.2.2         tools_4.5.0           
 [81] data.table_1.17.8      RSpectra_0.16-2        locfit_1.5-9.12        RANN_2.6.2            
 [85] dotCall64_1.2          cowplot_1.2.0          grid_4.5.0             tidyr_1.3.1           
 [89] edgeR_4.6.3            nlme_3.1-168           patchwork_1.3.1        cli_3.6.5             
 [93] spatstat.sparse_3.1-0  spam_2.11-1            viridisLite_0.4.2      dplyr_1.1.4           
 [97] uwot_0.2.3             gtable_0.3.6           digest_0.6.37          progressr_0.15.1      
[101] ggrepel_0.9.6          htmlwidgets_1.6.4      SeuratObject_5.1.0     farver_2.1.2          
[105] htmltools_0.5.8.1      lifecycle_1.0.4        httr_1.4.7             statmod_1.5.0         
[109] mime_0.13              MASS_7.3-65
scRNAseq • 260 views
ADD COMMENT
0
Entering edit mode

I originally tried to include my full question and code in one post, but there was an upload problem. I am therefore posting the code separately above, and here in this comment I am adding the questions and experimental context.

I have an scRNA-seq experiment with mice and two factors:

treatment: WT / KO

timepoint: baseline (bl), day4, day14

Mice were sacrificed at each timepoint (no repeated measures). We also have a batch variable (sequencing batch).

Raw counts (after QC) were pseudobulked per subcell type, for each combination of condition, timepoint, and batch (e.g., capillary endothelial cells, KO, day4, batch 7).

Goal:

1) Test KO vs WT within each timepoint (bl, day4, day14) 2) Test for an interaction (KO-WT difference changes from baseline to day4/day14) 3) Keep batch as a covariate

Questions:

1) Are my contrasts correct for KO vs WT within day4 and day14? 2) Can I use these "direct comparisons" without the interaction term if I only care about KO vs WT at a single timepoint? 3) Should I keep batch in the model even after Harmony batch correction during clustering?

ADD REPLY
1
Entering edit mode
@gordon-smyth
Last seen 10 hours ago
WEHI, Melbourne, Australia

If you are interested in KO vs WT for each timepoint, then you would much better off using the group-mean representation of the model instead of the factorial model you are using. The correct contrasts would then be obvious and transparent. I think that factorial models are seldom a good choice for genomic analyses. The group-mean approach is described in the limma and edgeR User's Guides, and also in Law et al (2020).

You probably need to omit batch from the pseudo-bulk analysis, but that's just my guess, not being involved in the details of your experiment.

Law CW, Zeglinski K, Dong X, Alhamdoosh M, Smyth GK, Ritchie ME (2020). A guide to creating design matrices for gene expression experiments. F1000Research 9, 1444.

ADD COMMENT

Login before adding your answer.

Traffic: 608 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6