Results from the univariate regressions performed using can be combined in a post-processing step to perform multivariate hypothesis testing. In this example, we fit on transcript-level counts and then perform multivariate hypothesis testing by combining transcripts at the gene-level. This is done with the function.

Import transcript-level counts

Read in transcript counts from the package.

library(readr)
library(tximport)
library(tximportData)

# specify directory
path <- system.file("extdata", package = "tximportData")

# read sample meta-data
samples <- read.table(file.path(path, "samples.txt"), header = TRUE)
samples.ext <- read.table(file.path(path, "samples_extended.txt"), header = TRUE, sep = "\t")

# read assignment of transcripts to genes
# remove genes on the PAR, since these are present twice
tx2gene <- read_csv(file.path(path, "tx2gene.gencode.v27.csv"))
tx2gene <- tx2gene[grep("PAR_Y", tx2gene$GENEID, invert = TRUE), ]

# read transcript-level quatifictions
files <- file.path(path, "salmon", samples$run, "quant.sf.gz")
txi <- tximport(files, type = "salmon", txOut = TRUE)

# Create metadata simulating two conditions
sampleTable <- data.frame(condition = factor(rep(c("A", "B"), each = 3)))
rownames(sampleTable) <- paste0("Sample", 1:6)

Standard dream analysis

Perform standard analysis at the transcript-level

library(variancePartition)
library(edgeR)

# Prepare transcript-level reads
dge <- DGEList(txi$counts)
design <- model.matrix(~condition, data = sampleTable)
isexpr <- filterByExpr(dge, design)
dge <- dge[isexpr, ]
dge <- calcNormFactors(dge)

# Estimate precision weights
vobj <- voomWithDreamWeights(dge, ~condition, sampleTable)

# Fit regression model one transcript at a time
fit <- dream(vobj, ~condition, sampleTable)
fit <- eBayes(fit)

Multivariate analysis

Combine the transcript-level results at the gene-level. The mapping between transcript and gene is stored in as a list.

# Prepare transcript to gene mapping
# keep only transcripts present in vobj
# then convert to list with key GENEID and values TXNAMEs
keep <- tx2gene$TXNAME %in% rownames(vobj)
tx2gene.lst <- unstack(tx2gene[keep, ])

# Run multivariate test on entries in each feature set
# Default method is "FE.empirical", but use "FE" here to reduce runtime
res <- mvTest(fit, vobj, tx2gene.lst, coef = "conditionB", method = "FE")

# truncate gene names since they have version numbers
# ENST00000498289.5 -> ENST00000498289
res$ID.short <- gsub("\\..+", "", res$ID)

Gene set analysis

Perform gene set analysis using on the gene-level test statistics.

# must have zenith > v1.0.2
library(zenith)
library(GSEABase)

gs <- get_MSigDB("C1", to = "ENSEMBL")

df_gsa <- zenithPR_gsa(res$stat, res$ID.short, gs, inter.gene.cor = .05)

head(df_gsa)
##          NGenes Correlation      delta       se    p.less    p.greater       PValue Direction
## chr7p13      28        0.05  7.1442404 2.034359 0.9997768 0.0002231723 0.0004463445        Up
## chr12q22     21        0.05 -1.2430448 2.168941 0.2832887 0.7167112635 0.5665774729      Down
## chr2q34      11        0.05 -0.2681142 2.595116 0.4588572 0.5411428235 0.9177143530      Down
##                  FDR  Geneset     coef
## chr7p13  0.001339034  chr7p13 zenithPR
## chr12q22 0.849866209 chr12q22 zenithPR
## chr2q34  0.917714353  chr2q34 zenithPR

Session info

## R version 4.5.0 beta (2025-04-02 r88102)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.2 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.22-bioc/R/lib/libRblas.so 
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0  LAPACK version 3.12.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_GB             
##  [4] LC_COLLATE=C               LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
## [10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## time zone: America/New_York
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats4    stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] GSEABase_1.71.0          graph_1.87.0             annotate_1.87.0         
##  [4] XML_3.99-0.18            AnnotationDbi_1.71.0     IRanges_2.43.0          
##  [7] S4Vectors_0.47.0         Biobase_2.69.0           BiocGenerics_0.55.0     
## [10] generics_0.1.3           zenith_1.11.0            tximportData_1.35.0     
## [13] tximport_1.37.0          readr_2.1.5              edgeR_4.7.0             
## [16] pander_0.6.6             variancePartition_1.39.0 BiocParallel_1.43.0     
## [19] limma_3.65.0             ggplot2_3.5.2            knitr_1.50              
## 
## loaded via a namespace (and not attached):
##   [1] jsonlite_2.0.0              magrittr_2.0.3              farver_2.1.2               
##   [4] nloptr_2.2.1                rmarkdown_2.29              vctrs_0.6.5                
##   [7] memoise_2.0.1               minqa_1.2.8                 RCurl_1.98-1.17            
##  [10] progress_1.2.3              S4Arrays_1.9.0              htmltools_0.5.8.1          
##  [13] broom_1.0.8                 SparseArray_1.9.0           sass_0.4.10                
##  [16] KernSmooth_2.23-26          bslib_0.9.0                 pbkrtest_0.5.3             
##  [19] plyr_1.8.9                  cachem_1.1.0                lifecycle_1.0.4            
##  [22] iterators_1.0.14            pkgconfig_2.0.3             Matrix_1.7-3               
##  [25] R6_2.6.1                    fastmap_1.2.0               GenomeInfoDbData_1.2.14    
##  [28] rbibutils_2.3               MatrixGenerics_1.21.0       digest_0.6.37              
##  [31] numDeriv_2016.8-1.1         colorspace_2.1-1            GenomicRanges_1.61.0       
##  [34] RSQLite_2.3.9               labeling_0.4.3              abind_1.4-8                
##  [37] httr_1.4.7                  compiler_4.5.0              bit64_4.6.0-1              
##  [40] aod_1.3.3                   withr_3.0.2                 backports_1.5.0            
##  [43] DBI_1.2.3                   gplots_3.2.0                MASS_7.3-65                
##  [46] DelayedArray_0.35.0         corpcor_1.6.10              gtools_3.9.5               
##  [49] caTools_1.18.3              tools_4.5.0                 msigdbr_10.0.2             
##  [52] remaCor_0.0.18              glue_1.8.0                  nlme_3.1-168               
##  [55] grid_4.5.0                  reshape2_1.4.4              snow_0.4-4                 
##  [58] gtable_0.3.6                tzdb_0.5.0                  tidyr_1.3.1                
##  [61] hms_1.1.3                   XVector_0.49.0              pillar_1.10.2              
##  [64] stringr_1.5.1               babelgene_22.9              vroom_1.6.5                
##  [67] splines_4.5.0               dplyr_1.1.4                 lattice_0.22-7             
##  [70] bit_4.6.0                   tidyselect_1.2.1            locfit_1.5-9.12            
##  [73] Biostrings_2.77.0           reformulas_0.4.0            SummarizedExperiment_1.39.0
##  [76] RhpcBLASctl_0.23-42         xfun_0.52                   statmod_1.5.0              
##  [79] matrixStats_1.5.0           KEGGgraph_1.69.0            stringi_1.8.7              
##  [82] UCSC.utils_1.5.0            yaml_2.3.10                 boot_1.3-31                
##  [85] evaluate_1.0.3              codetools_0.2-20            archive_1.1.12             
##  [88] tibble_3.2.1                Rgraphviz_2.53.0            cli_3.6.4                  
##  [91] RcppParallel_5.1.10         xtable_1.8-4                Rdpack_2.6.4               
##  [94] munsell_0.5.1               jquerylib_0.1.4             Rcpp_1.0.14                
##  [97] GenomeInfoDb_1.45.0         zigg_0.0.2                  EnvStats_3.0.0             
## [100] png_0.1-8                   Rfast_2.1.5.1               parallel_4.5.0             
## [103] assertthat_0.2.1            blob_1.2.4                  prettyunits_1.2.0          
## [106] bitops_1.0-9                lme4_1.1-37                 mvtnorm_1.3-3              
## [109] lmerTest_3.1-3              scales_1.3.0                purrr_1.0.4                
## [112] crayon_1.5.3                fANCOVA_0.6-1               rlang_1.1.6                
## [115] EnrichmentBrowser_2.39.0    KEGGREST_1.49.0

<>

References