The correlation structure between samples in complex study designs can be decomposed into the contribution of multiple dimensions of variation. variancePartition provides a statistical and visualization framework to interpret sources of variation. Here I describe a visualization of the correlation structure between samples for a single gene.

In the example dataset described in the main vignette, samples are correlated because they can come from the same individual or the same tissue. The function plotCorrStructure() shows the correlation structure caused by each variable as well and the joint correlation structure. Figure 1 shows the correlation between samples from the same individual where (a) shows the samples sorted based on clustering of the correlation matrix and (b) shows the original order. Figure 1 c) and d) shows the same type of plot except demonstrating the effect of tissue. The total correlation structure from summing individual and tissue correlation matricies is shown in Figure 2. The code to generate these plots is shown below.

Plot variance structure

# Fit linear mixed model and examine correlation stucture
# for one gene
data(varPartData)

form <- ~ Age + (1 | Individual) + (1 | Tissue)

fitList <- fitVarPartModel(geneExpr[1:2, ], form, info)

# focus on one gene
fit <- fitList[[1]]

By Individual

Reorder samples

# Figure 1a
# correlation structure based on similarity within Individual
# reorder samples based on clustering
plotCorrStructure(fit, "Individual")

Original order of samples

# Figure 1b
# use original order of samples
plotCorrStructure(fit, "Individual", reorder = FALSE)

By Tissue

Reorder samples

# Figure 1c
# correlation structure based on similarity within Tissue
# reorder samples based on clustering
plotCorrStructure(fit, "Tissue")

Original order of samples

# Figure 1d
# use original order of samples
plotCorrStructure(fit, "Tissue", reorder = FALSE)

By Individual and Tissue

Reorder samples

# Figure 2a
# correlation structure based on similarity within
# Individual *and* Tissue, reorder samples based on clustering
plotCorrStructure(fit)

Original order of samples

# Figure 2b
# use original order of samples
plotCorrStructure(fit, reorder = FALSE)

Session Info

## R version 4.4.0 RC (2024-04-16 r86468)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 22.04.4 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.20-bioc/R/lib/libRblas.so 
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.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] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] variancePartition_1.35.4 BiocParallel_1.39.0      limma_3.61.1            
## [4] ggplot2_3.5.1            knitr_1.47              
## 
## loaded via a namespace (and not attached):
##  [1] gtable_0.3.5        xfun_0.44           bslib_0.7.0         caTools_1.18.2     
##  [5] Biobase_2.65.0      lattice_0.22-6      numDeriv_2016.8-1.1 vctrs_0.6.5        
##  [9] tools_4.4.0         Rdpack_2.6          bitops_1.0-7        generics_0.1.3     
## [13] pbkrtest_0.5.2      parallel_4.4.0      tibble_3.2.1        fansi_1.0.6        
## [17] highr_0.11          pkgconfig_2.0.3     Matrix_1.7-0        KernSmooth_2.23-24 
## [21] lifecycle_1.0.4     stringr_1.5.1       compiler_4.4.0      gplots_3.1.3.1     
## [25] statmod_1.5.0       munsell_0.5.1       RhpcBLASctl_0.23-42 codetools_0.2-20   
## [29] lmerTest_3.1-3      htmltools_0.5.8.1   sass_0.4.9          yaml_2.3.8         
## [33] tidyr_1.3.1         pillar_1.9.0        nloptr_2.0.3        jquerylib_0.1.4    
## [37] MASS_7.3-61         aod_1.3.3           cachem_1.1.0        iterators_1.0.14   
## [41] boot_1.3-30         nlme_3.1-165        gtools_3.9.5        tidyselect_1.2.1   
## [45] digest_0.6.35       stringi_1.8.4       mvtnorm_1.2-5       fANCOVA_0.6-1      
## [49] reshape2_1.4.4      purrr_1.0.2         dplyr_1.1.4         splines_4.4.0      
## [53] fastmap_1.2.0       grid_4.4.0          colorspace_2.1-0    cli_3.6.2          
## [57] magrittr_2.0.3      utf8_1.2.4          broom_1.0.6         corpcor_1.6.10     
## [61] withr_3.0.0         backports_1.5.0     scales_1.3.0        remaCor_0.0.18     
## [65] rmarkdown_2.27      matrixStats_1.3.0   lme4_1.1-35.3       evaluate_0.24.0    
## [69] EnvStats_2.8.1      rbibutils_2.2.16    rlang_1.1.4         Rcpp_1.0.12        
## [73] glue_1.7.0          BiocGenerics_0.51.0 minqa_1.2.7         jsonlite_1.8.8     
## [77] plyr_1.8.9          R6_2.5.1