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 Under development (unstable) (2024-10-21 r87258)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.1 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.21-bioc/R/lib/libRblas.so 
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.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] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] variancePartition_1.37.1 BiocParallel_1.41.0      limma_3.63.2            
## [4] ggplot2_3.5.1            knitr_1.49              
## 
## loaded via a namespace (and not attached):
##  [1] gtable_0.3.6        xfun_0.49           bslib_0.8.0         caTools_1.18.3     
##  [5] Biobase_2.67.0      lattice_0.22-6      numDeriv_2016.8-1.1 vctrs_0.6.5        
##  [9] tools_4.5.0         Rdpack_2.6.1        bitops_1.0-9        generics_0.1.3     
## [13] pbkrtest_0.5.3      parallel_4.5.0      tibble_3.2.1        fansi_1.0.6        
## [17] pkgconfig_2.0.3     Matrix_1.7-1        KernSmooth_2.23-24  lifecycle_1.0.4    
## [21] stringr_1.5.1       compiler_4.5.0      gplots_3.2.0        statmod_1.5.0      
## [25] munsell_0.5.1       RhpcBLASctl_0.23-42 codetools_0.2-20    lmerTest_3.1-3     
## [29] htmltools_0.5.8.1   sass_0.4.9          yaml_2.3.10         tidyr_1.3.1        
## [33] pillar_1.9.0        nloptr_2.1.1        jquerylib_0.1.4     MASS_7.3-61        
## [37] aod_1.3.3           cachem_1.1.0        iterators_1.0.14    boot_1.3-31        
## [41] nlme_3.1-166        gtools_3.9.5        tidyselect_1.2.1    digest_0.6.37      
## [45] stringi_1.8.4       mvtnorm_1.3-2       fANCOVA_0.6-1       reshape2_1.4.4     
## [49] purrr_1.0.2         dplyr_1.1.4         splines_4.5.0       fastmap_1.2.0      
## [53] grid_4.5.0          colorspace_2.1-1    cli_3.6.3           magrittr_2.0.3     
## [57] utf8_1.2.4          broom_1.0.7         corpcor_1.6.10      withr_3.0.2        
## [61] backports_1.5.0     scales_1.3.0        remaCor_0.0.18      rmarkdown_2.29     
## [65] matrixStats_1.4.1   lme4_1.1-35.5       evaluate_1.0.1      EnvStats_3.0.0     
## [69] rbibutils_2.3       rlang_1.1.4         Rcpp_1.0.13-1       glue_1.8.0         
## [73] BiocGenerics_0.53.2 minqa_1.2.8         jsonlite_1.8.9      plyr_1.8.9         
## [77] R6_2.5.1