Additional visualizations of variance structure
Developed by Gabriel Hoffman
Run on 2024-06-12 13:01:01
Source:vignettes/additional_visualization.Rmd
additional_visualization.Rmd
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 (2024-04-24)
## Platform: aarch64-apple-darwin23.5.0
## Running under: macOS Sonoma 14.5
##
## Matrix products: default
## BLAS: /Users/gabrielhoffman/prog/R-4.4.0/lib/libRblas.dylib
## LAPACK: /Users/gabrielhoffman/prog/R-4.4.0/lib/libRlapack.dylib; LAPACK version 3.12.0
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## time zone: America/New_York
## tzcode source: internal
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] variancePartition_1.35.3 BiocParallel_1.38.0 limma_3.60.2
## [4] ggplot2_3.5.1 knitr_1.47
##
## loaded via a namespace (and not attached):
## [1] tidyselect_1.2.1 dplyr_1.1.4 bitops_1.0-7
## [4] fastmap_1.2.0 digest_0.6.35 lifecycle_1.0.4
## [7] statmod_1.5.0 magrittr_2.0.3 compiler_4.4.0
## [10] rlang_1.1.4 sass_0.4.9 tools_4.4.0
## [13] utf8_1.2.4 yaml_2.3.8 htmlwidgets_1.6.4
## [16] plyr_1.8.9 KernSmooth_2.23-24 withr_3.0.0
## [19] purrr_1.0.2 numDeriv_2016.8-1.1 BiocGenerics_0.50.0
## [22] desc_1.4.3 grid_4.4.0 aod_1.3.3
## [25] fansi_1.0.6 caTools_1.18.2 colorspace_2.1-0
## [28] scales_1.3.0 gtools_3.9.5 iterators_1.0.14
## [31] MASS_7.3-60.2 cli_3.6.2 mvtnorm_1.2-5
## [34] rmarkdown_2.27 ragg_1.3.2 generics_0.1.3
## [37] reshape2_1.4.4 minqa_1.2.7 cachem_1.1.0
## [40] stringr_1.5.1 splines_4.4.0 parallel_4.4.0
## [43] matrixStats_1.3.0 vctrs_0.6.5 boot_1.3-30
## [46] Matrix_1.7-0 jsonlite_1.8.8 pbkrtest_0.5.2
## [49] systemfonts_1.1.0 jquerylib_0.1.4 tidyr_1.3.1
## [52] glue_1.7.0 pkgdown_2.0.9 nloptr_2.0.3
## [55] codetools_0.2-20 stringi_1.8.4 gtable_0.3.5
## [58] EnvStats_2.8.1 lme4_1.1-35.3 lmerTest_3.1-3
## [61] munsell_0.5.1 tibble_3.2.1 remaCor_0.0.18
## [64] pillar_1.9.0 htmltools_0.5.8.1 gplots_3.1.3.1
## [67] R6_2.5.1 textshaping_0.4.0 Rdpack_2.6
## [70] evaluate_0.23 lattice_0.22-6 Biobase_2.64.0
## [73] highr_0.11 rbibutils_2.2.16 backports_1.5.0
## [76] RhpcBLASctl_0.23-42 memoise_2.0.1 broom_1.0.6
## [79] fANCOVA_0.6-1 corpcor_1.6.10 bslib_0.7.0
## [82] Rcpp_1.0.12 nlme_3.1-165 xfun_0.44
## [85] fs_1.6.4 pkgconfig_2.0.3