Standard RNA-seq processing

This tutorial assumes that the reader is familiar with the limma/voom workflow for RNA-seq. Process raw count data using limma/voom.

Limma Analysis

Limma has a built-in approach for analyzing repeated measures data using duplicateCorrelation(). The model can handle a single random effect, and forces the magnitude of the random effect to be the same across all genes.

Dream Analysis

The dream method replaces two core functions of limma with a linear mixed model.

  1. voomWithDreamWeights() replaces voom() to estimate precision weights
  2. dream() replaces lmFit() to estimate regression coefficients.

Otherwise dream uses the same workflow as limma with topTable(), since any statistical differences are handled behind the scenes.

##           (Intercept) Disease1
## sample_01           1        0
## sample_02           1        0
## sample_03           1        0
##                                   logFC  AveExpr        t      P.Value    adj.P.Val        B
## ENST00000283033.5 gene=TXNDC11 1.556233 3.567624 31.02068 3.099042e-21 3.099042e-18 38.15636
## ENST00000257181.9 gene=PRPF38A 1.380549 4.398270 21.59222 1.683871e-17 8.419354e-15 29.93271
## ENST00000525790.1 gene=TDRKH   1.508341 3.184931 19.51845 1.767605e-16 5.892017e-14 27.78202
##                                   z.std
## ENST00000283033.5 gene=TXNDC11 9.459336
## ENST00000257181.9 gene=PRPF38A 8.513757
## ENST00000525790.1 gene=TDRKH   8.236879

Since dream uses an estimated degrees of freedom value for each hypothsis test, the degrees of freedom is different for each gene here. Therefore, the t-statistics are not directly comparable since they have different degrees of freedom. In order to be able to compare test statistics, we report z.std which is the p-value transformed into a signed z-score. This can be used for downstream analysis.

Note that if a random effect is not specified, dream() automatically uses lmFit(), but the user must run eBayes() afterward.

Advanced hypothesis testing

Using contrasts to compare coefficients

You can also perform a hypothesis test of the difference between two or more coefficients by using a contrast matrix. The contrasts are evaluated at the time of the model fit and the results can be extracted with topTable(). This behaves like makeContrasts() and contrasts.fit() in limma.

Multiple contrasts can be evaluated at the same time, in order to save computation time. Make sure to inspect your contrast matrix to confirm it is testing what you intend.

## [1] "DiseaseSubtype2 - DiseaseSubtype1" "DiseaseSubtype1 - DiseaseSubtype0"
## [3] "DiseaseSubtype0"                   "DiseaseSubtype1"                  
## [5] "DiseaseSubtype2"                   "SexM"
##                                       logFC  AveExpr         t      P.Value  adj.P.Val          B
## ENST00000355624.3 gene=RAB11FIP2 -0.9493146 5.260280 -5.114589 3.698015e-05 0.03698015  0.1470281
## ENST00000593466.1 gene=DDA1      -1.7265709 3.901579 -3.700902 1.205688e-03 0.60284415 -1.2751588
## ENST00000200676.3 gene=CETP       1.4777422 3.723438  3.910146 3.397163e-03 0.99951347 -1.4383267
##                                      z.std
## ENST00000355624.3 gene=RAB11FIP2 -4.125580
## ENST00000593466.1 gene=DDA1      -3.237531
## ENST00000200676.3 gene=CETP       2.929309

Comparing multiple coefficients

So far contrasts have only involved the difference between two coefficients. But contrasts can also compare any linear combination of coefficients. Here, consider comparing DiseaseSubtype0 to the mean of DiseaseSubtype1 and DiseaseSubtype2. Note you can also customize the name of the contrast.

##                                    logFC  AveExpr         t      P.Value    adj.P.Val        B
## ENST00000456159.1 gene=MET    -0.9830788 2.458926 -6.975125 3.529900e-08 3.529900e-07 8.662257
## ENST00000570099.1 gene=YPEL3  -0.9512918 2.063331 -6.648837 6.060468e-07 2.172997e-06 7.230068
## ENST00000418210.2 gene=TMEM64 -1.0343236 4.715367 -6.655755 6.518991e-07 2.172997e-06 7.694537
##                                   z.std
## ENST00000456159.1 gene=MET    -5.512889
## ENST00000570099.1 gene=YPEL3  -4.989280
## ENST00000418210.2 gene=TMEM64 -4.975171

Joint hypothesis test of multiple coefficients

Joint hypothesis testing of multiple coefficients at the same time can be performed by using an F-test. Just like in limma, the results can be extracted using topTable()

##                                DiseaseSubtype2 DiseaseSubtype1  AveExpr        F      P.Value
## ENST00000418210.2 gene=TMEM64         5.301001        5.211674 4.715367 744.4317 5.216147e-23
## ENST00000555834.1 gene=RPS6KL1        5.662699        5.719196 5.272063 657.9520 2.377852e-22
## ENST00000589123.1 gene=NFIC           6.545195        6.181023 5.855335 519.2464 4.314164e-21
##                                   adj.P.Val    F.std
## ENST00000418210.2 gene=TMEM64  5.216147e-22 51.30770
## ENST00000555834.1 gene=RPS6KL1 1.188926e-21 49.79067
## ENST00000589123.1 gene=NFIC    1.438055e-20 46.89238

Since dream uses an estimated degrees of freedom value for each hypothsis test, the degrees of freedom is different for each gene here. Therefore, the F-statistics are not directly comparable since they have different degrees of freedom. In order to be able to compare test statistics, we report F.std which is the p-value transformed into an F-statistic with \(df_1\) the number of coefficients tested and \(df_2=\infty\). This can be used for downstream analysis.

Small-sample method

For small datasets, the Kenward-Roger method can be more powerful. But it is substantially more computationally intensive.

variancePartition plot

Dream and variancePartition share the same underlying linear mixed model framework. A variancePartition analysis can indicate important variables that should be included as fixed or random effects in the dream analysis.

Compare p-values from dream and duplicateCorrelation

In order to understand the empircal difference between dream and duplication correlation, we can plot the \(-\log_{10}\) p-values from both methods.

The duplicateCorrelation method estimates a single variance term genome-wide even though the donor contribution of a particular gene can vary substantially from the genome-wide trend. Using a single value genome-wide for the within-donor variance can reduce power and increase the false positive rate in a particular, reproducible way. Let \(\tau^2_g\) be the value of the donor component for gene \(g\) and \(\bar{\tau}^2\) be the genome-wide mean. For genes where \(\tau^2_g>\bar{\tau}^2\), using \(\bar{\tau}^2\) under-corrects for the donor component so that it increases the false positive rate compared to using \(\tau^2_g\). Conversely, for genes where \(\tau^2_g<\bar{\tau}^2\), using \(\bar{\tau}^2\) over-corrects for the donor component so that it decreases power. Increasing sample size does not overcome this issue. The dream method overcomes this issue by using a \(\tau^2_g\).

Here, the \(-\log_{10}\) p-values from both methods are plotted and colored by the donor contribution estiamted by variancePartition. The green value indicates \(\bar{\tau}^2\), while red and blue indicate higher and lower values, respectively. When only one variance component is used and the contrast matrix is simple, the effect of using dream versus duplicateCorrelation is determined by the comparison of \(\tau^2_g\) to \(\bar{\tau}^2\):

dream can increase the \(-\log_{10}\) p-value for genes with a lower donor component (i.e. \(\tau^2_g<\bar{\tau}^2\)) and decrease \(-\log_{10}\) p-value for genes with a higher donor component (i.e. \(\tau^2_g>\bar{\tau}^2\))

Note that using more variance components or a more complicated contrast matrix can make the relationship more complicated.

Parallel processing

variancePartition functions including dream(), fitExtractVarPartModel() and fitVarPartModel() can take advange of multicore machines to speed up analysis. It uses the BiocParallel package to manage the parallelization.

By default BPPARAM = SerialParam().

Session info

## R version 4.1.3 (2022-03-10)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.4 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.14-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.14-bioc/R/lib/libRlapack.so
## 
## 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       
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] edgeR_3.36.0             pander_0.6.5             variancePartition_1.24.1
## [4] BiocParallel_1.28.3      limma_3.50.3             ggplot2_3.3.5           
## [7] knitr_1.38              
## 
## loaded via a namespace (and not attached):
##  [1] Biobase_2.54.0         sass_0.4.1             tidyr_1.2.0            jsonlite_1.8.0        
##  [5] splines_4.1.3          foreach_1.5.2          RhpcBLASctl_0.21-247.1 gtools_3.9.2          
##  [9] bslib_0.3.1            Rdpack_2.3             assertthat_0.2.1       statmod_1.4.36        
## [13] highr_0.9              yaml_2.3.5             progress_1.2.2         numDeriv_2016.8-1.1   
## [17] pillar_1.7.0           backports_1.4.1        lattice_0.20-45        glue_1.6.2            
## [21] digest_0.6.29          rbibutils_2.2.8        minqa_1.2.4            colorspace_2.0-3      
## [25] htmltools_0.5.2        Matrix_1.4-1           plyr_1.8.7             pkgconfig_2.0.3       
## [29] broom_0.7.12           purrr_0.3.4            snow_0.4-4             scales_1.1.1          
## [33] lme4_1.1-29            tibble_3.1.6           farver_2.1.0           generics_0.1.2        
## [37] ellipsis_0.3.2         withr_2.5.0            BiocGenerics_0.40.0    pbkrtest_0.5.1        
## [41] cli_3.2.0              magrittr_2.0.3         crayon_1.5.1           evaluate_0.15         
## [45] fansi_1.0.3            doParallel_1.0.17      nlme_3.1-157           MASS_7.3-56           
## [49] gplots_3.1.1           tools_4.1.3            prettyunits_1.1.1      hms_1.1.1             
## [53] lifecycle_1.0.1        stringr_1.4.0          locfit_1.5-9.5         munsell_0.5.0         
## [57] aod_1.3.2              compiler_4.1.3         jquerylib_0.1.4        caTools_1.18.2        
## [61] rlang_1.0.2            grid_4.1.3             nloptr_2.0.0           iterators_1.0.14      
## [65] labeling_0.4.2         bitops_1.0-7           rmarkdown_2.13         boot_1.3-28           
## [69] lmerTest_3.1-3         gtable_0.3.0           codetools_0.2-18       DBI_1.1.2             
## [73] reshape2_1.4.4         R6_2.5.1               dplyr_1.0.8            fastmap_1.1.0         
## [77] utf8_1.2.2             KernSmooth_2.23-20     stringi_1.7.6          parallel_4.1.3        
## [81] Rcpp_1.0.8.3           vctrs_0.4.0            tidyselect_1.1.2       xfun_0.30

References

Law, C. W., Y. Chen, W. Shi, and G. K. Smyth. 2014. “Voom: precision weights unlock linear model analysis tools for RNA-seq read counts.” Genome Biology 15 (2): R29. https://doi.org/10.1186/gb-2014-15-2-r29.