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.
# 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]]
## R version 4.3.2 Patched (2023-11-13 r85521)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 22.04.3 LTS
##
## Matrix products: default
## BLAS: /home/biocbuild/bbs-3.18-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.32.5 BiocParallel_1.36.0 limma_3.58.1
## [4] ggplot2_3.4.4 knitr_1.45
##
## loaded via a namespace (and not attached):
## [1] gtable_0.3.4 xfun_0.42 bslib_0.6.1 caTools_1.18.2
## [5] Biobase_2.62.0 lattice_0.22-5 numDeriv_2016.8-1.1 vctrs_0.6.5
## [9] tools_4.3.2 Rdpack_2.6 bitops_1.0-7 generics_0.1.3
## [13] pbkrtest_0.5.2 parallel_4.3.2 tibble_3.2.1 fansi_1.0.6
## [17] highr_0.10 pkgconfig_2.0.3 Matrix_1.6-5 KernSmooth_2.23-22
## [21] lifecycle_1.0.4 stringr_1.5.1 compiler_4.3.2 gplots_3.1.3.1
## [25] statmod_1.5.0 munsell_0.5.0 RhpcBLASctl_0.23-42 codetools_0.2-19
## [29] lmerTest_3.1-3 htmltools_0.5.7 sass_0.4.8 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-60.0.1 aod_1.3.3 cachem_1.0.8 iterators_1.0.14
## [41] boot_1.3-28.1 nlme_3.1-164 gtools_3.9.5 tidyselect_1.2.0
## [45] digest_0.6.34 stringi_1.8.3 mvtnorm_1.2-4 fANCOVA_0.6-1
## [49] reshape2_1.4.4 purrr_1.0.2 dplyr_1.1.4 splines_4.3.2
## [53] fastmap_1.1.1 grid_4.3.2 colorspace_2.1-0 cli_3.6.2
## [57] magrittr_2.0.3 utf8_1.2.4 broom_1.0.5 corpcor_1.6.10
## [61] withr_3.0.0 backports_1.4.1 scales_1.3.0 remaCor_0.0.18
## [65] rmarkdown_2.25 matrixStats_1.2.0 lme4_1.1-35.1 evaluate_0.23
## [69] EnvStats_2.8.1 rbibutils_2.2.16 rlang_1.1.3 Rcpp_1.0.12
## [73] glue_1.7.0 BiocGenerics_0.48.1 minqa_1.2.6 jsonlite_1.8.8
## [77] plyr_1.8.9 R6_2.5.1