From 62a23d7e56c6e7516bb4da3ff137443014c8fdd8 Mon Sep 17 00:00:00 2001 From: kwells4 <kristen.wells@cuanschutz.edu> Date: Thu, 7 Dec 2023 09:39:02 -0700 Subject: [PATCH] renaming --- .gitignore | 2 + .../class7_matricies.html | 2406 ----------------- .../class-8-clustering.html | 2221 --------------- .../class-9-heatmap.html | 2204 --------------- .../class8_matricies.Rmd} | 25 +- .../anchor-4.2.2/anchor.min.js | 0 .../bowser-1.9.3/bowser.min.js | 0 .../distill-2.2.21/template.v2.js | 0 .../figure-html5/unnamed-chunk-63-1.png | Bin .../header-attrs-2.14/header-attrs.js | 0 .../jquery-3.6.0/jquery-3.6.0.js | 0 .../jquery-3.6.0/jquery-3.6.0.min.js | 0 .../jquery-3.6.0/jquery-3.6.0.min.map | 0 .../popper-2.6.0/popper.min.js | 0 .../tippy-6.2.7/tippy-bundle.umd.min.js | 0 .../tippy-6.2.7/tippy-light-border.css | 0 .../tippy-6.2.7/tippy.css | 0 .../tippy-6.2.7/tippy.umd.min.js | 0 .../webcomponents-2.0.0/webcomponents.js | 0 .../download_files.R | 2 +- .../img/matrix_image.jpg | Bin .../class-9-clustering.Rmd} | 48 +- .../anchor-4.2.2/anchor.min.js | 0 .../bowser-1.9.3/bowser.min.js | 0 .../distill-2.2.21/template.v2.js | 0 .../figure-html5/unnamed-chunk-11-1.png | Bin .../figure-html5/unnamed-chunk-12-1.png | Bin .../figure-html5/unnamed-chunk-14-1.png | Bin .../figure-html5/unnamed-chunk-15-1.png | Bin .../figure-html5/unnamed-chunk-16-1.png | Bin .../figure-html5/unnamed-chunk-17-1.png | Bin .../figure-html5/unnamed-chunk-18-1.png | Bin .../figure-html5/unnamed-chunk-19-1.png | Bin .../figure-html5/unnamed-chunk-20-1.png | Bin .../figure-html5/unnamed-chunk-22-1.png | Bin .../figure-html5/unnamed-chunk-23-1.png | Bin .../figure-html5/unnamed-chunk-24-1.png | Bin .../figure-html5/unnamed-chunk-26-1.png | Bin .../figure-html5/unnamed-chunk-28-1.png | Bin .../figure-html5/unnamed-chunk-30-1.png | Bin .../figure-html5/unnamed-chunk-32-1.png | Bin .../figure-html5/unnamed-chunk-33-1.png | Bin .../figure-html5/unnamed-chunk-35-1.png | Bin .../figure-html5/unnamed-chunk-36-1.png | Bin .../figure-html5/unnamed-chunk-37-1.png | Bin .../figure-html5/unnamed-chunk-38-1.png | Bin .../figure-html5/unnamed-chunk-39-1.png | Bin .../figure-html5/unnamed-chunk-40-1.png | Bin .../figure-html5/unnamed-chunk-41-1.png | Bin .../figure-html5/unnamed-chunk-42-1.png | Bin .../figure-html5/unnamed-chunk-43-1.png | Bin .../figure-html5/unnamed-chunk-44-1.png | Bin .../figure-html5/unnamed-chunk-45-1.png | Bin .../figure-html5/unnamed-chunk-46-1.png | Bin .../figure-html5/unnamed-chunk-47-1.png | Bin .../figure-html5/unnamed-chunk-48-1.png | Bin .../figure-html5/unnamed-chunk-49-1.png | Bin .../figure-html5/unnamed-chunk-50-1.png | Bin .../figure-html5/unnamed-chunk-51-1.png | Bin .../figure-html5/unnamed-chunk-6-1.png | Bin .../header-attrs-2.14/header-attrs.js | 0 .../jquery-3.6.0/jquery-3.6.0.js | 0 .../jquery-3.6.0/jquery-3.6.0.min.js | 0 .../jquery-3.6.0/jquery-3.6.0.min.map | 0 .../popper-2.6.0/popper.min.js | 0 .../tippy-6.2.7/tippy-bundle.umd.min.js | 0 .../tippy-6.2.7/tippy-light-border.css | 0 .../tippy-6.2.7/tippy.css | 0 .../tippy-6.2.7/tippy.umd.min.js | 0 .../webcomponents-2.0.0/webcomponents.js | 0 .../img/Hierarchical-clustering-3-1.jpg | Bin .../img/clustering1.jpg | Bin .../img/dendrogram.jpg | Bin .../img/final_clustering.jpg | Bin .../img/unclustered.jpg | Bin .../class-10-heatmap.Rmd} | 10 +- .../anchor-4.2.2/anchor.min.js | 0 .../bowser-1.9.3/bowser.min.js | 0 .../distill-2.2.21/template.v2.js | 0 .../figure-html5/unnamed-chunk-10-1.png | Bin .../figure-html5/unnamed-chunk-13-1.png | Bin .../figure-html5/unnamed-chunk-14-1.png | Bin .../figure-html5/unnamed-chunk-15-1.png | Bin .../figure-html5/unnamed-chunk-18-1.png | Bin .../figure-html5/unnamed-chunk-20-1.png | Bin .../figure-html5/unnamed-chunk-22-1.png | Bin .../figure-html5/unnamed-chunk-26-1.png | Bin .../figure-html5/unnamed-chunk-27-1.png | Bin .../figure-html5/unnamed-chunk-29-1.png | Bin .../figure-html5/unnamed-chunk-31-1.png | Bin .../figure-html5/unnamed-chunk-33-1.png | Bin .../figure-html5/unnamed-chunk-34-1.png | Bin .../figure-html5/unnamed-chunk-35-1.png | Bin .../figure-html5/unnamed-chunk-38-1.png | Bin .../figure-html5/unnamed-chunk-39-1.png | Bin .../figure-html5/unnamed-chunk-4-1.png | Bin .../figure-html5/unnamed-chunk-42-1.png | Bin .../figure-html5/unnamed-chunk-43-1.png | Bin .../figure-html5/unnamed-chunk-44-1.png | Bin .../figure-html5/unnamed-chunk-47-1.png | Bin .../figure-html5/unnamed-chunk-5-1.png | Bin .../figure-html5/unnamed-chunk-7-1.png | Bin .../header-attrs-2.14/header-attrs.js | 0 .../jquery-3.6.0/jquery-3.6.0.js | 0 .../jquery-3.6.0/jquery-3.6.0.min.js | 0 .../jquery-3.6.0/jquery-3.6.0.min.map | 0 .../popper-2.6.0/popper.min.js | 0 .../tippy-6.2.7/tippy-bundle.umd.min.js | 0 .../tippy-6.2.7/tippy-light-border.css | 0 .../tippy-6.2.7/tippy.css | 0 .../tippy-6.2.7/tippy.umd.min.js | 0 .../webcomponents-2.0.0/webcomponents.js | 0 112 files changed, 24 insertions(+), 6894 deletions(-) delete mode 100644 _posts/2022-11-10-class-7-matricies/class7_matricies.html delete mode 100644 _posts/2022-11-15-class-8-clustering/class-8-clustering.html delete mode 100644 _posts/2022-11-16-class-9-heatmap/class-9-heatmap.html rename _posts/{2022-11-10-class-7-matricies/class7_matricies.Rmd => 2023-12-08-class-8-matricies/class8_matricies.Rmd} (94%) rename _posts/{2022-11-10-class-7-matricies/class7_matricies_files => 2023-12-08-class-8-matricies/class8_matricies_files}/anchor-4.2.2/anchor.min.js (100%) rename _posts/{2022-11-10-class-7-matricies/class7_matricies_files => 2023-12-08-class-8-matricies/class8_matricies_files}/bowser-1.9.3/bowser.min.js (100%) rename _posts/{2022-11-10-class-7-matricies/class7_matricies_files => 2023-12-08-class-8-matricies/class8_matricies_files}/distill-2.2.21/template.v2.js (100%) rename _posts/{2022-11-10-class-7-matricies/class7_matricies_files => 2023-12-08-class-8-matricies/class8_matricies_files}/figure-html5/unnamed-chunk-63-1.png (100%) rename _posts/{2022-11-10-class-7-matricies/class7_matricies_files => 2023-12-08-class-8-matricies/class8_matricies_files}/header-attrs-2.14/header-attrs.js (100%) rename _posts/{2022-11-10-class-7-matricies/class7_matricies_files => 2023-12-08-class-8-matricies/class8_matricies_files}/jquery-3.6.0/jquery-3.6.0.js (100%) rename _posts/{2022-11-10-class-7-matricies/class7_matricies_files => 2023-12-08-class-8-matricies/class8_matricies_files}/jquery-3.6.0/jquery-3.6.0.min.js (100%) rename _posts/{2022-11-10-class-7-matricies/class7_matricies_files => 2023-12-08-class-8-matricies/class8_matricies_files}/jquery-3.6.0/jquery-3.6.0.min.map (100%) rename _posts/{2022-11-10-class-7-matricies/class7_matricies_files => 2023-12-08-class-8-matricies/class8_matricies_files}/popper-2.6.0/popper.min.js (100%) rename _posts/{2022-11-10-class-7-matricies/class7_matricies_files => 2023-12-08-class-8-matricies/class8_matricies_files}/tippy-6.2.7/tippy-bundle.umd.min.js (100%) rename _posts/{2022-11-10-class-7-matricies/class7_matricies_files => 2023-12-08-class-8-matricies/class8_matricies_files}/tippy-6.2.7/tippy-light-border.css (100%) rename _posts/{2022-11-10-class-7-matricies/class7_matricies_files => 2023-12-08-class-8-matricies/class8_matricies_files}/tippy-6.2.7/tippy.css (100%) rename _posts/{2022-11-10-class-7-matricies/class7_matricies_files => 2023-12-08-class-8-matricies/class8_matricies_files}/tippy-6.2.7/tippy.umd.min.js (100%) rename _posts/{2022-11-10-class-7-matricies/class7_matricies_files => 2023-12-08-class-8-matricies/class8_matricies_files}/webcomponents-2.0.0/webcomponents.js (100%) rename _posts/{2022-11-10-class-7-matricies => 2023-12-08-class-8-matricies}/download_files.R (94%) rename _posts/{2022-11-10-class-7-matricies => 2023-12-08-class-8-matricies}/img/matrix_image.jpg (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering.Rmd => 2023-12-11-class-9-clustering/class-9-clustering.Rmd} (94%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/anchor-4.2.2/anchor.min.js (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/bowser-1.9.3/bowser.min.js (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/distill-2.2.21/template.v2.js (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-11-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-12-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-14-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-15-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-16-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-17-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-18-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-19-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-20-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-22-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-23-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-24-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-26-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-28-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-30-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-32-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-33-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-35-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-36-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-37-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-38-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-39-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-40-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-41-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-42-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-43-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-44-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-45-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-46-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-47-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-48-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-49-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-50-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-51-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/figure-html5/unnamed-chunk-6-1.png (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/header-attrs-2.14/header-attrs.js (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/jquery-3.6.0/jquery-3.6.0.js (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/jquery-3.6.0/jquery-3.6.0.min.js (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/jquery-3.6.0/jquery-3.6.0.min.map (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/popper-2.6.0/popper.min.js (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/tippy-6.2.7/tippy-bundle.umd.min.js (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/tippy-6.2.7/tippy-light-border.css (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/tippy-6.2.7/tippy.css (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/tippy-6.2.7/tippy.umd.min.js (100%) rename _posts/{2022-11-15-class-8-clustering/class-8-clustering_files => 2023-12-11-class-9-clustering/class-9-clustering_files}/webcomponents-2.0.0/webcomponents.js (100%) rename _posts/{2022-11-15-class-8-clustering => 2023-12-11-class-9-clustering}/img/Hierarchical-clustering-3-1.jpg (100%) rename _posts/{2022-11-15-class-8-clustering => 2023-12-11-class-9-clustering}/img/clustering1.jpg (100%) rename _posts/{2022-11-15-class-8-clustering => 2023-12-11-class-9-clustering}/img/dendrogram.jpg (100%) rename _posts/{2022-11-15-class-8-clustering => 2023-12-11-class-9-clustering}/img/final_clustering.jpg (100%) rename _posts/{2022-11-15-class-8-clustering => 2023-12-11-class-9-clustering}/img/unclustered.jpg (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap.Rmd => 2023-12-12-class-10-heatmap/class-10-heatmap.Rmd} (98%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/anchor-4.2.2/anchor.min.js (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/bowser-1.9.3/bowser.min.js (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/distill-2.2.21/template.v2.js (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/figure-html5/unnamed-chunk-10-1.png (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/figure-html5/unnamed-chunk-13-1.png (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/figure-html5/unnamed-chunk-14-1.png (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/figure-html5/unnamed-chunk-15-1.png (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/figure-html5/unnamed-chunk-18-1.png (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/figure-html5/unnamed-chunk-20-1.png (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/figure-html5/unnamed-chunk-22-1.png (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/figure-html5/unnamed-chunk-26-1.png (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/figure-html5/unnamed-chunk-27-1.png (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/figure-html5/unnamed-chunk-29-1.png (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/figure-html5/unnamed-chunk-31-1.png (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/figure-html5/unnamed-chunk-33-1.png (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/figure-html5/unnamed-chunk-34-1.png (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/figure-html5/unnamed-chunk-35-1.png (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/figure-html5/unnamed-chunk-38-1.png (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/figure-html5/unnamed-chunk-39-1.png (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/figure-html5/unnamed-chunk-4-1.png (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/figure-html5/unnamed-chunk-42-1.png (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/figure-html5/unnamed-chunk-43-1.png (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/figure-html5/unnamed-chunk-44-1.png (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/figure-html5/unnamed-chunk-47-1.png (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/figure-html5/unnamed-chunk-5-1.png (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/figure-html5/unnamed-chunk-7-1.png (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/header-attrs-2.14/header-attrs.js (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/jquery-3.6.0/jquery-3.6.0.js (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/jquery-3.6.0/jquery-3.6.0.min.js (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/jquery-3.6.0/jquery-3.6.0.min.map (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/popper-2.6.0/popper.min.js (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/tippy-6.2.7/tippy-bundle.umd.min.js (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/tippy-6.2.7/tippy-light-border.css (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/tippy-6.2.7/tippy.css (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/tippy-6.2.7/tippy.umd.min.js (100%) rename _posts/{2022-11-16-class-9-heatmap/class-9-heatmap_files => 2023-12-12-class-10-heatmap/class-10-heatmap_files}/webcomponents-2.0.0/webcomponents.js (100%) diff --git a/.gitignore b/.gitignore index c15031e..cb775e9 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ docs .Rhistory ex/problem-set-3/matrices_clustering_heatmaps_key.* ps +renv* +.Rprofile diff --git a/_posts/2022-11-10-class-7-matricies/class7_matricies.html b/_posts/2022-11-10-class-7-matricies/class7_matricies.html deleted file mode 100644 index 23de5c9..0000000 --- a/_posts/2022-11-10-class-7-matricies/class7_matricies.html +++ /dev/null @@ -1,2406 +0,0 @@ -<!DOCTYPE html> - -<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang=""> - -<head> - <meta charset="utf-8"/> - <meta name="viewport" content="width=device-width, initial-scale=1"/> - <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"/> - <meta name="generator" content="distill" /> - - <style type="text/css"> - /* Hide doc at startup (prevent jankiness while JS renders/transforms) */ - body { - visibility: hidden; - } - </style> - - <!--radix_placeholder_import_source--> - <!--/radix_placeholder_import_source--> - -<style type="text/css">code{white-space: pre;}</style> -<style type="text/css" data-origin="pandoc"> -pre > code.sourceCode { white-space: pre; position: relative; } -pre > code.sourceCode > span { display: inline-block; line-height: 1.25; } -pre > code.sourceCode > span:empty { height: 1.2em; } -.sourceCode { overflow: visible; } -code.sourceCode > span { color: inherit; text-decoration: inherit; } -div.sourceCode { margin: 1em 0; } -pre.sourceCode { margin: 0; } -@media screen { -div.sourceCode { overflow: auto; } -} -@media print { -pre > code.sourceCode { white-space: pre-wrap; } -pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; } -} -pre.numberSource code - { counter-reset: source-line 0; } -pre.numberSource code > span - { position: relative; left: -4em; counter-increment: source-line; } -pre.numberSource code > span > a:first-child::before - { content: counter(source-line); - position: relative; left: -1em; text-align: right; vertical-align: baseline; - border: none; display: inline-block; - -webkit-touch-callout: none; -webkit-user-select: none; - -khtml-user-select: none; -moz-user-select: none; - -ms-user-select: none; user-select: none; - padding: 0 4px; width: 4em; - color: #aaaaaa; - } -pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; } -div.sourceCode - { color: #00769e; background-color: #f1f3f5; } -@media screen { -pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; } -} -code span { color: #00769e; } /* Normal */ -code span.al { color: #ad0000; } /* Alert */ -code span.an { color: #5e5e5e; } /* Annotation */ -code span.at { color: #657422; } /* Attribute */ -code span.bn { color: #ad0000; } /* BaseN */ -code span.bu { } /* BuiltIn */ -code span.cf { color: #00769e; } /* ControlFlow */ -code span.ch { color: #20794d; } /* Char */ -code span.cn { color: #8f5902; } /* Constant */ -code span.co { color: #5e5e5e; } /* Comment */ -code span.cv { color: #5e5e5e; font-style: italic; } /* CommentVar */ -code span.do { color: #5e5e5e; font-style: italic; } /* Documentation */ -code span.dt { color: #ad0000; } /* DataType */ -code span.dv { color: #ad0000; } /* DecVal */ -code span.er { color: #ad0000; } /* Error */ -code span.ex { } /* Extension */ -code span.fl { color: #ad0000; } /* Float */ -code span.fu { color: #4758ab; } /* Function */ -code span.im { } /* Import */ -code span.in { color: #5e5e5e; } /* Information */ -code span.kw { color: #00769e; } /* Keyword */ -code span.op { color: #5e5e5e; } /* Operator */ -code span.ot { color: #00769e; } /* Other */ -code span.pp { color: #ad0000; } /* Preprocessor */ -code span.sc { color: #5e5e5e; } /* SpecialChar */ -code span.ss { color: #20794d; } /* SpecialString */ -code span.st { color: #20794d; } /* String */ -code span.va { color: #111111; } /* Variable */ -code span.vs { color: #20794d; } /* VerbatimString */ -code span.wa { color: #5e5e5e; font-style: italic; } /* Warning */ -</style> - - - <!--radix_placeholder_meta_tags--> - <title>Class 7: Introduction to matricies</title> - - - - <!-- https://schema.org/Article --> - <meta property="article:published" itemprop="datePublished" content="2022-12-07"/> - <meta property="article:created" itemprop="dateCreated" content="2022-12-07"/> - <meta name="article:author" content="Kristen Wells"/> - - <!-- https://developers.facebook.com/docs/sharing/webmasters#markup --> - <meta property="og:title" content="Class 7: Introduction to matricies"/> - <meta property="og:type" content="article"/> - <meta property="og:locale" content="en_US"/> - - <!-- https://dev.twitter.com/cards/types/summary --> - <meta property="twitter:card" content="summary"/> - <meta property="twitter:title" content="Class 7: Introduction to matricies"/> - - <!--/radix_placeholder_meta_tags--> - <!--radix_placeholder_rmarkdown_metadata--> - - <script type="text/json" id="radix-rmarkdown-metadata"> - {"type":"list","attributes":{"names":{"type":"character","attributes":{},"value":["title","author","output","draft","preview","date"]}},"value":[{"type":"character","attributes":{},"value":["Class 7: Introduction to matricies"]},{"type":"list","attributes":{},"value":[{"type":"list","attributes":{"names":{"type":"character","attributes":{},"value":["name","url","affiliation","orcid_id"]}},"value":[{"type":"character","attributes":{},"value":["Kristen Wells"]},{"type":"character","attributes":{},"value":["https://github.com/kwells4"]},{"type":"character","attributes":{},"value":["RNA Bioscience Iniative, Barbara Davis Diabetes Center"]},{"type":"character","attributes":{},"value":["0000-0002-7466-8164"]}]}]},{"type":"list","attributes":{"names":{"type":"character","attributes":{},"value":["distill::distill_article"]}},"value":[{"type":"list","attributes":{"names":{"type":"character","attributes":{},"value":["self_contained","toc"]}},"value":[{"type":"logical","attributes":{},"value":[false]},{"type":"logical","attributes":{},"value":[true]}]}]},{"type":"logical","attributes":{},"value":[false]},{"type":"character","attributes":{},"value":["img/matrix_image.jpg"]},{"type":"character","attributes":{},"value":["12-07-2022"]}]} - </script> - <!--/radix_placeholder_rmarkdown_metadata--> - - <script type="text/json" id="radix-resource-manifest"> - {"type":"character","attributes":{},"value":["class7_matricies_files/anchor-4.2.2/anchor.min.js","class7_matricies_files/bowser-1.9.3/bowser.min.js","class7_matricies_files/distill-2.2.21/template.v2.js","class7_matricies_files/figure-html5/unnamed-chunk-63-1.png","class7_matricies_files/header-attrs-2.14/header-attrs.js","class7_matricies_files/jquery-3.6.0/jquery-3.6.0.js","class7_matricies_files/jquery-3.6.0/jquery-3.6.0.min.js","class7_matricies_files/jquery-3.6.0/jquery-3.6.0.min.map","class7_matricies_files/popper-2.6.0/popper.min.js","class7_matricies_files/tippy-6.2.7/tippy-bundle.umd.min.js","class7_matricies_files/tippy-6.2.7/tippy-light-border.css","class7_matricies_files/tippy-6.2.7/tippy.css","class7_matricies_files/tippy-6.2.7/tippy.umd.min.js","class7_matricies_files/webcomponents-2.0.0/webcomponents.js","img/matrix_image.jpg"]} - </script> - <!--radix_placeholder_navigation_in_header--> - <!--/radix_placeholder_navigation_in_header--> - <!--radix_placeholder_distill--> - - <style type="text/css"> - - body { - background-color: white; - } - - .pandoc-table { - width: 100%; - } - - .pandoc-table>caption { - margin-bottom: 10px; - } - - .pandoc-table th:not([align]) { - text-align: left; - } - - .pagedtable-footer { - font-size: 15px; - } - - d-byline .byline { - grid-template-columns: 2fr 2fr; - } - - d-byline .byline h3 { - margin-block-start: 1.5em; - } - - d-byline .byline .authors-affiliations h3 { - margin-block-start: 0.5em; - } - - .authors-affiliations .orcid-id { - width: 16px; - height:16px; - margin-left: 4px; - margin-right: 4px; - vertical-align: middle; - padding-bottom: 2px; - } - - d-title .dt-tags { - margin-top: 1em; - grid-column: text; - } - - .dt-tags .dt-tag { - text-decoration: none; - display: inline-block; - color: rgba(0,0,0,0.6); - padding: 0em 0.4em; - margin-right: 0.5em; - margin-bottom: 0.4em; - font-size: 70%; - border: 1px solid rgba(0,0,0,0.2); - border-radius: 3px; - text-transform: uppercase; - font-weight: 500; - } - - d-article table.gt_table td, - d-article table.gt_table th { - border-bottom: none; - font-size: 100%; - } - - .html-widget { - margin-bottom: 2.0em; - } - - .l-screen-inset { - padding-right: 16px; - } - - .l-screen .caption { - margin-left: 10px; - } - - .shaded { - background: rgb(247, 247, 247); - padding-top: 20px; - padding-bottom: 20px; - border-top: 1px solid rgba(0, 0, 0, 0.1); - border-bottom: 1px solid rgba(0, 0, 0, 0.1); - } - - .shaded .html-widget { - margin-bottom: 0; - border: 1px solid rgba(0, 0, 0, 0.1); - } - - .shaded .shaded-content { - background: white; - } - - .text-output { - margin-top: 0; - line-height: 1.5em; - } - - .hidden { - display: none !important; - } - - d-article { - padding-top: 2.5rem; - padding-bottom: 30px; - } - - d-appendix { - padding-top: 30px; - } - - d-article>p>img { - width: 100%; - } - - d-article h2 { - margin: 1rem 0 1.5rem 0; - } - - d-article h3 { - margin-top: 1.5rem; - } - - d-article iframe { - border: 1px solid rgba(0, 0, 0, 0.1); - margin-bottom: 2.0em; - width: 100%; - } - - /* Tweak code blocks */ - - d-article div.sourceCode code, - d-article pre code { - font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; - } - - d-article pre, - d-article div.sourceCode, - d-article div.sourceCode pre { - overflow: auto; - } - - d-article div.sourceCode { - background-color: white; - } - - d-article div.sourceCode pre { - padding-left: 10px; - font-size: 12px; - border-left: 2px solid rgba(0,0,0,0.1); - } - - d-article pre { - font-size: 12px; - color: black; - background: none; - margin-top: 0; - text-align: left; - white-space: pre; - word-spacing: normal; - word-break: normal; - word-wrap: normal; - line-height: 1.5; - - -moz-tab-size: 4; - -o-tab-size: 4; - tab-size: 4; - - -webkit-hyphens: none; - -moz-hyphens: none; - -ms-hyphens: none; - hyphens: none; - } - - d-article pre a { - border-bottom: none; - } - - d-article pre a:hover { - border-bottom: none; - text-decoration: underline; - } - - d-article details { - grid-column: text; - margin-bottom: 0.8em; - } - - @media(min-width: 768px) { - - d-article pre, - d-article div.sourceCode, - d-article div.sourceCode pre { - overflow: visible !important; - } - - d-article div.sourceCode pre { - padding-left: 18px; - font-size: 14px; - } - - d-article pre { - font-size: 14px; - } - - } - - figure img.external { - background: white; - border: 1px solid rgba(0, 0, 0, 0.1); - box-shadow: 0 1px 8px rgba(0, 0, 0, 0.1); - padding: 18px; - box-sizing: border-box; - } - - /* CSS for d-contents */ - - .d-contents { - grid-column: text; - color: rgba(0,0,0,0.8); - font-size: 0.9em; - padding-bottom: 1em; - margin-bottom: 1em; - padding-bottom: 0.5em; - margin-bottom: 1em; - padding-left: 0.25em; - justify-self: start; - } - - @media(min-width: 1000px) { - .d-contents.d-contents-float { - height: 0; - grid-column-start: 1; - grid-column-end: 4; - justify-self: center; - padding-right: 3em; - padding-left: 2em; - } - } - - .d-contents nav h3 { - font-size: 18px; - margin-top: 0; - margin-bottom: 1em; - } - - .d-contents li { - list-style-type: none - } - - .d-contents nav > ul { - padding-left: 0; - } - - .d-contents ul { - padding-left: 1em - } - - .d-contents nav ul li { - margin-top: 0.6em; - margin-bottom: 0.2em; - } - - .d-contents nav a { - font-size: 13px; - border-bottom: none; - text-decoration: none - color: rgba(0, 0, 0, 0.8); - } - - .d-contents nav a:hover { - text-decoration: underline solid rgba(0, 0, 0, 0.6) - } - - .d-contents nav > ul > li > a { - font-weight: 600; - } - - .d-contents nav > ul > li > ul { - font-weight: inherit; - } - - .d-contents nav > ul > li > ul > li { - margin-top: 0.2em; - } - - - .d-contents nav ul { - margin-top: 0; - margin-bottom: 0.25em; - } - - .d-article-with-toc h2:nth-child(2) { - margin-top: 0; - } - - - /* Figure */ - - .figure { - position: relative; - margin-bottom: 2.5em; - margin-top: 1.5em; - } - - .figure .caption { - color: rgba(0, 0, 0, 0.6); - font-size: 12px; - line-height: 1.5em; - } - - .figure img.external { - background: white; - border: 1px solid rgba(0, 0, 0, 0.1); - box-shadow: 0 1px 8px rgba(0, 0, 0, 0.1); - padding: 18px; - box-sizing: border-box; - } - - .figure .caption a { - color: rgba(0, 0, 0, 0.6); - } - - .figure .caption b, - .figure .caption strong, { - font-weight: 600; - color: rgba(0, 0, 0, 1.0); - } - - /* Citations */ - - d-article .citation { - color: inherit; - cursor: inherit; - } - - div.hanging-indent{ - margin-left: 1em; text-indent: -1em; - } - - /* Citation hover box */ - - .tippy-box[data-theme~=light-border] { - background-color: rgba(250, 250, 250, 0.95); - } - - .tippy-content > p { - margin-bottom: 0; - padding: 2px; - } - - - /* Tweak 1000px media break to show more text */ - - @media(min-width: 1000px) { - .base-grid, - distill-header, - d-title, - d-abstract, - d-article, - d-appendix, - distill-appendix, - d-byline, - d-footnote-list, - d-citation-list, - distill-footer { - grid-template-columns: [screen-start] 1fr [page-start kicker-start] 80px [middle-start] 50px [text-start kicker-end] 65px 65px 65px 65px 65px 65px 65px 65px [text-end gutter-start] 65px [middle-end] 65px [page-end gutter-end] 1fr [screen-end]; - grid-column-gap: 16px; - } - - .grid { - grid-column-gap: 16px; - } - - d-article { - font-size: 1.06rem; - line-height: 1.7em; - } - figure .caption, .figure .caption, figure figcaption { - font-size: 13px; - } - } - - @media(min-width: 1180px) { - .base-grid, - distill-header, - d-title, - d-abstract, - d-article, - d-appendix, - distill-appendix, - d-byline, - d-footnote-list, - d-citation-list, - distill-footer { - grid-template-columns: [screen-start] 1fr [page-start kicker-start] 60px [middle-start] 60px [text-start kicker-end] 60px 60px 60px 60px 60px 60px 60px 60px [text-end gutter-start] 60px [middle-end] 60px [page-end gutter-end] 1fr [screen-end]; - grid-column-gap: 32px; - } - - .grid { - grid-column-gap: 32px; - } - } - - - /* Get the citation styles for the appendix (not auto-injected on render since - we do our own rendering of the citation appendix) */ - - d-appendix .citation-appendix, - .d-appendix .citation-appendix { - font-size: 11px; - line-height: 15px; - border-left: 1px solid rgba(0, 0, 0, 0.1); - padding-left: 18px; - border: 1px solid rgba(0,0,0,0.1); - background: rgba(0, 0, 0, 0.02); - padding: 10px 18px; - border-radius: 3px; - color: rgba(150, 150, 150, 1); - overflow: hidden; - margin-top: -12px; - white-space: pre-wrap; - word-wrap: break-word; - } - - /* Include appendix styles here so they can be overridden */ - - d-appendix { - contain: layout style; - font-size: 0.8em; - line-height: 1.7em; - margin-top: 60px; - margin-bottom: 0; - border-top: 1px solid rgba(0, 0, 0, 0.1); - color: rgba(0,0,0,0.5); - padding-top: 60px; - padding-bottom: 48px; - } - - d-appendix h3 { - grid-column: page-start / text-start; - font-size: 15px; - font-weight: 500; - margin-top: 1em; - margin-bottom: 0; - color: rgba(0,0,0,0.65); - } - - d-appendix h3 + * { - margin-top: 1em; - } - - d-appendix ol { - padding: 0 0 0 15px; - } - - @media (min-width: 768px) { - d-appendix ol { - padding: 0 0 0 30px; - margin-left: -30px; - } - } - - d-appendix li { - margin-bottom: 1em; - } - - d-appendix a { - color: rgba(0, 0, 0, 0.6); - } - - d-appendix > * { - grid-column: text; - } - - d-appendix > d-footnote-list, - d-appendix > d-citation-list, - d-appendix > distill-appendix { - grid-column: screen; - } - - /* Include footnote styles here so they can be overridden */ - - d-footnote-list { - contain: layout style; - } - - d-footnote-list > * { - grid-column: text; - } - - d-footnote-list a.footnote-backlink { - color: rgba(0,0,0,0.3); - padding-left: 0.5em; - } - - - - /* Anchor.js */ - - .anchorjs-link { - /*transition: all .25s linear; */ - text-decoration: none; - border-bottom: none; - } - *:hover > .anchorjs-link { - margin-left: -1.125em !important; - text-decoration: none; - border-bottom: none; - } - - /* Social footer */ - - .social_footer { - margin-top: 30px; - margin-bottom: 0; - color: rgba(0,0,0,0.67); - } - - .disqus-comments { - margin-right: 30px; - } - - .disqus-comment-count { - border-bottom: 1px solid rgba(0, 0, 0, 0.4); - cursor: pointer; - } - - #disqus_thread { - margin-top: 30px; - } - - .article-sharing a { - border-bottom: none; - margin-right: 8px; - } - - .article-sharing a:hover { - border-bottom: none; - } - - .sidebar-section.subscribe { - font-size: 12px; - line-height: 1.6em; - } - - .subscribe p { - margin-bottom: 0.5em; - } - - - .article-footer .subscribe { - font-size: 15px; - margin-top: 45px; - } - - - .sidebar-section.custom { - font-size: 12px; - line-height: 1.6em; - } - - .custom p { - margin-bottom: 0.5em; - } - - /* Styles for listing layout (hide title) */ - .layout-listing d-title, .layout-listing .d-title { - display: none; - } - - /* Styles for posts lists (not auto-injected) */ - - - .posts-with-sidebar { - padding-left: 45px; - padding-right: 45px; - } - - .posts-list .description h2, - .posts-list .description p { - font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial, sans-serif; - } - - .posts-list .description h2 { - font-weight: 700; - border-bottom: none; - padding-bottom: 0; - } - - .posts-list h2.post-tag { - border-bottom: 1px solid rgba(0, 0, 0, 0.2); - padding-bottom: 12px; - } - .posts-list { - margin-top: 60px; - margin-bottom: 24px; - } - - .posts-list .post-preview { - text-decoration: none; - overflow: hidden; - display: block; - border-bottom: 1px solid rgba(0, 0, 0, 0.1); - padding: 24px 0; - } - - .post-preview-last { - border-bottom: none !important; - } - - .posts-list .posts-list-caption { - grid-column: screen; - font-weight: 400; - } - - .posts-list .post-preview h2 { - margin: 0 0 6px 0; - line-height: 1.2em; - font-style: normal; - font-size: 24px; - } - - .posts-list .post-preview p { - margin: 0 0 12px 0; - line-height: 1.4em; - font-size: 16px; - } - - .posts-list .post-preview .thumbnail { - box-sizing: border-box; - margin-bottom: 24px; - position: relative; - max-width: 500px; - } - .posts-list .post-preview img { - width: 100%; - display: block; - } - - .posts-list .metadata { - font-size: 12px; - line-height: 1.4em; - margin-bottom: 18px; - } - - .posts-list .metadata > * { - display: inline-block; - } - - .posts-list .metadata .publishedDate { - margin-right: 2em; - } - - .posts-list .metadata .dt-authors { - display: block; - margin-top: 0.3em; - margin-right: 2em; - } - - .posts-list .dt-tags { - display: block; - line-height: 1em; - } - - .posts-list .dt-tags .dt-tag { - display: inline-block; - color: rgba(0,0,0,0.6); - padding: 0.3em 0.4em; - margin-right: 0.2em; - margin-bottom: 0.4em; - font-size: 60%; - border: 1px solid rgba(0,0,0,0.2); - border-radius: 3px; - text-transform: uppercase; - font-weight: 500; - } - - .posts-list img { - opacity: 1; - } - - .posts-list img[data-src] { - opacity: 0; - } - - .posts-more { - clear: both; - } - - - .posts-sidebar { - font-size: 16px; - } - - .posts-sidebar h3 { - font-size: 16px; - margin-top: 0; - margin-bottom: 0.5em; - font-weight: 400; - text-transform: uppercase; - } - - .sidebar-section { - margin-bottom: 30px; - } - - .categories ul { - list-style-type: none; - margin: 0; - padding: 0; - } - - .categories li { - color: rgba(0, 0, 0, 0.8); - margin-bottom: 0; - } - - .categories li>a { - border-bottom: none; - } - - .categories li>a:hover { - border-bottom: 1px solid rgba(0, 0, 0, 0.4); - } - - .categories .active { - font-weight: 600; - } - - .categories .category-count { - color: rgba(0, 0, 0, 0.4); - } - - - @media(min-width: 768px) { - .posts-list .post-preview h2 { - font-size: 26px; - } - .posts-list .post-preview .thumbnail { - float: right; - width: 30%; - margin-bottom: 0; - } - .posts-list .post-preview .description { - float: left; - width: 45%; - } - .posts-list .post-preview .metadata { - float: left; - width: 20%; - margin-top: 8px; - } - .posts-list .post-preview p { - margin: 0 0 12px 0; - line-height: 1.5em; - font-size: 16px; - } - .posts-with-sidebar .posts-list { - float: left; - width: 75%; - } - .posts-with-sidebar .posts-sidebar { - float: right; - width: 20%; - margin-top: 60px; - padding-top: 24px; - padding-bottom: 24px; - } - } - - - /* Improve display for browsers without grid (IE/Edge <= 15) */ - - .downlevel { - line-height: 1.6em; - font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial, sans-serif; - margin: 0; - } - - .downlevel .d-title { - padding-top: 6rem; - padding-bottom: 1.5rem; - } - - .downlevel .d-title h1 { - font-size: 50px; - font-weight: 700; - line-height: 1.1em; - margin: 0 0 0.5rem; - } - - .downlevel .d-title p { - font-weight: 300; - font-size: 1.2rem; - line-height: 1.55em; - margin-top: 0; - } - - .downlevel .d-byline { - padding-top: 0.8em; - padding-bottom: 0.8em; - font-size: 0.8rem; - line-height: 1.8em; - } - - .downlevel .section-separator { - border: none; - border-top: 1px solid rgba(0, 0, 0, 0.1); - } - - .downlevel .d-article { - font-size: 1.06rem; - line-height: 1.7em; - padding-top: 1rem; - padding-bottom: 2rem; - } - - - .downlevel .d-appendix { - padding-left: 0; - padding-right: 0; - max-width: none; - font-size: 0.8em; - line-height: 1.7em; - margin-bottom: 0; - color: rgba(0,0,0,0.5); - padding-top: 40px; - padding-bottom: 48px; - } - - .downlevel .footnotes ol { - padding-left: 13px; - } - - .downlevel .base-grid, - .downlevel .distill-header, - .downlevel .d-title, - .downlevel .d-abstract, - .downlevel .d-article, - .downlevel .d-appendix, - .downlevel .distill-appendix, - .downlevel .d-byline, - .downlevel .d-footnote-list, - .downlevel .d-citation-list, - .downlevel .distill-footer, - .downlevel .appendix-bottom, - .downlevel .posts-container { - padding-left: 40px; - padding-right: 40px; - } - - @media(min-width: 768px) { - .downlevel .base-grid, - .downlevel .distill-header, - .downlevel .d-title, - .downlevel .d-abstract, - .downlevel .d-article, - .downlevel .d-appendix, - .downlevel .distill-appendix, - .downlevel .d-byline, - .downlevel .d-footnote-list, - .downlevel .d-citation-list, - .downlevel .distill-footer, - .downlevel .appendix-bottom, - .downlevel .posts-container { - padding-left: 150px; - padding-right: 150px; - max-width: 900px; - } - } - - .downlevel pre code { - display: block; - border-left: 2px solid rgba(0, 0, 0, .1); - padding: 0 0 0 20px; - font-size: 14px; - } - - .downlevel code, .downlevel pre { - color: black; - background: none; - font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; - text-align: left; - white-space: pre; - word-spacing: normal; - word-break: normal; - word-wrap: normal; - line-height: 1.5; - - -moz-tab-size: 4; - -o-tab-size: 4; - tab-size: 4; - - -webkit-hyphens: none; - -moz-hyphens: none; - -ms-hyphens: none; - hyphens: none; - } - - .downlevel .posts-list .post-preview { - color: inherit; - } - - - - </style> - - <script type="application/javascript"> - - function is_downlevel_browser() { - if (bowser.isUnsupportedBrowser({ msie: "12", msedge: "16"}, - window.navigator.userAgent)) { - return true; - } else { - return window.load_distill_framework === undefined; - } - } - - // show body when load is complete - function on_load_complete() { - - // add anchors - if (window.anchors) { - window.anchors.options.placement = 'left'; - window.anchors.add('d-article > h2, d-article > h3, d-article > h4, d-article > h5'); - } - - - // set body to visible - document.body.style.visibility = 'visible'; - - // force redraw for leaflet widgets - if (window.HTMLWidgets) { - var maps = window.HTMLWidgets.findAll(".leaflet"); - $.each(maps, function(i, el) { - var map = this.getMap(); - map.invalidateSize(); - map.eachLayer(function(layer) { - if (layer instanceof L.TileLayer) - layer.redraw(); - }); - }); - } - - // trigger 'shown' so htmlwidgets resize - $('d-article').trigger('shown'); - } - - function init_distill() { - - init_common(); - - // create front matter - var front_matter = $('<d-front-matter></d-front-matter>'); - $('#distill-front-matter').wrap(front_matter); - - // create d-title - $('.d-title').changeElementType('d-title'); - - // create d-byline - var byline = $('<d-byline></d-byline>'); - $('.d-byline').replaceWith(byline); - - // create d-article - var article = $('<d-article></d-article>'); - $('.d-article').wrap(article).children().unwrap(); - - // move posts container into article - $('.posts-container').appendTo($('d-article')); - - // create d-appendix - $('.d-appendix').changeElementType('d-appendix'); - - // flag indicating that we have appendix items - var appendix = $('.appendix-bottom').children('h3').length > 0; - - // replace footnotes with <d-footnote> - $('.footnote-ref').each(function(i, val) { - appendix = true; - var href = $(this).attr('href'); - var id = href.replace('#', ''); - var fn = $('#' + id); - var fn_p = $('#' + id + '>p'); - fn_p.find('.footnote-back').remove(); - var text = fn_p.html(); - var dtfn = $('<d-footnote></d-footnote>'); - dtfn.html(text); - $(this).replaceWith(dtfn); - }); - // remove footnotes - $('.footnotes').remove(); - - // move refs into #references-listing - $('#references-listing').replaceWith($('#refs')); - - $('h1.appendix, h2.appendix').each(function(i, val) { - $(this).changeElementType('h3'); - }); - $('h3.appendix').each(function(i, val) { - var id = $(this).attr('id'); - $('.d-contents a[href="#' + id + '"]').parent().remove(); - appendix = true; - $(this).nextUntil($('h1, h2, h3')).addBack().appendTo($('d-appendix')); - }); - - // show d-appendix if we have appendix content - $("d-appendix").css('display', appendix ? 'grid' : 'none'); - - // localize layout chunks to just output - $('.layout-chunk').each(function(i, val) { - - // capture layout - var layout = $(this).attr('data-layout'); - - // apply layout to markdown level block elements - var elements = $(this).children().not('details, div.sourceCode, pre, script'); - elements.each(function(i, el) { - var layout_div = $('<div class="' + layout + '"></div>'); - if (layout_div.hasClass('shaded')) { - var shaded_content = $('<div class="shaded-content"></div>'); - $(this).wrap(shaded_content); - $(this).parent().wrap(layout_div); - } else { - $(this).wrap(layout_div); - } - }); - - - // unwrap the layout-chunk div - $(this).children().unwrap(); - }); - - // remove code block used to force highlighting css - $('.distill-force-highlighting-css').parent().remove(); - - // remove empty line numbers inserted by pandoc when using a - // custom syntax highlighting theme - $('code.sourceCode a:empty').remove(); - - // load distill framework - load_distill_framework(); - - // wait for window.distillRunlevel == 4 to do post processing - function distill_post_process() { - - if (!window.distillRunlevel || window.distillRunlevel < 4) - return; - - // hide author/affiliations entirely if we have no authors - var front_matter = JSON.parse($("#distill-front-matter").html()); - var have_authors = front_matter.authors && front_matter.authors.length > 0; - if (!have_authors) - $('d-byline').addClass('hidden'); - - // article with toc class - $('.d-contents').parent().addClass('d-article-with-toc'); - - // strip links that point to # - $('.authors-affiliations').find('a[href="#"]').removeAttr('href'); - - // add orcid ids - $('.authors-affiliations').find('.author').each(function(i, el) { - var orcid_id = front_matter.authors[i].orcidID; - if (orcid_id) { - var a = $('<a></a>'); - a.attr('href', 'https://orcid.org/' + orcid_id); - var img = $('<img></img>'); - img.addClass('orcid-id'); - img.attr('alt', 'ORCID ID'); - img.attr('src','data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2ZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo1N0NEMjA4MDI1MjA2ODExOTk0QzkzNTEzRjZEQTg1NyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDozM0NDOEJGNEZGNTcxMUUxODdBOEVCODg2RjdCQ0QwOSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDozM0NDOEJGM0ZGNTcxMUUxODdBOEVCODg2RjdCQ0QwOSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IE1hY2ludG9zaCI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkZDN0YxMTc0MDcyMDY4MTE5NUZFRDc5MUM2MUUwNEREIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjU3Q0QyMDgwMjUyMDY4MTE5OTRDOTM1MTNGNkRBODU3Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+84NovQAAAR1JREFUeNpiZEADy85ZJgCpeCB2QJM6AMQLo4yOL0AWZETSqACk1gOxAQN+cAGIA4EGPQBxmJA0nwdpjjQ8xqArmczw5tMHXAaALDgP1QMxAGqzAAPxQACqh4ER6uf5MBlkm0X4EGayMfMw/Pr7Bd2gRBZogMFBrv01hisv5jLsv9nLAPIOMnjy8RDDyYctyAbFM2EJbRQw+aAWw/LzVgx7b+cwCHKqMhjJFCBLOzAR6+lXX84xnHjYyqAo5IUizkRCwIENQQckGSDGY4TVgAPEaraQr2a4/24bSuoExcJCfAEJihXkWDj3ZAKy9EJGaEo8T0QSxkjSwORsCAuDQCD+QILmD1A9kECEZgxDaEZhICIzGcIyEyOl2RkgwAAhkmC+eAm0TAAAAABJRU5ErkJggg=='); - a.append(img); - $(this).append(a); - } - }); - - // hide elements of author/affiliations grid that have no value - function hide_byline_column(caption) { - $('d-byline').find('h3:contains("' + caption + '")').parent().css('visibility', 'hidden'); - } - - // affiliations - var have_affiliations = false; - for (var i = 0; i<front_matter.authors.length; ++i) { - var author = front_matter.authors[i]; - if (author.affiliation !== " ") { - have_affiliations = true; - break; - } - } - if (!have_affiliations) - $('d-byline').find('h3:contains("Affiliations")').css('visibility', 'hidden'); - - // published date - if (!front_matter.publishedDate) - hide_byline_column("Published"); - - // document object identifier - var doi = $('d-byline').find('h3:contains("DOI")'); - var doi_p = doi.next().empty(); - if (!front_matter.doi) { - // if we have a citation and valid citationText then link to that - if ($('#citation').length > 0 && front_matter.citationText) { - doi.html('Citation'); - $('<a href="#citation"></a>') - .text(front_matter.citationText) - .appendTo(doi_p); - } else { - hide_byline_column("DOI"); - } - } else { - $('<a></a>') - .attr('href', "https://doi.org/" + front_matter.doi) - .html(front_matter.doi) - .appendTo(doi_p); - } - - // change plural form of authors/affiliations - if (front_matter.authors.length === 1) { - var grid = $('.authors-affiliations'); - grid.children('h3:contains("Authors")').text('Author'); - grid.children('h3:contains("Affiliations")').text('Affiliation'); - } - - // remove d-appendix and d-footnote-list local styles - $('d-appendix > style:first-child').remove(); - $('d-footnote-list > style:first-child').remove(); - - // move appendix-bottom entries to the bottom - $('.appendix-bottom').appendTo('d-appendix').children().unwrap(); - $('.appendix-bottom').remove(); - - // hoverable references - $('span.citation[data-cites]').each(function() { - const citeChild = $(this).children()[0] - // Do not process if @xyz has been used without escaping and without bibliography activated - // https://github.com/rstudio/distill/issues/466 - if (citeChild === undefined) return true - - if (citeChild.nodeName == "D-FOOTNOTE") { - var fn = citeChild - $(this).html(fn.shadowRoot.querySelector("sup")) - $(this).id = fn.id - fn.remove() - } - var refs = $(this).attr('data-cites').split(" "); - var refHtml = refs.map(function(ref) { - // Could use CSS.escape too here, we insure backward compatibility in navigator - return "<p>" + $('div[id="ref-' + ref + '"]').html() + "</p>"; - }).join("\n"); - window.tippy(this, { - allowHTML: true, - content: refHtml, - maxWidth: 500, - interactive: true, - interactiveBorder: 10, - theme: 'light-border', - placement: 'bottom-start' - }); - }); - - // fix footnotes in tables (#411) - // replacing broken distill.pub feature - $('table d-footnote').each(function() { - // we replace internal showAtNode methode which is triggered when hovering a footnote - this.hoverBox.showAtNode = function(node) { - // ported from https://github.com/distillpub/template/pull/105/files - calcOffset = function(elem) { - let x = elem.offsetLeft; - let y = elem.offsetTop; - // Traverse upwards until an `absolute` element is found or `elem` - // becomes null. - while (elem = elem.offsetParent && elem.style.position != 'absolute') { - x += elem.offsetLeft; - y += elem.offsetTop; - } - - return { left: x, top: y }; - } - // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetTop - const bbox = node.getBoundingClientRect(); - const offset = calcOffset(node); - this.show([offset.left + bbox.width, offset.top + bbox.height]); - } - }) - - // clear polling timer - clearInterval(tid); - - // show body now that everything is ready - on_load_complete(); - } - - var tid = setInterval(distill_post_process, 50); - distill_post_process(); - - } - - function init_downlevel() { - - init_common(); - - // insert hr after d-title - $('.d-title').after($('<hr class="section-separator"/>')); - - // check if we have authors - var front_matter = JSON.parse($("#distill-front-matter").html()); - var have_authors = front_matter.authors && front_matter.authors.length > 0; - - // manage byline/border - if (!have_authors) - $('.d-byline').remove(); - $('.d-byline').after($('<hr class="section-separator"/>')); - $('.d-byline a').remove(); - - // remove toc - $('.d-contents').remove(); - - // move appendix elements - $('h1.appendix, h2.appendix').each(function(i, val) { - $(this).changeElementType('h3'); - }); - $('h3.appendix').each(function(i, val) { - $(this).nextUntil($('h1, h2, h3')).addBack().appendTo($('.d-appendix')); - }); - - - // inject headers into references and footnotes - var refs_header = $('<h3></h3>'); - refs_header.text('References'); - $('#refs').prepend(refs_header); - - var footnotes_header = $('<h3></h3'); - footnotes_header.text('Footnotes'); - $('.footnotes').children('hr').first().replaceWith(footnotes_header); - - // move appendix-bottom entries to the bottom - $('.appendix-bottom').appendTo('.d-appendix').children().unwrap(); - $('.appendix-bottom').remove(); - - // remove appendix if it's empty - if ($('.d-appendix').children().length === 0) - $('.d-appendix').remove(); - - // prepend separator above appendix - $('.d-appendix').before($('<hr class="section-separator" style="clear: both"/>')); - - // trim code - $('pre>code').each(function(i, val) { - $(this).html($.trim($(this).html())); - }); - - // move posts-container right before article - $('.posts-container').insertBefore($('.d-article')); - - $('body').addClass('downlevel'); - - on_load_complete(); - } - - - function init_common() { - - // jquery plugin to change element types - (function($) { - $.fn.changeElementType = function(newType) { - var attrs = {}; - - $.each(this[0].attributes, function(idx, attr) { - attrs[attr.nodeName] = attr.nodeValue; - }); - - this.replaceWith(function() { - return $("<" + newType + "/>", attrs).append($(this).contents()); - }); - }; - })(jQuery); - - // prevent underline for linked images - $('a > img').parent().css({'border-bottom' : 'none'}); - - // mark non-body figures created by knitr chunks as 100% width - $('.layout-chunk').each(function(i, val) { - var figures = $(this).find('img, .html-widget'); - // ignore leaflet img layers (#106) - figures = figures.filter(':not(img[class*="leaflet"])') - if ($(this).attr('data-layout') !== "l-body") { - figures.css('width', '100%'); - } else { - figures.css('max-width', '100%'); - figures.filter("[width]").each(function(i, val) { - var fig = $(this); - fig.css('width', fig.attr('width') + 'px'); - }); - - } - }); - - // auto-append index.html to post-preview links in file: protocol - // and in rstudio ide preview - $('.post-preview').each(function(i, val) { - if (window.location.protocol === "file:") - $(this).attr('href', $(this).attr('href') + "index.html"); - }); - - // get rid of index.html references in header - if (window.location.protocol !== "file:") { - $('.distill-site-header a[href]').each(function(i,val) { - $(this).attr('href', $(this).attr('href').replace(/^index[.]html/, "./")); - }); - } - - // add class to pandoc style tables - $('tr.header').parent('thead').parent('table').addClass('pandoc-table'); - $('.kable-table').children('table').addClass('pandoc-table'); - - // add figcaption style to table captions - $('caption').parent('table').addClass("figcaption"); - - // initialize posts list - if (window.init_posts_list) - window.init_posts_list(); - - // implmement disqus comment link - $('.disqus-comment-count').click(function() { - window.headroom_prevent_pin = true; - $('#disqus_thread').toggleClass('hidden'); - if (!$('#disqus_thread').hasClass('hidden')) { - var offset = $(this).offset(); - $(window).resize(); - $('html, body').animate({ - scrollTop: offset.top - 35 - }); - } - }); - } - - document.addEventListener('DOMContentLoaded', function() { - if (is_downlevel_browser()) - init_downlevel(); - else - window.addEventListener('WebComponentsReady', init_distill); - }); - - </script> - - <!--/radix_placeholder_distill--> - <script src="class7_matricies_files/header-attrs-2.14/header-attrs.js"></script> - <script src="class7_matricies_files/jquery-3.6.0/jquery-3.6.0.min.js"></script> - <script src="class7_matricies_files/popper-2.6.0/popper.min.js"></script> - <link href="class7_matricies_files/tippy-6.2.7/tippy.css" rel="stylesheet" /> - <link href="class7_matricies_files/tippy-6.2.7/tippy-light-border.css" rel="stylesheet" /> - <script src="class7_matricies_files/tippy-6.2.7/tippy.umd.min.js"></script> - <script src="class7_matricies_files/anchor-4.2.2/anchor.min.js"></script> - <script src="class7_matricies_files/bowser-1.9.3/bowser.min.js"></script> - <script src="class7_matricies_files/webcomponents-2.0.0/webcomponents.js"></script> - <script src="class7_matricies_files/distill-2.2.21/template.v2.js"></script> - <!--radix_placeholder_site_in_header--> - <!--/radix_placeholder_site_in_header--> - - -</head> - -<body> - -<!--radix_placeholder_front_matter--> - -<script id="distill-front-matter" type="text/json"> -{"title":"Class 7: Introduction to matricies","authors":[{"author":"Kristen Wells","authorURL":"https://github.com/kwells4","affiliation":"RNA Bioscience Iniative, Barbara Davis Diabetes Center","affiliationURL":"#","orcidID":"0000-0002-7466-8164"}],"publishedDate":"2022-12-07T00:00:00.000-07:00","citationText":"Wells, 2022"} -</script> - -<!--/radix_placeholder_front_matter--> -<!--radix_placeholder_navigation_before_body--> -<!--/radix_placeholder_navigation_before_body--> -<!--radix_placeholder_site_before_body--> -<!--/radix_placeholder_site_before_body--> - -<div class="d-title"> -<h1>Class 7: Introduction to matricies</h1> -<!--radix_placeholder_categories--> -<!--/radix_placeholder_categories--> - -</div> - -<div class="d-byline"> - Kristen Wells <a href="https://github.com/kwells4" class="uri">https://github.com/kwells4</a> (RNA Bioscience Iniative, Barbara Davis Diabetes Center) - -<br/>12-07-2022 -</div> - -<div class="d-article"> -<div class="d-contents d-contents-float"> -<nav class="l-text toc figcaption" id="TOC"> -<h3>Contents</h3> -<ul> -<li><a href="#goals-for-this-class" id="toc-goals-for-this-class">Goals for this class</a></li> -<li><a href="#load-packages" id="toc-load-packages">Load packages</a></li> -<li><a href="#download-files" id="toc-download-files">Download files</a></li> -<li><a href="#what-is-a-matrix" id="toc-what-is-a-matrix">What is a matrix?</a></li> -<li><a href="#matrix-opearions" id="toc-matrix-opearions">Matrix opearions</a> -<ul> -<li><a href="#basic-operations" id="toc-basic-operations">Basic operations</a></li> -<li><a href="#matrix-multiplication" id="toc-matrix-multiplication">Matrix multiplication</a></li> -</ul></li> -<li><a href="#performing-functions-on-a-matrix" id="toc-performing-functions-on-a-matrix">Performing functions on a matrix</a> -<ul> -<li><a href="#basic-functions" id="toc-basic-functions">Basic functions</a></li> -<li><a href="#summary-functions" id="toc-summary-functions">Summary functions</a></li> -<li><a href="#transposition" id="toc-transposition">Transposition</a></li> -<li><a href="#statistical-tests" id="toc-statistical-tests">Statistical tests</a></li> -</ul></li> -<li><a href="#using-dataframes-and-matricies" id="toc-using-dataframes-and-matricies">Using dataframes and matricies</a></li> -<li><a href="#im-a-biologist-why-should-i-care" id="toc-im-a-biologist-why-should-i-care">I’m a biologist, why should I care?</a></li> -<li><a href="#acknowldgements-and-additional-references" id="toc-acknowldgements-and-additional-references">Acknowldgements and additional references</a></li> -</ul> -</nav> -</div> -<p><em>The Rmarkdown for this class is <a href="https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2022-11-10-class-7-matricies/class7_matricies.Rmd">on github</a></em></p> -<h2 id="goals-for-this-class">Goals for this class</h2> -<ul> -<li>Learn what is a matrix</li> -<li>Describe difference between matrix and data frame</li> -<li>Perform mathematical functions</li> -<li>Convert between matrix and data frames</li> -</ul> -<h2 id="load-packages">Load packages</h2> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='kw'><a href='https://rdrr.io/r/base/library.html'>library</a></span><span class='op'>(</span><span class='va'><a href='https://tidyverse.tidyverse.org'>tidyverse</a></span><span class='op'>)</span></span> -<span><span class='kw'><a href='https://rdrr.io/r/base/library.html'>library</a></span><span class='op'>(</span><span class='va'><a href='https://here.r-lib.org/'>here</a></span><span class='op'>)</span></span></code></pre> -</div> -</div> -<h2 id="download-files">Download files</h2> -<p>Before we get started, let’s download all of the files you will need for the next three classes.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='co'># conditionally download all of the files used in rmarkdown from github </span></span> -<span><span class='kw'><a href='https://rdrr.io/r/base/source.html'>source</a></span><span class='op'>(</span><span class='st'>"https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2022-11-10-class-7-matricies/download_files.R"</span><span class='op'>)</span></span></code></pre> -</div> -</div> -<h2 id="what-is-a-matrix">What is a matrix?</h2> -<p>A Matrix is an 2 dimensional object in R. We create a matrix using the <code>matrix</code> function</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>M</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>matrix</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='fl'>10</span><span class='op'>:</span><span class='fl'>21</span><span class='op'>)</span>, nrow <span class='op'>=</span> <span class='fl'>4</span>, byrow <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span></span> -<span><span class='va'>M</span></span></code></pre> -</div> -<pre><code> [,1] [,2] [,3] -[1,] 10 11 12 -[2,] 13 14 15 -[3,] 16 17 18 -[4,] 19 20 21</code></pre> -</div> -<p>We can also use <code>as.matrix</code> on an existing dataframe</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>df</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/data.frame.html'>data.frame</a></span><span class='op'>(</span><span class='st'>"A"</span> <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='fl'>10</span><span class='op'>:</span><span class='fl'>13</span><span class='op'>)</span>, <span class='st'>"B"</span> <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='fl'>14</span><span class='op'>:</span><span class='fl'>17</span><span class='op'>)</span>, <span class='st'>"C"</span> <span class='op'>=</span> <span class='op'>(</span><span class='fl'>18</span><span class='op'>:</span><span class='fl'>21</span><span class='op'>)</span><span class='op'>)</span></span> -<span><span class='va'>df</span></span></code></pre> -</div> -<pre><code> A B C -1 10 14 18 -2 11 15 19 -3 12 16 20 -4 13 17 21</code></pre> -</div> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>new_mat</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>as.matrix</a></span><span class='op'>(</span><span class='va'>df</span><span class='op'>)</span></span> -<span><span class='va'>new_mat</span></span></code></pre> -</div> -<pre><code> A B C -[1,] 10 14 18 -[2,] 11 15 19 -[3,] 12 16 20 -[4,] 13 17 21</code></pre> -</div> -<p>Just like data frames, we can name the rows and columns of the Matrix</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/colnames.html'>rownames</a></span><span class='op'>(</span><span class='va'>new_mat</span><span class='op'>)</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='st'>"first"</span>, <span class='st'>"second"</span>, <span class='st'>"third"</span>, <span class='st'>"forth"</span><span class='op'>)</span></span> -<span><span class='fu'><a href='https://rdrr.io/r/base/colnames.html'>colnames</a></span><span class='op'>(</span><span class='va'>new_mat</span><span class='op'>)</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='st'>"D"</span>, <span class='st'>"E"</span>, <span class='st'>"F"</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>new_mat</span></span></code></pre> -</div> -<pre><code> D E F -first 10 14 18 -second 11 15 19 -third 12 16 20 -forth 13 17 21</code></pre> -</div> -<p>We can look at the structure of the matrix using <code>str</code></p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/utils/str.html'>str</a></span><span class='op'>(</span><span class='va'>new_mat</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code> int [1:4, 1:3] 10 11 12 13 14 15 16 17 18 19 ... - - attr(*, "dimnames")=List of 2 - ..$ : chr [1:4] "first" "second" "third" "forth" - ..$ : chr [1:3] "D" "E" "F"</code></pre> -</div> -<p>Here you can see that the type of this structure is <code>int</code> because it is a matrix consisting of integers. We can also see the row names and column names.</p> -<p>As with data frames, we can check the size of the matrix using <code>nrow</code>, <code>ncol</code> and <code>dim</code></p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/nrow.html'>nrow</a></span><span class='op'>(</span><span class='va'>new_mat</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>[1] 4</code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/nrow.html'>ncol</a></span><span class='op'>(</span><span class='va'>new_mat</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>[1] 3</code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/dim.html'>dim</a></span><span class='op'>(</span><span class='va'>new_mat</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>[1] 4 3</code></pre> -</div> -<p>We can also access data using brackets<code>[</code></p> -<p>Selecting a single value:</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>new_mat</span><span class='op'>[</span><span class='fl'>1</span>,<span class='fl'>2</span><span class='op'>]</span></span></code></pre> -</div> -<pre><code>[1] 14</code></pre> -</div> -<p>Selecting a section of the matrix:</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>new_mat</span><span class='op'>[</span><span class='fl'>1</span><span class='op'>:</span><span class='fl'>3</span>,<span class='fl'>2</span><span class='op'>]</span></span></code></pre> -</div> -<pre><code> first second third - 14 15 16 </code></pre> -</div> -<p>If we don’t provide an index for the row, R will return all rows:</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>new_mat</span><span class='op'>[</span>, <span class='fl'>3</span><span class='op'>]</span></span></code></pre> -</div> -<pre><code> first second third forth - 18 19 20 21 </code></pre> -</div> -<p>The same is true for the columns</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>new_mat</span><span class='op'>[</span><span class='fl'>3</span>,<span class='op'>]</span></span></code></pre> -</div> -<pre><code> D E F -12 16 20 </code></pre> -</div> -<p>Because this matrix has row and column names, we can also pull out data based on those</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>new_mat</span><span class='op'>[</span><span class='st'>"second"</span>, <span class='st'>"D"</span><span class='op'>]</span></span></code></pre> -</div> -<pre><code>[1] 11</code></pre> -</div> -<p><strong>Exercise</strong></p> -<p>What value is in row 2 and column 3 of <code>new_mat</code>?</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='co'># TODO find the value in the matrix at row 2 and column 3</span></span></code></pre> -</div> -</div> -<p><strong>If we can make a matrix from a data frame, what’s the difference?</strong> -Matrices can only have values of one type –> integer, boolean, character, while a dataframe can be a mix of types:</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>df</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/data.frame.html'>data.frame</a></span><span class='op'>(</span><span class='st'>"A"</span> <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='fl'>10</span><span class='op'>:</span><span class='fl'>12</span><span class='op'>)</span>,</span> -<span> <span class='st'>"B"</span> <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='st'>"cat"</span>, <span class='st'>"dog"</span>, <span class='st'>"fish"</span><span class='op'>)</span>,</span> -<span> <span class='st'>"C"</span> <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='cn'>TRUE</span>, <span class='cn'>TRUE</span>, <span class='cn'>FALSE</span><span class='op'>)</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>df</span></span></code></pre> -</div> -<pre><code> A B C -1 10 cat TRUE -2 11 dog TRUE -3 12 fish FALSE</code></pre> -</div> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>M</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>as.matrix</a></span><span class='op'>(</span><span class='va'>df</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>M</span></span></code></pre> -</div> -<pre><code> A B C -[1,] "10" "cat" "TRUE" -[2,] "11" "dog" "TRUE" -[3,] "12" "fish" "FALSE"</code></pre> -</div> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/typeof.html'>typeof</a></span><span class='op'>(</span><span class='va'>df</span><span class='op'>[</span>,<span class='fl'>1</span><span class='op'>]</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>[1] "integer"</code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/typeof.html'>typeof</a></span><span class='op'>(</span><span class='va'>M</span><span class='op'>[</span>,<span class='fl'>1</span><span class='op'>]</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>[1] "character"</code></pre> -</div> -<p>But Matrices can take any type of input</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>M</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>matrix</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='cn'>TRUE</span>, <span class='cn'>FALSE</span><span class='op'>)</span>, <span class='fl'>4</span><span class='op'>)</span>, nrow <span class='op'>=</span> <span class='fl'>4</span>, byrow <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span></span> -<span><span class='va'>M</span></span></code></pre> -</div> -<pre><code> [,1] [,2] -[1,] TRUE FALSE -[2,] TRUE FALSE -[3,] TRUE FALSE -[4,] TRUE FALSE</code></pre> -</div> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/typeof.html'>typeof</a></span><span class='op'>(</span><span class='va'>M</span><span class='op'>[</span>,<span class='fl'>1</span><span class='op'>]</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>[1] "logical"</code></pre> -</div> -<h2 id="matrix-opearions">Matrix opearions</h2> -<p>If you’ve taken linear algebra, you’ve probably worked with matrices before. These same matrix operations can be done in R</p> -<h3 id="basic-operations">Basic operations</h3> -<p>We can do any of the mathematical operations for a matrix and one value. For example, we can add 5 to all values in a matrix, or subtract 2, or divide by 10</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>M</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>matrix</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='fl'>10</span><span class='op'>:</span><span class='fl'>21</span><span class='op'>)</span>, nrow <span class='op'>=</span> <span class='fl'>4</span>, byrow <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span></span> -<span><span class='va'>M</span></span></code></pre> -</div> -<pre><code> [,1] [,2] [,3] -[1,] 10 11 12 -[2,] 13 14 15 -[3,] 16 17 18 -[4,] 19 20 21</code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>M</span> <span class='op'>+</span> <span class='fl'>1</span></span></code></pre> -</div> -<pre><code> [,1] [,2] [,3] -[1,] 11 12 13 -[2,] 14 15 16 -[3,] 17 18 19 -[4,] 20 21 22</code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>M</span> <span class='op'>+</span> <span class='fl'>2</span></span></code></pre> -</div> -<pre><code> [,1] [,2] [,3] -[1,] 12 13 14 -[2,] 15 16 17 -[3,] 18 19 20 -[4,] 21 22 23</code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>M</span> <span class='op'>-</span> <span class='fl'>5</span></span></code></pre> -</div> -<pre><code> [,1] [,2] [,3] -[1,] 5 6 7 -[2,] 8 9 10 -[3,] 11 12 13 -[4,] 14 15 16</code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>M</span> <span class='op'>/</span> <span class='fl'>3</span></span></code></pre> -</div> -<pre><code> [,1] [,2] [,3] -[1,] 3.333333 3.666667 4 -[2,] 4.333333 4.666667 5 -[3,] 5.333333 5.666667 6 -[4,] 6.333333 6.666667 7</code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>M</span> <span class='op'>*</span> <span class='fl'>10</span></span></code></pre> -</div> -<pre><code> [,1] [,2] [,3] -[1,] 100 110 120 -[2,] 130 140 150 -[3,] 160 170 180 -[4,] 190 200 210</code></pre> -</div> -<p>We can also provide a vector or another matrix to perform element-wise functions with.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>vector</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='fl'>2</span>, <span class='fl'>3</span>, <span class='fl'>4</span>, <span class='fl'>5</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>M</span> <span class='op'>+</span> <span class='va'>vector</span></span></code></pre> -</div> -<pre><code> [,1] [,2] [,3] -[1,] 12 13 14 -[2,] 16 17 18 -[3,] 20 21 22 -[4,] 24 25 26</code></pre> -</div> -<p>Here you can see that each element of the vector is added to a row ie element 1 is added to row 1, element 2 is added to row 2, etc.</p> -<p>The same is true for subtraction</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>M</span> <span class='op'>-</span> <span class='va'>vector</span></span></code></pre> -</div> -<pre><code> [,1] [,2] [,3] -[1,] 8 9 10 -[2,] 10 11 12 -[3,] 12 13 14 -[4,] 14 15 16</code></pre> -</div> -<p>And multiplication and division</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>M</span> <span class='op'>/</span> <span class='va'>vector</span></span></code></pre> -</div> -<pre><code> [,1] [,2] [,3] -[1,] 5.000000 5.500000 6.0 -[2,] 4.333333 4.666667 5.0 -[3,] 4.000000 4.250000 4.5 -[4,] 3.800000 4.000000 4.2</code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>M</span> <span class='op'>*</span> <span class='va'>vector</span></span></code></pre> -</div> -<pre><code> [,1] [,2] [,3] -[1,] 20 22 24 -[2,] 39 42 45 -[3,] 64 68 72 -[4,] 95 100 105</code></pre> -</div> -<p>What happens if there are a different number of rows as elements in the vector?</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>vector</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='fl'>2</span>, <span class='fl'>3</span>, <span class='fl'>4</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>M</span></span></code></pre> -</div> -<pre><code> [,1] [,2] [,3] -[1,] 10 11 12 -[2,] 13 14 15 -[3,] 16 17 18 -[4,] 19 20 21</code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>M</span> <span class='op'>+</span> <span class='va'>vector</span></span></code></pre> -</div> -<pre><code> [,1] [,2] [,3] -[1,] 12 14 16 -[2,] 16 18 17 -[3,] 20 19 21 -[4,] 21 23 25</code></pre> -</div> -<p>Note how the vector just gets reused, no error is thrown.</p> -<p>We can also perform these operations on two matrices</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>M1</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>matrix</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='fl'>10</span><span class='op'>:</span><span class='fl'>21</span><span class='op'>)</span>, nrow <span class='op'>=</span> <span class='fl'>4</span>, byrow <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span></span> -<span><span class='va'>M2</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>matrix</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='fl'>110</span><span class='op'>:</span><span class='fl'>121</span><span class='op'>)</span>, nrow <span class='op'>=</span><span class='fl'>4</span>, byrow <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>M1</span></span></code></pre> -</div> -<pre><code> [,1] [,2] [,3] -[1,] 10 11 12 -[2,] 13 14 15 -[3,] 16 17 18 -[4,] 19 20 21</code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>M2</span></span></code></pre> -</div> -<pre><code> [,1] [,2] [,3] -[1,] 110 111 112 -[2,] 113 114 115 -[3,] 116 117 118 -[4,] 119 120 121</code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>M1</span> <span class='op'>+</span> <span class='va'>M2</span></span></code></pre> -</div> -<pre><code> [,1] [,2] [,3] -[1,] 120 122 124 -[2,] 126 128 130 -[3,] 132 134 136 -[4,] 138 140 142</code></pre> -</div> -<p>Note how elements in the same position of each matrix are added together</p> -<p><em>Note this also is true of vectors</em></p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>v1</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='fl'>1</span>,<span class='fl'>2</span>,<span class='fl'>3</span><span class='op'>)</span></span> -<span><span class='va'>v2</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='fl'>4</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>v1</span> <span class='op'>+</span> <span class='va'>v2</span></span></code></pre> -</div> -<pre><code>[1] 5 6 7</code></pre> -</div> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>v3</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='fl'>5</span>, <span class='fl'>6</span><span class='op'>)</span></span> -<span><span class='va'>v1</span> <span class='op'>+</span> <span class='va'>v3</span></span></code></pre> -</div> -<pre><code>[1] 6 8 8</code></pre> -</div> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>v4</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='fl'>10</span>, <span class='fl'>11</span>, <span class='fl'>12</span>, <span class='fl'>13</span>, <span class='fl'>14</span>, <span class='fl'>15</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>v1</span> <span class='op'>+</span> <span class='va'>v4</span></span></code></pre> -</div> -<pre><code>[1] 11 13 15 14 16 18</code></pre> -</div> -<p><strong>Exercise</strong> -Multiply, subtract, and divide the two matrices <code>M1</code> and <code>M2</code></p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='co'># TODO multiply, subtract and divide M1 and M2</span></span></code></pre> -</div> -</div> -<h3 id="matrix-multiplication">Matrix multiplication</h3> -<p>We will only briefly touch on matrix multiplication, but one reason matrices are very important in R is that you can perform multiplication with them. Exactly how this is done is explained nicely in a <a href="https://www.mathsisfun.com/algebra/matrix-multiplying.html">math is fun</a> tutorial.</p> -<p>Let’s try to multiply two matrices together. Remember our first matrix has 4 rows and 3 columns:</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/dim.html'>dim</a></span><span class='op'>(</span><span class='va'>M</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>[1] 4 3</code></pre> -</div> -<p>So our new matrix must have 3 rows</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>M2</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>matrix</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='fl'>5</span><span class='op'>:</span><span class='fl'>19</span><span class='op'>)</span>, nrow <span class='op'>=</span> <span class='fl'>3</span>, byrow <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span></span> -<span><span class='va'>M2</span></span></code></pre> -</div> -<pre><code> [,1] [,2] [,3] [,4] [,5] -[1,] 5 6 7 8 9 -[2,] 10 11 12 13 14 -[3,] 15 16 17 18 19</code></pre> -</div> -<p>Let’s perform matrix multiplication with these</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>M</span> <span class='op'><a href='https://rdrr.io/r/base/matmult.html'>%*%</a></span> <span class='va'>M2</span></span></code></pre> -</div> -<pre><code> [,1] [,2] [,3] [,4] [,5] -[1,] 340 373 406 439 472 -[2,] 430 472 514 556 598 -[3,] 520 571 622 673 724 -[4,] 610 670 730 790 850</code></pre> -</div> -<h2 id="performing-functions-on-a-matrix">Performing functions on a matrix</h2> -<p>So far, a matrix has looked a lot like a dataframe with some limitations. One of the places where matrices become the most useful is performing statistical functions because all items in a matrix are of the same type.</p> -<p>For this next section, let’s use some data that I downloaded from the social security office. This has the top 100 boy and girl names by state for 2020.</p> -<p>We can now read in the data and convert it to a matrix</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>names_mat</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/utils/read.table.html'>read.csv</a></span><span class='op'>(</span><span class='fu'><a href='https://here.r-lib.org//reference/here.html'>here</a></span><span class='op'>(</span><span class='st'>"class_7-9_data"</span>, <span class='st'>"boy_name_counts.csv"</span><span class='op'>)</span>,</span> -<span> row.names <span class='op'>=</span> <span class='fl'>1</span><span class='op'>)</span> <span class='op'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%>%</a></span></span> -<span> <span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>as.matrix</a></span><span class='op'>(</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>names_mat</span><span class='op'>[</span><span class='fl'>1</span><span class='op'>:</span><span class='fl'>5</span>, <span class='fl'>1</span><span class='op'>:</span><span class='fl'>5</span><span class='op'>]</span></span></code></pre> -</div> -<pre><code> Alabama Alaska Arizona Arkansas California -William 366 36 174 152 1021 -James 304 34 215 105 1148 -John 267 20 97 94 623 -Elijah 254 42 284 143 1586 -Noah 243 35 397 138 2625</code></pre> -</div> -<p>Above you can see that we have the number of males with each name in each state. Looking at the structure, we can see that it is an integer matrix.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/utils/str.html'>str</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code> int [1:40, 1:20] 366 304 267 254 243 207 187 183 173 166 ... - - attr(*, "dimnames")=List of 2 - ..$ : chr [1:40] "William" "James" "John" "Elijah" ... - ..$ : chr [1:20] "Alabama" "Alaska" "Arizona" "Arkansas" ...</code></pre> -</div> -<p>We can now explore this data set using many of the functions you have already learned such as <code>rowSums</code> and <code>colSums</code></p> -<h3 id="basic-functions">Basic functions</h3> -<p>First, lets find the sum for all of the rows - how many total babies were named each name?</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/colSums.html'>rowSums</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code> William James John Elijah Noah Liam Mason - 5067 5005 3295 5921 8118 8512 4040 - Oliver Henry Jackson Samuel Jaxon Asher Grayson - 5961 4121 3599 3549 2571 3212 2938 - Levi Michael Carter Benjamin Charles Wyatt Thomas - 3717 4061 3017 5265 2427 3255 2475 - Aiden Luke David Owen Daniel Logan Joseph - 3872 3230 3554 3369 4223 3933 3356 - Lucas Joshua Jack Alexander Maverick Gabriel Ethan - 4794 2645 3399 4530 2588 3091 4322 - Eli Isaac Hunter Ezra Theodore - 2202 3029 1940 2999 3409 </code></pre> -</div> -<p>And then the columns - how many babies were included from each state?</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/colSums.html'>colSums</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code> Alabama Alaska Arizona Arkansas California - 5687 986 7371 3428 41256 - Colorado Connecticut Delaware Florida Georgia - 6396 4211 1117 21661 11791 - Hawaii Idaho Illinois Indiana Iowa - 1111 2306 13407 8283 3508 - Kansas Kentucky Louisiana Maine Maryland - 3630 5518 4955 1372 6617 </code></pre> -</div> -<p>What if we want to find the percent of children with a given name across all states (divide the value by the row sum * 100) - what percent of total babies for each name came from each state:</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>percent_mat</span> <span class='op'><-</span> <span class='va'>names_mat</span> <span class='op'>/</span> <span class='fu'><a href='https://rdrr.io/r/base/colSums.html'>rowSums</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>)</span> <span class='op'>*</span> <span class='fl'>100</span></span> -<span><span class='va'>percent_mat</span><span class='op'>[</span><span class='fl'>1</span><span class='op'>:</span><span class='fl'>5</span>, <span class='fl'>1</span><span class='op'>:</span><span class='fl'>5</span><span class='op'>]</span></span></code></pre> -</div> -<pre><code> Alabama Alaska Arizona Arkansas California -William 7.223209 0.7104796 3.433985 2.999803 20.14999 -James 6.073926 0.6793207 4.295704 2.097902 22.93706 -John 8.103187 0.6069803 2.943854 2.852807 18.90744 -Elijah 4.289816 0.7093396 4.796487 2.415133 26.78602 -Noah 2.993348 0.4311407 4.890367 1.699926 32.33555</code></pre> -</div> -<p><em>Remember from above that division using a vector will divide every element of a row by one value, so we can only do this using <code>rowSums</code>. In a few minutes we will discuss how do do this on the columns.</em></p> -<h3 id="summary-functions">Summary functions</h3> -<p>We can also find the minimum, maximum, mean, and median values of the whole matrix and any column. First, lets get summary data for the whole matrix using <code>summary</code></p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/summary.html'>summary</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>)</span><span class='op'>[</span> , <span class='fl'>1</span><span class='op'>:</span><span class='fl'>3</span><span class='op'>]</span></span></code></pre> -</div> -<pre><code> Alabama Alaska Arizona - Min. : 61.00 Min. :14.00 Min. : 84.0 - 1st Qu.: 94.75 1st Qu.:18.00 1st Qu.:143.8 - Median :125.00 Median :22.50 Median :174.5 - Mean :142.18 Mean :24.65 Mean :184.3 - 3rd Qu.:163.00 3rd Qu.:28.00 3rd Qu.:191.2 - Max. :366.00 Max. :44.00 Max. :451.0 </code></pre> -</div> -<p>You can see that this calculates the min, max, mean, median, and quartiles for the columns.</p> -<p>What if we just want the minimum value for the “Alabama” names? We can run <code>min</code> while subsetting to just the column of interest</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/Extremes.html'>min</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>[</span>, <span class='st'>"Alabama"</span><span class='op'>]</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>[1] 61</code></pre> -</div> -<p>We can do the same for the rows Lets try this for “William”</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/Extremes.html'>min</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>[</span><span class='st'>"William"</span>,<span class='op'>]</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>[1] 29</code></pre> -</div> -<p>What if we wanted to find the smallest value in the whole matrix?</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/Extremes.html'>min</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>[1] 13</code></pre> -</div> -<p><code>max</code> works the same as min</p> -<p><strong>Exercise</strong> -Find the maximum value in the for “Noah”</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='co'># TODO Find the maximum value in the second row and the whole matrix</span></span></code></pre> -</div> -</div> -<p>We can also find the mean, median, and standard deviation of any part of the matrix</p> -<p>By row:</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/mean.html'>mean</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>[</span><span class='st'>"William"</span>, <span class='op'>]</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>[1] 253.35</code></pre> -</div> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/stats/median.html'>median</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>[</span><span class='st'>"William"</span>, <span class='op'>]</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>[1] 178</code></pre> -</div> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/stats/sd.html'>sd</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>[</span><span class='st'>"William"</span>, <span class='op'>]</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>[1] 239.8189</code></pre> -</div> -<p>By column:</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/mean.html'>mean</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>[</span> , <span class='st'>"Alabama"</span><span class='op'>]</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>[1] 142.175</code></pre> -</div> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/stats/median.html'>median</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>[</span> , <span class='st'>"Alabama"</span><span class='op'>]</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>[1] 125</code></pre> -</div> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/stats/sd.html'>sd</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>[</span> , <span class='st'>"Alabama"</span><span class='op'>]</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>[1] 67.66012</code></pre> -</div> -<h3 id="transposition">Transposition</h3> -<p>One important quality of a matrix is being able to transpose it to interchange the rows and columns - here the rows become columns and columns become rows. We transpose using <code>t()</code> to the matrix. Let’s first look at this using the matrix we started with</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>M</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>matrix</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='fl'>10</span><span class='op'>:</span><span class='fl'>21</span><span class='op'>)</span>, nrow <span class='op'>=</span> <span class='fl'>4</span>, byrow <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span></span> -<span><span class='va'>M</span></span></code></pre> -</div> -<pre><code> [,1] [,2] [,3] -[1,] 10 11 12 -[2,] 13 14 15 -[3,] 16 17 18 -[4,] 19 20 21</code></pre> -</div> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/t.html'>t</a></span><span class='op'>(</span><span class='va'>M</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code> [,1] [,2] [,3] [,4] -[1,] 10 13 16 19 -[2,] 11 14 17 20 -[3,] 12 15 18 21</code></pre> -</div> -<p>Note that the output of transposing either a matrix or a data frame will be a matrix (because the type within a column of a data frame must be the same).</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>df</span></span></code></pre> -</div> -<pre><code> A B C -1 10 cat TRUE -2 11 dog TRUE -3 12 fish FALSE</code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/t.html'>t</a></span><span class='op'>(</span><span class='va'>df</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code> [,1] [,2] [,3] -A "10" "11" "12" -B "cat" "dog" "fish" -C "TRUE" "TRUE" "FALSE"</code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/utils/str.html'>str</a></span><span class='op'>(</span><span class='va'>df</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>'data.frame': 3 obs. of 3 variables: - $ A: int 10 11 12 - $ B: chr "cat" "dog" "fish" - $ C: logi TRUE TRUE FALSE</code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/utils/str.html'>str</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/t.html'>t</a></span><span class='op'>(</span><span class='va'>df</span><span class='op'>)</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code> chr [1:3, 1:3] "10" "cat" "TRUE" "11" "dog" "TRUE" "12" "fish" ... - - attr(*, "dimnames")=List of 2 - ..$ : chr [1:3] "A" "B" "C" - ..$ : NULL</code></pre> -</div> -<p>Note how after the transposition, all items in the original df are now characters and we no longer have a dataframe.</p> -<p>Now let’s try this transposition on the names matrix we’ve been working with</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>transposed_mat</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/t.html'>t</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>transposed_mat</span><span class='op'>[</span><span class='fl'>1</span><span class='op'>:</span><span class='fl'>3</span>,<span class='fl'>1</span><span class='op'>:</span><span class='fl'>3</span><span class='op'>]</span></span></code></pre> -</div> -<pre><code> William James John -Alabama 366 304 267 -Alaska 36 34 20 -Arizona 174 215 97</code></pre> -</div> -<p>Note how the columns are now names and the rows are now states.</p> -<p>Remember the note above where we could only divide by the <code>rowSums</code>? Now we can use this transposition to figure out the percent of children in each state with a given name (divide the value by the column sum * 100)</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>state_percents</span> <span class='op'><-</span> <span class='va'>transposed_mat</span> <span class='op'>/</span> <span class='fu'><a href='https://rdrr.io/r/base/colSums.html'>rowSums</a></span><span class='op'>(</span><span class='va'>transposed_mat</span><span class='op'>)</span> <span class='op'>*</span> <span class='fl'>100</span></span> -<span></span> -<span><span class='va'>state_percents</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/t.html'>t</a></span><span class='op'>(</span><span class='va'>state_percents</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>state_percents</span><span class='op'>[</span><span class='fl'>1</span><span class='op'>:</span><span class='fl'>3</span>, <span class='fl'>1</span><span class='op'>:</span><span class='fl'>3</span><span class='op'>]</span></span></code></pre> -</div> -<pre><code> Alabama Alaska Arizona -William 6.435731 3.651116 2.360602 -James 5.345525 3.448276 2.916836 -John 4.694918 2.028398 1.315968</code></pre> -</div> -<p>Above we did this in several steps, but we can also do in in one step:</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>state_percents_2</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/t.html'>t</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/t.html'>t</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>)</span> <span class='op'>/</span> <span class='fu'><a href='https://rdrr.io/r/base/colSums.html'>colSums</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>*</span> <span class='fl'>100</span></span> -<span></span> -<span><span class='fu'><a href='https://rdrr.io/r/base/identical.html'>identical</a></span><span class='op'>(</span><span class='va'>state_percents</span>, <span class='va'>state_percents_2</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>[1] TRUE</code></pre> -</div> -<h3 id="statistical-tests">Statistical tests</h3> -<p>We can also use matrices to perform statistical tests, like t-tests. For instance, are the names Oliver and Noah, or Oliver and Thomas used different amounts?</p> -<p>First, let’s normalize the data to account for the fact that each state reported different numbers of births. To do this normalization, let’s first divide each value by the total number of children reported for that state. Remember, we need to first transpose the matrix to be able to divide by the <code>colSums</code></p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>normalized_mat</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/t.html'>t</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/t.html'>t</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>)</span> <span class='op'>/</span> <span class='fu'><a href='https://rdrr.io/r/base/colSums.html'>colSums</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>)</span><span class='op'>)</span></span></code></pre> -</div> -</div> -<p>Now that we have normalized values, we can do a t-test.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>normalized_mat</span><span class='op'>[</span><span class='st'>"Oliver"</span>, <span class='fl'>1</span><span class='op'>:</span><span class='fl'>3</span><span class='op'>]</span></span></code></pre> -</div> -<pre><code> Alabama Alaska Arizona -0.03217865 0.04361055 0.04124271 </code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>normalized_mat</span><span class='op'>[</span><span class='st'>"Noah"</span>, <span class='fl'>1</span><span class='op'>:</span><span class='fl'>3</span><span class='op'>]</span></span></code></pre> -</div> -<pre><code> Alabama Alaska Arizona -0.04272903 0.03549696 0.05385972 </code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>normalized_mat</span><span class='op'>[</span><span class='st'>"Thomas"</span>, <span class='fl'>1</span><span class='op'>:</span><span class='fl'>3</span><span class='op'>]</span></span></code></pre> -</div> -<pre><code> Alabama Alaska Arizona -0.02092492 0.02028398 0.01329535 </code></pre> -</div> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/stats/t.test.html'>t.test</a></span><span class='op'>(</span><span class='va'>normalized_mat</span><span class='op'>[</span><span class='st'>"Oliver"</span>,<span class='op'>]</span>, <span class='va'>normalized_mat</span><span class='op'>[</span><span class='st'>"Noah"</span>,<span class='op'>]</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code> - Welch Two Sample t-test - -data: normalized_mat["Oliver", ] and normalized_mat["Noah", ] -t = -1.1861, df = 36.481, p-value = 0.2433 -alternative hypothesis: true difference in means is not equal to 0 -95 percent confidence interval: - -0.010275411 0.002689617 -sample estimates: - mean of x mean of y -0.04133411 0.04512700 </code></pre> -</div> -<p>Between Oliver and Noah, there does not seem to be a difference with the data we have. What about Oliver and Thomas?</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/stats/t.test.html'>t.test</a></span><span class='op'>(</span><span class='va'>normalized_mat</span><span class='op'>[</span><span class='st'>"Oliver"</span>,<span class='op'>]</span>, <span class='va'>normalized_mat</span><span class='op'>[</span><span class='st'>"Thomas"</span>,<span class='op'>]</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code> - Welch Two Sample t-test - -data: normalized_mat["Oliver", ] and normalized_mat["Thomas", ] -t = 9.3268, df = 21.544, p-value = 5.121e-09 -alternative hypothesis: true difference in means is not equal to 0 -95 percent confidence interval: - 0.01858464 0.02922945 -sample estimates: - mean of x mean of y -0.04133411 0.01742706 </code></pre> -</div> -<p>Here we can see that there is a difference between the mean values for Oliver and Thomas using a <code>t.test</code></p> -<h2 id="using-dataframes-and-matricies">Using dataframes and matricies</h2> -<p>For many of the <code>tidyverse</code> functions you’ve learned so far, a data frame is required. Fortunately, it is very easy to change between a data frame and a matrix.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>normalized_dat</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/data.frame.html'>data.frame</a></span><span class='op'>(</span><span class='va'>normalized_mat</span><span class='op'>)</span></span> -<span></span> -<span><span class='fu'><a href='https://rdrr.io/r/utils/str.html'>str</a></span><span class='op'>(</span><span class='va'>normalized_dat</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>'data.frame': 40 obs. of 20 variables: - $ Alabama : num 0.0644 0.0535 0.0469 0.0447 0.0427 ... - $ Alaska : num 0.0365 0.0345 0.0203 0.0426 0.0355 ... - $ Arizona : num 0.0236 0.0292 0.0132 0.0385 0.0539 ... - $ Arkansas : num 0.0443 0.0306 0.0274 0.0417 0.0403 ... - $ California : num 0.0247 0.0278 0.0151 0.0384 0.0636 ... - $ Colorado : num 0.0369 0.0364 0.0211 0.0317 0.0408 ... - $ Connecticut: num 0.0356 0.0359 0.0302 0.024 0.0503 ... - $ Delaware : num 0.0269 0.0322 0.0251 0.0403 0.0466 ... - $ Florida : num 0.0244 0.0278 0.018 0.0436 0.0608 ... - $ Georgia : num 0.0469 0.0369 0.0317 0.0446 0.0494 ... - $ Hawaii : num 0.0261 0.0297 0.0252 0.0342 0.0513 ... - $ Idaho : num 0.0412 0.0399 0.0173 0.0351 0.0308 ... - $ Illinois : num 0.0345 0.0334 0.023 0.0309 0.053 ... - $ Indiana : num 0.0333 0.0321 0.0164 0.0396 0.0391 ... - $ Iowa : num 0.0425 0.0296 0.0154 0.0299 0.0371 ... - $ Kansas : num 0.0342 0.0336 0.0226 0.0358 0.0372 ... - $ Kentucky : num 0.0448 0.0399 0.0268 0.0419 0.0379 ... - $ Louisiana : num 0.0367 0.0349 0.0367 0.0478 0.044 ... - $ Maine : num 0.0277 0.0248 0.016 0.0255 0.035 ... - $ Maryland : num 0.0328 0.0378 0.0213 0.0293 0.0533 ...</code></pre> -</div> -<p>Once we can move between matrices and data frames, we can start to tidy our data for plotting purposes. Let’s plot the distribution of name usage as a violin plot. Here we want the counts to be the y axis and the names to be the y axis.</p> -<p>The first thing we need to do is make our matrix into a data frame</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>names_dat</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/data.frame.html'>data.frame</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>)</span></span></code></pre> -</div> -</div> -<p>Next, we will want the names to be a column rather than the row names. We can do this using <code>$</code> or <code>tibble::rownames_to_column</code></p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>names_dat</span> <span class='op'><-</span> <span class='fu'><a href='https://tibble.tidyverse.org/reference/rownames.html'>rownames_to_column</a></span><span class='op'>(</span><span class='va'>names_dat</span>, <span class='st'>"name"</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>names_dat</span><span class='op'>[</span><span class='fl'>1</span><span class='op'>:</span><span class='fl'>3</span>,<span class='fl'>1</span><span class='op'>:</span><span class='fl'>3</span><span class='op'>]</span></span></code></pre> -</div> -<pre><code> name Alabama Alaska -1 William 366 36 -2 James 304 34 -3 John 267 20</code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='co'># To set using $</span></span> -<span><span class='co'># names_dat$name <- rownames(names_dat)</span></span></code></pre> -</div> -</div> -<p>Next, we need to <code>pivot_longer</code> from <code>tidyr</code>. We want to take everything but the names column</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>pivot_columns</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/colnames.html'>colnames</a></span><span class='op'>(</span><span class='va'>names_dat</span><span class='op'>)</span><span class='op'>[</span><span class='fu'><a href='https://rdrr.io/r/base/colnames.html'>colnames</a></span><span class='op'>(</span><span class='va'>names_dat</span><span class='op'>)</span> <span class='op'>!=</span> <span class='st'>"name"</span><span class='op'>]</span></span> -<span></span> -<span><span class='va'>names_dat</span> <span class='op'><-</span> <span class='fu'><a href='https://tidyr.tidyverse.org/reference/pivot_longer.html'>pivot_longer</a></span><span class='op'>(</span><span class='va'>names_dat</span>, cols <span class='op'>=</span> <span class='fu'><a href='https://tidyselect.r-lib.org/reference/all_of.html'>all_of</a></span><span class='op'>(</span><span class='va'>pivot_columns</span><span class='op'>)</span>,</span> -<span> names_to <span class='op'>=</span> <span class='st'>"state"</span>, values_to <span class='op'>=</span> <span class='st'>"count"</span><span class='op'>)</span></span></code></pre> -</div> -</div> -<p>Note, we can use the pipe <code>%>%</code> from <code>dplyr</code> to put all of this into one statement.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='co'># Here we will specify the columns to keep first</span></span> -<span><span class='va'>pivot_columns</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/colnames.html'>colnames</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>names_dat</span> <span class='op'><-</span> <span class='va'>names_mat</span> <span class='op'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%>%</a></span> </span> -<span> <span class='va'>data.frame</span> <span class='op'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%>%</a></span> </span> -<span> <span class='fu'><a href='https://tibble.tidyverse.org/reference/rownames.html'>rownames_to_column</a></span><span class='op'>(</span><span class='st'>"name"</span><span class='op'>)</span> <span class='op'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%>%</a></span> </span> -<span> <span class='fu'><a href='https://tidyr.tidyverse.org/reference/pivot_longer.html'>pivot_longer</a></span><span class='op'>(</span>cols <span class='op'>=</span> <span class='fu'><a href='https://tidyselect.r-lib.org/reference/all_of.html'>all_of</a></span><span class='op'>(</span><span class='va'>pivot_columns</span><span class='op'>)</span>, </span> -<span> names_to <span class='op'>=</span> <span class='st'>"state"</span>, values_to <span class='op'>=</span> <span class='st'>"count"</span><span class='op'>)</span></span></code></pre> -</div> -</div> -<p>With this new data frame, we can now plot the distribution of names</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='co'># I first set the theme</span></span> -<span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/theme_get.html'>theme_set</a></span><span class='op'>(</span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggtheme.html'>theme_classic</a></span><span class='op'>(</span>base_size <span class='op'>=</span> <span class='fl'>10</span><span class='op'>)</span><span class='op'>)</span></span> -<span></span> -<span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggplot.html'>ggplot</a></span><span class='op'>(</span><span class='va'>names_dat</span>, <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span><span class='op'>(</span>x <span class='op'>=</span> <span class='va'>name</span>, y <span class='op'>=</span> <span class='va'>count</span>,</span> -<span> fill <span class='op'>=</span> <span class='va'>name</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span> </span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_violin.html'>geom_violin</a></span><span class='op'>(</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/theme.html'>theme</a></span><span class='op'>(</span>axis.text.x <span class='op'>=</span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/element.html'>element_text</a></span><span class='op'>(</span>angle <span class='op'>=</span> <span class='fl'>90</span>,</span> -<span> vjust <span class='op'>=</span> <span class='fl'>0.5</span>, hjust<span class='op'>=</span><span class='fl'>1</span><span class='op'>)</span><span class='op'>)</span> <span class='co'># rotate x axis</span></span></code></pre> -</div> -<p><img src="class7_matricies_files/figure-html5/unnamed-chunk-63-1.png" width="624" /></p> -</div> -<p>There are a few outliers here, almost certainly California. As we discussed above, normalizing the data helps put everything onto the same scale.</p> -<p><strong>Exercise</strong> -Can you make the same plot as above but use our normalized values?</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='co'># TODO make plot above with normalized values</span></span> -<span><span class='co'># Hint start with normalized_dat</span></span></code></pre> -</div> -</div> -<h2 id="im-a-biologist-why-should-i-care">I’m a biologist, why should I care?</h2> -<ul> -<li>Many of your datasets can be analyzed using matrices -<ul> -<li>If you analyze RNA-seq data, all of the processing and differential testing will be done in a matrix through <code>DESeq2</code></li> -<li>If you analyze protein data, that is best done in a matrix</li> -<li>Single cell RNA-seq data is analyzed using matrices, especially sparse matrices</li> -<li>Even just many measurements can be analyzed using a matrix</li> -</ul></li> -<li>Matrices are efficient object types for most types of analysis you would want to do</li> -</ul> -<h2 id="acknowldgements-and-additional-references">Acknowldgements and additional references</h2> -<p>The content of this class borrows heavily from previous tutorials:</p> -<ul> -<li>Matrices -<ul> -<li><a href="https://bookdown.org/manishpatwal/bookdown-demo/matrices-in-r.html">R example</a></li> -<li><a href="https://monashbioinformaticsplatform.github.io/r-intro/matrices.html">Quick tips</a></li> -</ul></li> -</ul> -<div class="sourceCode" id="cb72"><pre class="sourceCode r distill-force-highlighting-css"><code class="sourceCode r"></code></pre></div> -<!--radix_placeholder_article_footer--> -<!--/radix_placeholder_article_footer--> -</div> - -<div class="d-appendix"> -</div> - - -<!--radix_placeholder_site_after_body--> -<!--/radix_placeholder_site_after_body--> -<!--radix_placeholder_appendices--> -<div class="appendix-bottom"></div> -<!--/radix_placeholder_appendices--> -<!--radix_placeholder_navigation_after_body--> -<!--/radix_placeholder_navigation_after_body--> - -</body> - -</html> diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering.html b/_posts/2022-11-15-class-8-clustering/class-8-clustering.html deleted file mode 100644 index c43ae65..0000000 --- a/_posts/2022-11-15-class-8-clustering/class-8-clustering.html +++ /dev/null @@ -1,2221 +0,0 @@ -<!DOCTYPE html> - -<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang=""> - -<head> - <meta charset="utf-8"/> - <meta name="viewport" content="width=device-width, initial-scale=1"/> - <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"/> - <meta name="generator" content="distill" /> - - <style type="text/css"> - /* Hide doc at startup (prevent jankiness while JS renders/transforms) */ - body { - visibility: hidden; - } - </style> - - <!--radix_placeholder_import_source--> - <!--/radix_placeholder_import_source--> - -<style type="text/css">code{white-space: pre;}</style> -<style type="text/css" data-origin="pandoc"> -pre > code.sourceCode { white-space: pre; position: relative; } -pre > code.sourceCode > span { display: inline-block; line-height: 1.25; } -pre > code.sourceCode > span:empty { height: 1.2em; } -.sourceCode { overflow: visible; } -code.sourceCode > span { color: inherit; text-decoration: inherit; } -div.sourceCode { margin: 1em 0; } -pre.sourceCode { margin: 0; } -@media screen { -div.sourceCode { overflow: auto; } -} -@media print { -pre > code.sourceCode { white-space: pre-wrap; } -pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; } -} -pre.numberSource code - { counter-reset: source-line 0; } -pre.numberSource code > span - { position: relative; left: -4em; counter-increment: source-line; } -pre.numberSource code > span > a:first-child::before - { content: counter(source-line); - position: relative; left: -1em; text-align: right; vertical-align: baseline; - border: none; display: inline-block; - -webkit-touch-callout: none; -webkit-user-select: none; - -khtml-user-select: none; -moz-user-select: none; - -ms-user-select: none; user-select: none; - padding: 0 4px; width: 4em; - color: #aaaaaa; - } -pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; } -div.sourceCode - { color: #00769e; background-color: #f1f3f5; } -@media screen { -pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; } -} -code span { color: #00769e; } /* Normal */ -code span.al { color: #ad0000; } /* Alert */ -code span.an { color: #5e5e5e; } /* Annotation */ -code span.at { color: #657422; } /* Attribute */ -code span.bn { color: #ad0000; } /* BaseN */ -code span.bu { } /* BuiltIn */ -code span.cf { color: #00769e; } /* ControlFlow */ -code span.ch { color: #20794d; } /* Char */ -code span.cn { color: #8f5902; } /* Constant */ -code span.co { color: #5e5e5e; } /* Comment */ -code span.cv { color: #5e5e5e; font-style: italic; } /* CommentVar */ -code span.do { color: #5e5e5e; font-style: italic; } /* Documentation */ -code span.dt { color: #ad0000; } /* DataType */ -code span.dv { color: #ad0000; } /* DecVal */ -code span.er { color: #ad0000; } /* Error */ -code span.ex { } /* Extension */ -code span.fl { color: #ad0000; } /* Float */ -code span.fu { color: #4758ab; } /* Function */ -code span.im { } /* Import */ -code span.in { color: #5e5e5e; } /* Information */ -code span.kw { color: #00769e; } /* Keyword */ -code span.op { color: #5e5e5e; } /* Operator */ -code span.ot { color: #00769e; } /* Other */ -code span.pp { color: #ad0000; } /* Preprocessor */ -code span.sc { color: #5e5e5e; } /* SpecialChar */ -code span.ss { color: #20794d; } /* SpecialString */ -code span.st { color: #20794d; } /* String */ -code span.va { color: #111111; } /* Variable */ -code span.vs { color: #20794d; } /* VerbatimString */ -code span.wa { color: #5e5e5e; font-style: italic; } /* Warning */ -</style> - - - <!--radix_placeholder_meta_tags--> - <title>Class 8: Introduction to clustering and PCA</title> - - - - <!-- https://schema.org/Article --> - <meta property="article:published" itemprop="datePublished" content="2022-12-08"/> - <meta property="article:created" itemprop="dateCreated" content="2022-12-08"/> - <meta name="article:author" content="Kristen Wells"/> - - <!-- https://developers.facebook.com/docs/sharing/webmasters#markup --> - <meta property="og:title" content="Class 8: Introduction to clustering and PCA"/> - <meta property="og:type" content="article"/> - <meta property="og:locale" content="en_US"/> - - <!-- https://dev.twitter.com/cards/types/summary --> - <meta property="twitter:card" content="summary"/> - <meta property="twitter:title" content="Class 8: Introduction to clustering and PCA"/> - - <!--/radix_placeholder_meta_tags--> - <!--radix_placeholder_rmarkdown_metadata--> - - <script type="text/json" id="radix-rmarkdown-metadata"> - {"type":"list","attributes":{"names":{"type":"character","attributes":{},"value":["title","author","output","draft","date"]}},"value":[{"type":"character","attributes":{},"value":["Class 8: Introduction to clustering and PCA"]},{"type":"list","attributes":{},"value":[{"type":"list","attributes":{"names":{"type":"character","attributes":{},"value":["name","url","affiliation","orcid_id"]}},"value":[{"type":"character","attributes":{},"value":["Kristen Wells"]},{"type":"character","attributes":{},"value":["https://github.com/kwells4"]},{"type":"character","attributes":{},"value":["RNA Bioscience Iniative, Barbara Davis Diabetes Center"]},{"type":"character","attributes":{},"value":["0000-0002-7466-8164"]}]}]},{"type":"list","attributes":{"names":{"type":"character","attributes":{},"value":["distill::distill_article"]}},"value":[{"type":"list","attributes":{"names":{"type":"character","attributes":{},"value":["self_contained","toc"]}},"value":[{"type":"logical","attributes":{},"value":[false]},{"type":"logical","attributes":{},"value":[true]}]}]},{"type":"logical","attributes":{},"value":[false]},{"type":"character","attributes":{},"value":["12-08-2022"]}]} - </script> - <!--/radix_placeholder_rmarkdown_metadata--> - - <script type="text/json" id="radix-resource-manifest"> - {"type":"character","attributes":{},"value":["class-8-clustering_files/anchor-4.2.2/anchor.min.js","class-8-clustering_files/bowser-1.9.3/bowser.min.js","class-8-clustering_files/distill-2.2.21/template.v2.js","class-8-clustering_files/figure-html5/unnamed-chunk-11-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-12-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-14-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-15-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-16-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-17-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-18-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-19-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-20-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-22-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-23-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-24-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-26-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-28-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-30-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-32-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-33-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-35-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-36-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-37-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-38-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-39-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-40-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-41-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-42-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-43-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-44-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-45-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-46-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-47-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-48-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-49-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-50-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-51-1.png","class-8-clustering_files/figure-html5/unnamed-chunk-6-1.png","class-8-clustering_files/header-attrs-2.14/header-attrs.js","class-8-clustering_files/jquery-3.6.0/jquery-3.6.0.js","class-8-clustering_files/jquery-3.6.0/jquery-3.6.0.min.js","class-8-clustering_files/jquery-3.6.0/jquery-3.6.0.min.map","class-8-clustering_files/popper-2.6.0/popper.min.js","class-8-clustering_files/tippy-6.2.7/tippy-bundle.umd.min.js","class-8-clustering_files/tippy-6.2.7/tippy-light-border.css","class-8-clustering_files/tippy-6.2.7/tippy.css","class-8-clustering_files/tippy-6.2.7/tippy.umd.min.js","class-8-clustering_files/webcomponents-2.0.0/webcomponents.js","img/clustering1.jpg","img/dendrogram.jpg","img/final_clustering.jpg","img/Hierarchical-clustering-3-1.jpg","img/unclustered.jpg"]} - </script> - <!--radix_placeholder_navigation_in_header--> - <!--/radix_placeholder_navigation_in_header--> - <!--radix_placeholder_distill--> - - <style type="text/css"> - - body { - background-color: white; - } - - .pandoc-table { - width: 100%; - } - - .pandoc-table>caption { - margin-bottom: 10px; - } - - .pandoc-table th:not([align]) { - text-align: left; - } - - .pagedtable-footer { - font-size: 15px; - } - - d-byline .byline { - grid-template-columns: 2fr 2fr; - } - - d-byline .byline h3 { - margin-block-start: 1.5em; - } - - d-byline .byline .authors-affiliations h3 { - margin-block-start: 0.5em; - } - - .authors-affiliations .orcid-id { - width: 16px; - height:16px; - margin-left: 4px; - margin-right: 4px; - vertical-align: middle; - padding-bottom: 2px; - } - - d-title .dt-tags { - margin-top: 1em; - grid-column: text; - } - - .dt-tags .dt-tag { - text-decoration: none; - display: inline-block; - color: rgba(0,0,0,0.6); - padding: 0em 0.4em; - margin-right: 0.5em; - margin-bottom: 0.4em; - font-size: 70%; - border: 1px solid rgba(0,0,0,0.2); - border-radius: 3px; - text-transform: uppercase; - font-weight: 500; - } - - d-article table.gt_table td, - d-article table.gt_table th { - border-bottom: none; - font-size: 100%; - } - - .html-widget { - margin-bottom: 2.0em; - } - - .l-screen-inset { - padding-right: 16px; - } - - .l-screen .caption { - margin-left: 10px; - } - - .shaded { - background: rgb(247, 247, 247); - padding-top: 20px; - padding-bottom: 20px; - border-top: 1px solid rgba(0, 0, 0, 0.1); - border-bottom: 1px solid rgba(0, 0, 0, 0.1); - } - - .shaded .html-widget { - margin-bottom: 0; - border: 1px solid rgba(0, 0, 0, 0.1); - } - - .shaded .shaded-content { - background: white; - } - - .text-output { - margin-top: 0; - line-height: 1.5em; - } - - .hidden { - display: none !important; - } - - d-article { - padding-top: 2.5rem; - padding-bottom: 30px; - } - - d-appendix { - padding-top: 30px; - } - - d-article>p>img { - width: 100%; - } - - d-article h2 { - margin: 1rem 0 1.5rem 0; - } - - d-article h3 { - margin-top: 1.5rem; - } - - d-article iframe { - border: 1px solid rgba(0, 0, 0, 0.1); - margin-bottom: 2.0em; - width: 100%; - } - - /* Tweak code blocks */ - - d-article div.sourceCode code, - d-article pre code { - font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; - } - - d-article pre, - d-article div.sourceCode, - d-article div.sourceCode pre { - overflow: auto; - } - - d-article div.sourceCode { - background-color: white; - } - - d-article div.sourceCode pre { - padding-left: 10px; - font-size: 12px; - border-left: 2px solid rgba(0,0,0,0.1); - } - - d-article pre { - font-size: 12px; - color: black; - background: none; - margin-top: 0; - text-align: left; - white-space: pre; - word-spacing: normal; - word-break: normal; - word-wrap: normal; - line-height: 1.5; - - -moz-tab-size: 4; - -o-tab-size: 4; - tab-size: 4; - - -webkit-hyphens: none; - -moz-hyphens: none; - -ms-hyphens: none; - hyphens: none; - } - - d-article pre a { - border-bottom: none; - } - - d-article pre a:hover { - border-bottom: none; - text-decoration: underline; - } - - d-article details { - grid-column: text; - margin-bottom: 0.8em; - } - - @media(min-width: 768px) { - - d-article pre, - d-article div.sourceCode, - d-article div.sourceCode pre { - overflow: visible !important; - } - - d-article div.sourceCode pre { - padding-left: 18px; - font-size: 14px; - } - - d-article pre { - font-size: 14px; - } - - } - - figure img.external { - background: white; - border: 1px solid rgba(0, 0, 0, 0.1); - box-shadow: 0 1px 8px rgba(0, 0, 0, 0.1); - padding: 18px; - box-sizing: border-box; - } - - /* CSS for d-contents */ - - .d-contents { - grid-column: text; - color: rgba(0,0,0,0.8); - font-size: 0.9em; - padding-bottom: 1em; - margin-bottom: 1em; - padding-bottom: 0.5em; - margin-bottom: 1em; - padding-left: 0.25em; - justify-self: start; - } - - @media(min-width: 1000px) { - .d-contents.d-contents-float { - height: 0; - grid-column-start: 1; - grid-column-end: 4; - justify-self: center; - padding-right: 3em; - padding-left: 2em; - } - } - - .d-contents nav h3 { - font-size: 18px; - margin-top: 0; - margin-bottom: 1em; - } - - .d-contents li { - list-style-type: none - } - - .d-contents nav > ul { - padding-left: 0; - } - - .d-contents ul { - padding-left: 1em - } - - .d-contents nav ul li { - margin-top: 0.6em; - margin-bottom: 0.2em; - } - - .d-contents nav a { - font-size: 13px; - border-bottom: none; - text-decoration: none - color: rgba(0, 0, 0, 0.8); - } - - .d-contents nav a:hover { - text-decoration: underline solid rgba(0, 0, 0, 0.6) - } - - .d-contents nav > ul > li > a { - font-weight: 600; - } - - .d-contents nav > ul > li > ul { - font-weight: inherit; - } - - .d-contents nav > ul > li > ul > li { - margin-top: 0.2em; - } - - - .d-contents nav ul { - margin-top: 0; - margin-bottom: 0.25em; - } - - .d-article-with-toc h2:nth-child(2) { - margin-top: 0; - } - - - /* Figure */ - - .figure { - position: relative; - margin-bottom: 2.5em; - margin-top: 1.5em; - } - - .figure .caption { - color: rgba(0, 0, 0, 0.6); - font-size: 12px; - line-height: 1.5em; - } - - .figure img.external { - background: white; - border: 1px solid rgba(0, 0, 0, 0.1); - box-shadow: 0 1px 8px rgba(0, 0, 0, 0.1); - padding: 18px; - box-sizing: border-box; - } - - .figure .caption a { - color: rgba(0, 0, 0, 0.6); - } - - .figure .caption b, - .figure .caption strong, { - font-weight: 600; - color: rgba(0, 0, 0, 1.0); - } - - /* Citations */ - - d-article .citation { - color: inherit; - cursor: inherit; - } - - div.hanging-indent{ - margin-left: 1em; text-indent: -1em; - } - - /* Citation hover box */ - - .tippy-box[data-theme~=light-border] { - background-color: rgba(250, 250, 250, 0.95); - } - - .tippy-content > p { - margin-bottom: 0; - padding: 2px; - } - - - /* Tweak 1000px media break to show more text */ - - @media(min-width: 1000px) { - .base-grid, - distill-header, - d-title, - d-abstract, - d-article, - d-appendix, - distill-appendix, - d-byline, - d-footnote-list, - d-citation-list, - distill-footer { - grid-template-columns: [screen-start] 1fr [page-start kicker-start] 80px [middle-start] 50px [text-start kicker-end] 65px 65px 65px 65px 65px 65px 65px 65px [text-end gutter-start] 65px [middle-end] 65px [page-end gutter-end] 1fr [screen-end]; - grid-column-gap: 16px; - } - - .grid { - grid-column-gap: 16px; - } - - d-article { - font-size: 1.06rem; - line-height: 1.7em; - } - figure .caption, .figure .caption, figure figcaption { - font-size: 13px; - } - } - - @media(min-width: 1180px) { - .base-grid, - distill-header, - d-title, - d-abstract, - d-article, - d-appendix, - distill-appendix, - d-byline, - d-footnote-list, - d-citation-list, - distill-footer { - grid-template-columns: [screen-start] 1fr [page-start kicker-start] 60px [middle-start] 60px [text-start kicker-end] 60px 60px 60px 60px 60px 60px 60px 60px [text-end gutter-start] 60px [middle-end] 60px [page-end gutter-end] 1fr [screen-end]; - grid-column-gap: 32px; - } - - .grid { - grid-column-gap: 32px; - } - } - - - /* Get the citation styles for the appendix (not auto-injected on render since - we do our own rendering of the citation appendix) */ - - d-appendix .citation-appendix, - .d-appendix .citation-appendix { - font-size: 11px; - line-height: 15px; - border-left: 1px solid rgba(0, 0, 0, 0.1); - padding-left: 18px; - border: 1px solid rgba(0,0,0,0.1); - background: rgba(0, 0, 0, 0.02); - padding: 10px 18px; - border-radius: 3px; - color: rgba(150, 150, 150, 1); - overflow: hidden; - margin-top: -12px; - white-space: pre-wrap; - word-wrap: break-word; - } - - /* Include appendix styles here so they can be overridden */ - - d-appendix { - contain: layout style; - font-size: 0.8em; - line-height: 1.7em; - margin-top: 60px; - margin-bottom: 0; - border-top: 1px solid rgba(0, 0, 0, 0.1); - color: rgba(0,0,0,0.5); - padding-top: 60px; - padding-bottom: 48px; - } - - d-appendix h3 { - grid-column: page-start / text-start; - font-size: 15px; - font-weight: 500; - margin-top: 1em; - margin-bottom: 0; - color: rgba(0,0,0,0.65); - } - - d-appendix h3 + * { - margin-top: 1em; - } - - d-appendix ol { - padding: 0 0 0 15px; - } - - @media (min-width: 768px) { - d-appendix ol { - padding: 0 0 0 30px; - margin-left: -30px; - } - } - - d-appendix li { - margin-bottom: 1em; - } - - d-appendix a { - color: rgba(0, 0, 0, 0.6); - } - - d-appendix > * { - grid-column: text; - } - - d-appendix > d-footnote-list, - d-appendix > d-citation-list, - d-appendix > distill-appendix { - grid-column: screen; - } - - /* Include footnote styles here so they can be overridden */ - - d-footnote-list { - contain: layout style; - } - - d-footnote-list > * { - grid-column: text; - } - - d-footnote-list a.footnote-backlink { - color: rgba(0,0,0,0.3); - padding-left: 0.5em; - } - - - - /* Anchor.js */ - - .anchorjs-link { - /*transition: all .25s linear; */ - text-decoration: none; - border-bottom: none; - } - *:hover > .anchorjs-link { - margin-left: -1.125em !important; - text-decoration: none; - border-bottom: none; - } - - /* Social footer */ - - .social_footer { - margin-top: 30px; - margin-bottom: 0; - color: rgba(0,0,0,0.67); - } - - .disqus-comments { - margin-right: 30px; - } - - .disqus-comment-count { - border-bottom: 1px solid rgba(0, 0, 0, 0.4); - cursor: pointer; - } - - #disqus_thread { - margin-top: 30px; - } - - .article-sharing a { - border-bottom: none; - margin-right: 8px; - } - - .article-sharing a:hover { - border-bottom: none; - } - - .sidebar-section.subscribe { - font-size: 12px; - line-height: 1.6em; - } - - .subscribe p { - margin-bottom: 0.5em; - } - - - .article-footer .subscribe { - font-size: 15px; - margin-top: 45px; - } - - - .sidebar-section.custom { - font-size: 12px; - line-height: 1.6em; - } - - .custom p { - margin-bottom: 0.5em; - } - - /* Styles for listing layout (hide title) */ - .layout-listing d-title, .layout-listing .d-title { - display: none; - } - - /* Styles for posts lists (not auto-injected) */ - - - .posts-with-sidebar { - padding-left: 45px; - padding-right: 45px; - } - - .posts-list .description h2, - .posts-list .description p { - font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial, sans-serif; - } - - .posts-list .description h2 { - font-weight: 700; - border-bottom: none; - padding-bottom: 0; - } - - .posts-list h2.post-tag { - border-bottom: 1px solid rgba(0, 0, 0, 0.2); - padding-bottom: 12px; - } - .posts-list { - margin-top: 60px; - margin-bottom: 24px; - } - - .posts-list .post-preview { - text-decoration: none; - overflow: hidden; - display: block; - border-bottom: 1px solid rgba(0, 0, 0, 0.1); - padding: 24px 0; - } - - .post-preview-last { - border-bottom: none !important; - } - - .posts-list .posts-list-caption { - grid-column: screen; - font-weight: 400; - } - - .posts-list .post-preview h2 { - margin: 0 0 6px 0; - line-height: 1.2em; - font-style: normal; - font-size: 24px; - } - - .posts-list .post-preview p { - margin: 0 0 12px 0; - line-height: 1.4em; - font-size: 16px; - } - - .posts-list .post-preview .thumbnail { - box-sizing: border-box; - margin-bottom: 24px; - position: relative; - max-width: 500px; - } - .posts-list .post-preview img { - width: 100%; - display: block; - } - - .posts-list .metadata { - font-size: 12px; - line-height: 1.4em; - margin-bottom: 18px; - } - - .posts-list .metadata > * { - display: inline-block; - } - - .posts-list .metadata .publishedDate { - margin-right: 2em; - } - - .posts-list .metadata .dt-authors { - display: block; - margin-top: 0.3em; - margin-right: 2em; - } - - .posts-list .dt-tags { - display: block; - line-height: 1em; - } - - .posts-list .dt-tags .dt-tag { - display: inline-block; - color: rgba(0,0,0,0.6); - padding: 0.3em 0.4em; - margin-right: 0.2em; - margin-bottom: 0.4em; - font-size: 60%; - border: 1px solid rgba(0,0,0,0.2); - border-radius: 3px; - text-transform: uppercase; - font-weight: 500; - } - - .posts-list img { - opacity: 1; - } - - .posts-list img[data-src] { - opacity: 0; - } - - .posts-more { - clear: both; - } - - - .posts-sidebar { - font-size: 16px; - } - - .posts-sidebar h3 { - font-size: 16px; - margin-top: 0; - margin-bottom: 0.5em; - font-weight: 400; - text-transform: uppercase; - } - - .sidebar-section { - margin-bottom: 30px; - } - - .categories ul { - list-style-type: none; - margin: 0; - padding: 0; - } - - .categories li { - color: rgba(0, 0, 0, 0.8); - margin-bottom: 0; - } - - .categories li>a { - border-bottom: none; - } - - .categories li>a:hover { - border-bottom: 1px solid rgba(0, 0, 0, 0.4); - } - - .categories .active { - font-weight: 600; - } - - .categories .category-count { - color: rgba(0, 0, 0, 0.4); - } - - - @media(min-width: 768px) { - .posts-list .post-preview h2 { - font-size: 26px; - } - .posts-list .post-preview .thumbnail { - float: right; - width: 30%; - margin-bottom: 0; - } - .posts-list .post-preview .description { - float: left; - width: 45%; - } - .posts-list .post-preview .metadata { - float: left; - width: 20%; - margin-top: 8px; - } - .posts-list .post-preview p { - margin: 0 0 12px 0; - line-height: 1.5em; - font-size: 16px; - } - .posts-with-sidebar .posts-list { - float: left; - width: 75%; - } - .posts-with-sidebar .posts-sidebar { - float: right; - width: 20%; - margin-top: 60px; - padding-top: 24px; - padding-bottom: 24px; - } - } - - - /* Improve display for browsers without grid (IE/Edge <= 15) */ - - .downlevel { - line-height: 1.6em; - font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial, sans-serif; - margin: 0; - } - - .downlevel .d-title { - padding-top: 6rem; - padding-bottom: 1.5rem; - } - - .downlevel .d-title h1 { - font-size: 50px; - font-weight: 700; - line-height: 1.1em; - margin: 0 0 0.5rem; - } - - .downlevel .d-title p { - font-weight: 300; - font-size: 1.2rem; - line-height: 1.55em; - margin-top: 0; - } - - .downlevel .d-byline { - padding-top: 0.8em; - padding-bottom: 0.8em; - font-size: 0.8rem; - line-height: 1.8em; - } - - .downlevel .section-separator { - border: none; - border-top: 1px solid rgba(0, 0, 0, 0.1); - } - - .downlevel .d-article { - font-size: 1.06rem; - line-height: 1.7em; - padding-top: 1rem; - padding-bottom: 2rem; - } - - - .downlevel .d-appendix { - padding-left: 0; - padding-right: 0; - max-width: none; - font-size: 0.8em; - line-height: 1.7em; - margin-bottom: 0; - color: rgba(0,0,0,0.5); - padding-top: 40px; - padding-bottom: 48px; - } - - .downlevel .footnotes ol { - padding-left: 13px; - } - - .downlevel .base-grid, - .downlevel .distill-header, - .downlevel .d-title, - .downlevel .d-abstract, - .downlevel .d-article, - .downlevel .d-appendix, - .downlevel .distill-appendix, - .downlevel .d-byline, - .downlevel .d-footnote-list, - .downlevel .d-citation-list, - .downlevel .distill-footer, - .downlevel .appendix-bottom, - .downlevel .posts-container { - padding-left: 40px; - padding-right: 40px; - } - - @media(min-width: 768px) { - .downlevel .base-grid, - .downlevel .distill-header, - .downlevel .d-title, - .downlevel .d-abstract, - .downlevel .d-article, - .downlevel .d-appendix, - .downlevel .distill-appendix, - .downlevel .d-byline, - .downlevel .d-footnote-list, - .downlevel .d-citation-list, - .downlevel .distill-footer, - .downlevel .appendix-bottom, - .downlevel .posts-container { - padding-left: 150px; - padding-right: 150px; - max-width: 900px; - } - } - - .downlevel pre code { - display: block; - border-left: 2px solid rgba(0, 0, 0, .1); - padding: 0 0 0 20px; - font-size: 14px; - } - - .downlevel code, .downlevel pre { - color: black; - background: none; - font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; - text-align: left; - white-space: pre; - word-spacing: normal; - word-break: normal; - word-wrap: normal; - line-height: 1.5; - - -moz-tab-size: 4; - -o-tab-size: 4; - tab-size: 4; - - -webkit-hyphens: none; - -moz-hyphens: none; - -ms-hyphens: none; - hyphens: none; - } - - .downlevel .posts-list .post-preview { - color: inherit; - } - - - - </style> - - <script type="application/javascript"> - - function is_downlevel_browser() { - if (bowser.isUnsupportedBrowser({ msie: "12", msedge: "16"}, - window.navigator.userAgent)) { - return true; - } else { - return window.load_distill_framework === undefined; - } - } - - // show body when load is complete - function on_load_complete() { - - // add anchors - if (window.anchors) { - window.anchors.options.placement = 'left'; - window.anchors.add('d-article > h2, d-article > h3, d-article > h4, d-article > h5'); - } - - - // set body to visible - document.body.style.visibility = 'visible'; - - // force redraw for leaflet widgets - if (window.HTMLWidgets) { - var maps = window.HTMLWidgets.findAll(".leaflet"); - $.each(maps, function(i, el) { - var map = this.getMap(); - map.invalidateSize(); - map.eachLayer(function(layer) { - if (layer instanceof L.TileLayer) - layer.redraw(); - }); - }); - } - - // trigger 'shown' so htmlwidgets resize - $('d-article').trigger('shown'); - } - - function init_distill() { - - init_common(); - - // create front matter - var front_matter = $('<d-front-matter></d-front-matter>'); - $('#distill-front-matter').wrap(front_matter); - - // create d-title - $('.d-title').changeElementType('d-title'); - - // create d-byline - var byline = $('<d-byline></d-byline>'); - $('.d-byline').replaceWith(byline); - - // create d-article - var article = $('<d-article></d-article>'); - $('.d-article').wrap(article).children().unwrap(); - - // move posts container into article - $('.posts-container').appendTo($('d-article')); - - // create d-appendix - $('.d-appendix').changeElementType('d-appendix'); - - // flag indicating that we have appendix items - var appendix = $('.appendix-bottom').children('h3').length > 0; - - // replace footnotes with <d-footnote> - $('.footnote-ref').each(function(i, val) { - appendix = true; - var href = $(this).attr('href'); - var id = href.replace('#', ''); - var fn = $('#' + id); - var fn_p = $('#' + id + '>p'); - fn_p.find('.footnote-back').remove(); - var text = fn_p.html(); - var dtfn = $('<d-footnote></d-footnote>'); - dtfn.html(text); - $(this).replaceWith(dtfn); - }); - // remove footnotes - $('.footnotes').remove(); - - // move refs into #references-listing - $('#references-listing').replaceWith($('#refs')); - - $('h1.appendix, h2.appendix').each(function(i, val) { - $(this).changeElementType('h3'); - }); - $('h3.appendix').each(function(i, val) { - var id = $(this).attr('id'); - $('.d-contents a[href="#' + id + '"]').parent().remove(); - appendix = true; - $(this).nextUntil($('h1, h2, h3')).addBack().appendTo($('d-appendix')); - }); - - // show d-appendix if we have appendix content - $("d-appendix").css('display', appendix ? 'grid' : 'none'); - - // localize layout chunks to just output - $('.layout-chunk').each(function(i, val) { - - // capture layout - var layout = $(this).attr('data-layout'); - - // apply layout to markdown level block elements - var elements = $(this).children().not('details, div.sourceCode, pre, script'); - elements.each(function(i, el) { - var layout_div = $('<div class="' + layout + '"></div>'); - if (layout_div.hasClass('shaded')) { - var shaded_content = $('<div class="shaded-content"></div>'); - $(this).wrap(shaded_content); - $(this).parent().wrap(layout_div); - } else { - $(this).wrap(layout_div); - } - }); - - - // unwrap the layout-chunk div - $(this).children().unwrap(); - }); - - // remove code block used to force highlighting css - $('.distill-force-highlighting-css').parent().remove(); - - // remove empty line numbers inserted by pandoc when using a - // custom syntax highlighting theme - $('code.sourceCode a:empty').remove(); - - // load distill framework - load_distill_framework(); - - // wait for window.distillRunlevel == 4 to do post processing - function distill_post_process() { - - if (!window.distillRunlevel || window.distillRunlevel < 4) - return; - - // hide author/affiliations entirely if we have no authors - var front_matter = JSON.parse($("#distill-front-matter").html()); - var have_authors = front_matter.authors && front_matter.authors.length > 0; - if (!have_authors) - $('d-byline').addClass('hidden'); - - // article with toc class - $('.d-contents').parent().addClass('d-article-with-toc'); - - // strip links that point to # - $('.authors-affiliations').find('a[href="#"]').removeAttr('href'); - - // add orcid ids - $('.authors-affiliations').find('.author').each(function(i, el) { - var orcid_id = front_matter.authors[i].orcidID; - if (orcid_id) { - var a = $('<a></a>'); - a.attr('href', 'https://orcid.org/' + orcid_id); - var img = $('<img></img>'); - img.addClass('orcid-id'); - img.attr('alt', 'ORCID ID'); - img.attr('src','data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2ZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo1N0NEMjA4MDI1MjA2ODExOTk0QzkzNTEzRjZEQTg1NyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDozM0NDOEJGNEZGNTcxMUUxODdBOEVCODg2RjdCQ0QwOSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDozM0NDOEJGM0ZGNTcxMUUxODdBOEVCODg2RjdCQ0QwOSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IE1hY2ludG9zaCI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkZDN0YxMTc0MDcyMDY4MTE5NUZFRDc5MUM2MUUwNEREIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjU3Q0QyMDgwMjUyMDY4MTE5OTRDOTM1MTNGNkRBODU3Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+84NovQAAAR1JREFUeNpiZEADy85ZJgCpeCB2QJM6AMQLo4yOL0AWZETSqACk1gOxAQN+cAGIA4EGPQBxmJA0nwdpjjQ8xqArmczw5tMHXAaALDgP1QMxAGqzAAPxQACqh4ER6uf5MBlkm0X4EGayMfMw/Pr7Bd2gRBZogMFBrv01hisv5jLsv9nLAPIOMnjy8RDDyYctyAbFM2EJbRQw+aAWw/LzVgx7b+cwCHKqMhjJFCBLOzAR6+lXX84xnHjYyqAo5IUizkRCwIENQQckGSDGY4TVgAPEaraQr2a4/24bSuoExcJCfAEJihXkWDj3ZAKy9EJGaEo8T0QSxkjSwORsCAuDQCD+QILmD1A9kECEZgxDaEZhICIzGcIyEyOl2RkgwAAhkmC+eAm0TAAAAABJRU5ErkJggg=='); - a.append(img); - $(this).append(a); - } - }); - - // hide elements of author/affiliations grid that have no value - function hide_byline_column(caption) { - $('d-byline').find('h3:contains("' + caption + '")').parent().css('visibility', 'hidden'); - } - - // affiliations - var have_affiliations = false; - for (var i = 0; i<front_matter.authors.length; ++i) { - var author = front_matter.authors[i]; - if (author.affiliation !== " ") { - have_affiliations = true; - break; - } - } - if (!have_affiliations) - $('d-byline').find('h3:contains("Affiliations")').css('visibility', 'hidden'); - - // published date - if (!front_matter.publishedDate) - hide_byline_column("Published"); - - // document object identifier - var doi = $('d-byline').find('h3:contains("DOI")'); - var doi_p = doi.next().empty(); - if (!front_matter.doi) { - // if we have a citation and valid citationText then link to that - if ($('#citation').length > 0 && front_matter.citationText) { - doi.html('Citation'); - $('<a href="#citation"></a>') - .text(front_matter.citationText) - .appendTo(doi_p); - } else { - hide_byline_column("DOI"); - } - } else { - $('<a></a>') - .attr('href', "https://doi.org/" + front_matter.doi) - .html(front_matter.doi) - .appendTo(doi_p); - } - - // change plural form of authors/affiliations - if (front_matter.authors.length === 1) { - var grid = $('.authors-affiliations'); - grid.children('h3:contains("Authors")').text('Author'); - grid.children('h3:contains("Affiliations")').text('Affiliation'); - } - - // remove d-appendix and d-footnote-list local styles - $('d-appendix > style:first-child').remove(); - $('d-footnote-list > style:first-child').remove(); - - // move appendix-bottom entries to the bottom - $('.appendix-bottom').appendTo('d-appendix').children().unwrap(); - $('.appendix-bottom').remove(); - - // hoverable references - $('span.citation[data-cites]').each(function() { - const citeChild = $(this).children()[0] - // Do not process if @xyz has been used without escaping and without bibliography activated - // https://github.com/rstudio/distill/issues/466 - if (citeChild === undefined) return true - - if (citeChild.nodeName == "D-FOOTNOTE") { - var fn = citeChild - $(this).html(fn.shadowRoot.querySelector("sup")) - $(this).id = fn.id - fn.remove() - } - var refs = $(this).attr('data-cites').split(" "); - var refHtml = refs.map(function(ref) { - // Could use CSS.escape too here, we insure backward compatibility in navigator - return "<p>" + $('div[id="ref-' + ref + '"]').html() + "</p>"; - }).join("\n"); - window.tippy(this, { - allowHTML: true, - content: refHtml, - maxWidth: 500, - interactive: true, - interactiveBorder: 10, - theme: 'light-border', - placement: 'bottom-start' - }); - }); - - // fix footnotes in tables (#411) - // replacing broken distill.pub feature - $('table d-footnote').each(function() { - // we replace internal showAtNode methode which is triggered when hovering a footnote - this.hoverBox.showAtNode = function(node) { - // ported from https://github.com/distillpub/template/pull/105/files - calcOffset = function(elem) { - let x = elem.offsetLeft; - let y = elem.offsetTop; - // Traverse upwards until an `absolute` element is found or `elem` - // becomes null. - while (elem = elem.offsetParent && elem.style.position != 'absolute') { - x += elem.offsetLeft; - y += elem.offsetTop; - } - - return { left: x, top: y }; - } - // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetTop - const bbox = node.getBoundingClientRect(); - const offset = calcOffset(node); - this.show([offset.left + bbox.width, offset.top + bbox.height]); - } - }) - - // clear polling timer - clearInterval(tid); - - // show body now that everything is ready - on_load_complete(); - } - - var tid = setInterval(distill_post_process, 50); - distill_post_process(); - - } - - function init_downlevel() { - - init_common(); - - // insert hr after d-title - $('.d-title').after($('<hr class="section-separator"/>')); - - // check if we have authors - var front_matter = JSON.parse($("#distill-front-matter").html()); - var have_authors = front_matter.authors && front_matter.authors.length > 0; - - // manage byline/border - if (!have_authors) - $('.d-byline').remove(); - $('.d-byline').after($('<hr class="section-separator"/>')); - $('.d-byline a').remove(); - - // remove toc - $('.d-contents').remove(); - - // move appendix elements - $('h1.appendix, h2.appendix').each(function(i, val) { - $(this).changeElementType('h3'); - }); - $('h3.appendix').each(function(i, val) { - $(this).nextUntil($('h1, h2, h3')).addBack().appendTo($('.d-appendix')); - }); - - - // inject headers into references and footnotes - var refs_header = $('<h3></h3>'); - refs_header.text('References'); - $('#refs').prepend(refs_header); - - var footnotes_header = $('<h3></h3'); - footnotes_header.text('Footnotes'); - $('.footnotes').children('hr').first().replaceWith(footnotes_header); - - // move appendix-bottom entries to the bottom - $('.appendix-bottom').appendTo('.d-appendix').children().unwrap(); - $('.appendix-bottom').remove(); - - // remove appendix if it's empty - if ($('.d-appendix').children().length === 0) - $('.d-appendix').remove(); - - // prepend separator above appendix - $('.d-appendix').before($('<hr class="section-separator" style="clear: both"/>')); - - // trim code - $('pre>code').each(function(i, val) { - $(this).html($.trim($(this).html())); - }); - - // move posts-container right before article - $('.posts-container').insertBefore($('.d-article')); - - $('body').addClass('downlevel'); - - on_load_complete(); - } - - - function init_common() { - - // jquery plugin to change element types - (function($) { - $.fn.changeElementType = function(newType) { - var attrs = {}; - - $.each(this[0].attributes, function(idx, attr) { - attrs[attr.nodeName] = attr.nodeValue; - }); - - this.replaceWith(function() { - return $("<" + newType + "/>", attrs).append($(this).contents()); - }); - }; - })(jQuery); - - // prevent underline for linked images - $('a > img').parent().css({'border-bottom' : 'none'}); - - // mark non-body figures created by knitr chunks as 100% width - $('.layout-chunk').each(function(i, val) { - var figures = $(this).find('img, .html-widget'); - // ignore leaflet img layers (#106) - figures = figures.filter(':not(img[class*="leaflet"])') - if ($(this).attr('data-layout') !== "l-body") { - figures.css('width', '100%'); - } else { - figures.css('max-width', '100%'); - figures.filter("[width]").each(function(i, val) { - var fig = $(this); - fig.css('width', fig.attr('width') + 'px'); - }); - - } - }); - - // auto-append index.html to post-preview links in file: protocol - // and in rstudio ide preview - $('.post-preview').each(function(i, val) { - if (window.location.protocol === "file:") - $(this).attr('href', $(this).attr('href') + "index.html"); - }); - - // get rid of index.html references in header - if (window.location.protocol !== "file:") { - $('.distill-site-header a[href]').each(function(i,val) { - $(this).attr('href', $(this).attr('href').replace(/^index[.]html/, "./")); - }); - } - - // add class to pandoc style tables - $('tr.header').parent('thead').parent('table').addClass('pandoc-table'); - $('.kable-table').children('table').addClass('pandoc-table'); - - // add figcaption style to table captions - $('caption').parent('table').addClass("figcaption"); - - // initialize posts list - if (window.init_posts_list) - window.init_posts_list(); - - // implmement disqus comment link - $('.disqus-comment-count').click(function() { - window.headroom_prevent_pin = true; - $('#disqus_thread').toggleClass('hidden'); - if (!$('#disqus_thread').hasClass('hidden')) { - var offset = $(this).offset(); - $(window).resize(); - $('html, body').animate({ - scrollTop: offset.top - 35 - }); - } - }); - } - - document.addEventListener('DOMContentLoaded', function() { - if (is_downlevel_browser()) - init_downlevel(); - else - window.addEventListener('WebComponentsReady', init_distill); - }); - - </script> - - <!--/radix_placeholder_distill--> - <script src="class-8-clustering_files/header-attrs-2.14/header-attrs.js"></script> - <script src="class-8-clustering_files/jquery-3.6.0/jquery-3.6.0.min.js"></script> - <script src="class-8-clustering_files/popper-2.6.0/popper.min.js"></script> - <link href="class-8-clustering_files/tippy-6.2.7/tippy.css" rel="stylesheet" /> - <link href="class-8-clustering_files/tippy-6.2.7/tippy-light-border.css" rel="stylesheet" /> - <script src="class-8-clustering_files/tippy-6.2.7/tippy.umd.min.js"></script> - <script src="class-8-clustering_files/anchor-4.2.2/anchor.min.js"></script> - <script src="class-8-clustering_files/bowser-1.9.3/bowser.min.js"></script> - <script src="class-8-clustering_files/webcomponents-2.0.0/webcomponents.js"></script> - <script src="class-8-clustering_files/distill-2.2.21/template.v2.js"></script> - <!--radix_placeholder_site_in_header--> - <!--/radix_placeholder_site_in_header--> - - -</head> - -<body> - -<!--radix_placeholder_front_matter--> - -<script id="distill-front-matter" type="text/json"> -{"title":"Class 8: Introduction to clustering and PCA","authors":[{"author":"Kristen Wells","authorURL":"https://github.com/kwells4","affiliation":"RNA Bioscience Iniative, Barbara Davis Diabetes Center","affiliationURL":"#","orcidID":"0000-0002-7466-8164"}],"publishedDate":"2022-12-08T00:00:00.000-07:00","citationText":"Wells, 2022"} -</script> - -<!--/radix_placeholder_front_matter--> -<!--radix_placeholder_navigation_before_body--> -<!--/radix_placeholder_navigation_before_body--> -<!--radix_placeholder_site_before_body--> -<!--/radix_placeholder_site_before_body--> - -<div class="d-title"> -<h1>Class 8: Introduction to clustering and PCA</h1> -<!--radix_placeholder_categories--> -<!--/radix_placeholder_categories--> - -</div> - -<div class="d-byline"> - Kristen Wells <a href="https://github.com/kwells4" class="uri">https://github.com/kwells4</a> (RNA Bioscience Iniative, Barbara Davis Diabetes Center) - -<br/>12-08-2022 -</div> - -<div class="d-article"> -<div class="d-contents d-contents-float"> -<nav class="l-text toc figcaption" id="TOC"> -<h3>Contents</h3> -<ul> -<li><a href="#goals-for-this-class" id="toc-goals-for-this-class">Goals for this class</a></li> -<li><a href="#load-packages" id="toc-load-packages">Load packages</a></li> -<li><a href="#download-files" id="toc-download-files">Download files</a></li> -<li><a href="#what-is-clustering" id="toc-what-is-clustering">What is clustering</a> -<ul> -<li><a href="#k---means-clustering" id="toc-k---means-clustering">K - means clustering</a></li> -<li><a href="#hierarchical-clustering" id="toc-hierarchical-clustering">Hierarchical clustering</a></li> -</ul></li> -<li><a href="#using-dimensionality-reduction-to-visualize-data" id="toc-using-dimensionality-reduction-to-visualize-data">Using dimensionality reduction to visualize data</a> -<ul> -<li><a href="#visualizing-the-data-with-pca" id="toc-visualizing-the-data-with-pca">Visualizing the data with PCA</a></li> -</ul></li> -<li><a href="#implementing-clustering-on-our-dataset" id="toc-implementing-clustering-on-our-dataset">Implementing clustering on our dataset</a> -<ul> -<li><a href="#k-means-clustering-of-names" id="toc-k-means-clustering-of-names">K means clustering of names</a></li> -<li><a href="#hierarchical-clustering-of-names" id="toc-hierarchical-clustering-of-names">Hierarchical clustering of names</a></li> -<li><a href="#repeating-by-clustering-states" id="toc-repeating-by-clustering-states">Repeating by clustering states</a></li> -<li><a href="#hierarchical-clustering-of-states" id="toc-hierarchical-clustering-of-states">Hierarchical clustering of states</a></li> -</ul></li> -<li><a href="#im-a-biologist-why-should-i-care" id="toc-im-a-biologist-why-should-i-care">I’m a biologist, why should I care?</a></li> -<li><a href="#acknowldgements-and-additional-references" id="toc-acknowldgements-and-additional-references">Acknowldgements and additional references</a></li> -</ul> -</nav> -</div> -<p><em>The Rmarkdown for this class is <a href="https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2022-11-15-class-8-clustering/class-8-clustering.Rmd">on github</a></em></p> -<h2 id="goals-for-this-class">Goals for this class</h2> -<ul> -<li>Learn about different types of clustering</li> -<li>Cluster data using these different approaches</li> -<li>Learn how to use dimensionality reduction to visualize complex data</li> -</ul> -<h2 id="load-packages">Load packages</h2> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='kw'><a href='https://rdrr.io/r/base/library.html'>library</a></span><span class='op'>(</span><span class='va'><a href='https://tidyverse.tidyverse.org'>tidyverse</a></span><span class='op'>)</span></span> -<span><span class='co'># install factoextra if needed</span></span> -<span><span class='co'># install.packages("factoextra")</span></span> -<span><span class='kw'><a href='https://rdrr.io/r/base/library.html'>library</a></span><span class='op'>(</span><span class='va'><a href='http://www.sthda.com/english/rpkgs/factoextra'>factoextra</a></span><span class='op'>)</span></span> -<span><span class='kw'><a href='https://rdrr.io/r/base/library.html'>library</a></span><span class='op'>(</span><span class='va'><a href='https://here.r-lib.org/'>here</a></span><span class='op'>)</span></span></code></pre> -</div> -</div> -<h2 id="download-files">Download files</h2> -<p>Before we get started, let’s download all of the files you will need for the next three classes.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='co'># conditionally download all of the files used in rmarkdown from github </span></span> -<span><span class='kw'><a href='https://rdrr.io/r/base/source.html'>source</a></span><span class='op'>(</span><span class='st'>"https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2022-11-10-class-7-matricies/download_files.R"</span><span class='op'>)</span></span></code></pre> -</div> -</div> -<h2 id="what-is-clustering">What is clustering</h2> -<p>Clustering is grouping together similar objects or elements. Clustering is a very important part of any type of data analysis.</p> -<ol type="1"> -<li>Clustering is important for grouping important data togeher - it is what powers those “for you” posts you get when clicking on news articles</li> -<li>Cluster is also important for biology, it helps us group samples together in RNA-seq or in any experiment where you can get many measurements for samples, cells together in single cell methods</li> -<li>It can also be used to group together states or districts that are likely to vote in similar ways</li> -</ol> -<p>Clustering is an unsupervised task - this means that it tries to group together items with no previous knowledge</p> -<h3 id="k---means-clustering">K - means clustering</h3> -<p>I’m loosely following the <a href="https://towardsdatascience.com/how-does-k-means-clustering-in-machine-learning-work-fdaaaf5acfa0">tutorial here</a> through this section. Click on the above link for a more in-depth discussion.</p> -<p>k-means clustering uses the distance between points as a measure of similarity. The basic idea is that we are adding k points to the data, called centroids that will try to center themselves in the middle of k clusters. This means that the value of k - set by the user, is a very important value to set.</p> -<p>Consider the dataset below</p> -<div class="layout-chunk" data-layout="l-body"> -<p><img src="https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2022-11-15-class-8-clustering/img/unclustered.jpg" /><!-- --></p> -</div> -<p>In the figure above you would probably say that there are 3 clear clusters. Let’s start by giving a k of 3.</p> -<p>First the centroids are placed randomly and the distance from each point to each centroid is calculated. Points are then assigned to the cluster that corresponds to the nearest centroid: if a point is closest to centroid 1, it is placed into cluster 1.</p> -<div class="layout-chunk" data-layout="l-body"> -<p><img src="https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2022-11-15-class-8-clustering/img/clustering1.jpg" /><!-- --></p> -</div> -<p>Next, the mean distance from all points belonging to a cluster to that cluser’s centroid is calculated.</p> -<p>Then, the “centroids” are moved to that mean value that was calculated and the process of assigning points and finding the mean value is repeated.</p> -<p>This is done until the distance between the centroid and the nearest points doesn’t change. All points that are closest to the centroid are placed in that cluster</p> -<div class="layout-chunk" data-layout="l-body"> -<p><img src="https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2022-11-15-class-8-clustering/img/final_clustering.jpg" /><!-- --></p> -</div> -<p>Let’s try clustering on our own example:</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/theme_get.html'>theme_set</a></span><span class='op'>(</span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggtheme.html'>theme_classic</a></span><span class='op'>(</span>base_size <span class='op'>=</span> <span class='fl'>10</span><span class='op'>)</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>test_data</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/data.frame.html'>data.frame</a></span><span class='op'>(</span><span class='st'>"x_val"</span> <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='fl'>1</span>, <span class='fl'>3</span>, <span class='fl'>10</span>, <span class='fl'>12</span>, <span class='fl'>11</span>,</span> -<span> <span class='fl'>13</span>, <span class='fl'>11</span>, <span class='fl'>3</span>, <span class='fl'>2</span>, <span class='fl'>15</span>,</span> -<span> <span class='fl'>9</span>, <span class='fl'>2</span>, <span class='fl'>13</span>, <span class='fl'>12</span>, <span class='fl'>11</span><span class='op'>)</span>,</span> -<span> <span class='st'>"y_val"</span> <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='fl'>10</span>, <span class='fl'>12</span>, <span class='fl'>3</span>, <span class='fl'>2</span>, <span class='fl'>10</span>,</span> -<span> <span class='fl'>3</span>, <span class='fl'>1</span>, <span class='fl'>10</span>, <span class='fl'>13</span>, <span class='fl'>2</span>,</span> -<span> <span class='fl'>1</span>, <span class='fl'>13</span>, <span class='fl'>12</span>, <span class='fl'>13</span>, <span class='fl'>11</span><span class='op'>)</span><span class='op'>)</span></span> -<span></span> -<span><span class='fu'><a href='https://rdrr.io/r/base/colnames.html'>rownames</a></span><span class='op'>(</span><span class='va'>test_data</span><span class='op'>)</span> <span class='op'><-</span> <span class='va'>letters</span><span class='op'>[</span><span class='fl'>1</span><span class='op'>:</span><span class='fu'><a href='https://rdrr.io/r/base/nrow.html'>nrow</a></span><span class='op'>(</span><span class='va'>test_data</span><span class='op'>)</span><span class='op'>]</span></span></code></pre> -</div> -</div> -<p>Let’s quickly plot it to get a feeling of what it looks like</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggplot.html'>ggplot</a></span><span class='op'>(</span><span class='va'>test_data</span>, <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span><span class='op'>(</span>x <span class='op'>=</span> <span class='va'>x_val</span>, y <span class='op'>=</span> <span class='va'>y_val</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'>ggplot2</span><span class='fu'>::</span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_point.html'>geom_point</a></span><span class='op'>(</span>size <span class='op'>=</span> <span class='fl'>2</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-8-clustering_files/figure-html5/unnamed-chunk-6-1.png" width="624" /></p> -</div> -<p>Here it looks like we have three clusters. Let’s try running the k means clustering algorithm. We will be using <code>kmeans</code>. The <code>centers</code> corresponds to the number of clusters we expect in the data. The <code>nstart</code> corresponds to the number of random starting points to try (like the randomly placed centroids above).</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/Random.html'>set.seed</a></span><span class='op'>(</span><span class='fl'>123</span><span class='op'>)</span></span> -<span><span class='va'>km.res</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/stats/kmeans.html'>kmeans</a></span><span class='op'>(</span><span class='va'>test_data</span>, centers <span class='op'>=</span> <span class='fl'>3</span>, nstart <span class='op'>=</span> <span class='fl'>25</span><span class='op'>)</span></span></code></pre> -</div> -</div> -<p>The return of this function is a list. To figure out the components returned we can use <code>names()</code></p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/names.html'>names</a></span><span class='op'>(</span><span class='va'>km.res</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>[1] "cluster" "centers" "totss" "withinss" -[5] "tot.withinss" "betweenss" "size" "iter" -[9] "ifault" </code></pre> -</div> -<p>The actually cluster information is in <code>km.res$cluster</code>, the position of the centroids is in <code>km.res$centers</code></p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>km.res</span><span class='op'>$</span><span class='va'>cluster</span></span></code></pre> -</div> -<pre><code>a b c d e f g h i j k l m n o -1 1 3 3 2 3 3 1 1 3 3 1 2 2 2 </code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>km.res</span><span class='op'>$</span><span class='va'>centers</span></span></code></pre> -</div> -<pre><code> x_val y_val -1 2.20000 11.6 -2 11.75000 11.5 -3 11.66667 2.0</code></pre> -</div> -<p>Let’s add our clustering information to our data frame</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>cluster_k3</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/cbind.html'>cbind</a></span><span class='op'>(</span><span class='va'>test_data</span>, <span class='st'>"cluster"</span> <span class='op'>=</span> <span class='va'>km.res</span><span class='op'>$</span><span class='va'>cluster</span><span class='op'>)</span></span></code></pre> -</div> -</div> -<p>And replot with the new clusters</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>cluster_k3</span><span class='op'>$</span><span class='va'>cluster</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/factor.html'>factor</a></span><span class='op'>(</span><span class='va'>cluster_k3</span><span class='op'>$</span><span class='va'>cluster</span><span class='op'>)</span></span> -<span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggplot.html'>ggplot</a></span><span class='op'>(</span><span class='va'>cluster_k3</span>, <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span><span class='op'>(</span>x <span class='op'>=</span> <span class='va'>x_val</span>, y <span class='op'>=</span> <span class='va'>y_val</span>, color <span class='op'>=</span> <span class='va'>cluster</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'>ggplot2</span><span class='fu'>::</span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_point.html'>geom_point</a></span><span class='op'>(</span>size <span class='op'>=</span> <span class='fl'>2</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-8-clustering_files/figure-html5/unnamed-chunk-11-1.png" width="624" /></p> -</div> -<p>This looks like it did a pretty good job! What if we repeat with different values for k?</p> -<ul> -<li>K = 2</li> -</ul> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/Random.html'>set.seed</a></span><span class='op'>(</span><span class='fl'>123</span><span class='op'>)</span></span> -<span><span class='va'>km.res2</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/stats/kmeans.html'>kmeans</a></span><span class='op'>(</span><span class='va'>test_data</span>, centers <span class='op'>=</span> <span class='fl'>2</span>, nstart <span class='op'>=</span> <span class='fl'>25</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>cluster_k2</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/cbind.html'>cbind</a></span><span class='op'>(</span><span class='va'>test_data</span>, <span class='st'>"cluster"</span> <span class='op'>=</span> <span class='va'>km.res2</span><span class='op'>$</span><span class='va'>cluster</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>cluster_k2</span><span class='op'>$</span><span class='va'>cluster</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/factor.html'>factor</a></span><span class='op'>(</span><span class='va'>cluster_k2</span><span class='op'>$</span><span class='va'>cluster</span><span class='op'>)</span></span> -<span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggplot.html'>ggplot</a></span><span class='op'>(</span><span class='va'>cluster_k2</span>, <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span><span class='op'>(</span>x <span class='op'>=</span> <span class='va'>x_val</span>, y <span class='op'>=</span> <span class='va'>y_val</span>, color <span class='op'>=</span> <span class='va'>cluster</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'>ggplot2</span><span class='fu'>::</span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_point.html'>geom_point</a></span><span class='op'>(</span>size <span class='op'>=</span> <span class='fl'>2</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-8-clustering_files/figure-html5/unnamed-chunk-12-1.png" width="624" /></p> -</div> -<p>Now two populations that appear visually different have been clumped together because we allowed for only 2 centroids.</p> -<p><strong>Exercise</strong> -Repeat the process above, but compute for 4 clusters</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='co'># TODO find k = 4 clusters</span></span></code></pre> -</div> -</div> -<p>Note, the <code>nstart</code> value and the set seed is very important. If we don’t set a seed and only do one start, we end up with very different results when running several times:</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>km.res</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/stats/kmeans.html'>kmeans</a></span><span class='op'>(</span><span class='va'>test_data</span>, centers <span class='op'>=</span> <span class='fl'>3</span>, nstart <span class='op'>=</span> <span class='fl'>1</span><span class='op'>)</span></span> -<span><span class='va'>cluster_k3</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/cbind.html'>cbind</a></span><span class='op'>(</span><span class='va'>test_data</span>, <span class='st'>"cluster"</span> <span class='op'>=</span> <span class='va'>km.res</span><span class='op'>$</span><span class='va'>cluster</span><span class='op'>)</span></span> -<span><span class='va'>cluster_k3</span><span class='op'>$</span><span class='va'>cluster</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/factor.html'>factor</a></span><span class='op'>(</span><span class='va'>cluster_k3</span><span class='op'>$</span><span class='va'>cluster</span><span class='op'>)</span></span> -<span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggplot.html'>ggplot</a></span><span class='op'>(</span><span class='va'>cluster_k3</span>, <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span><span class='op'>(</span>x <span class='op'>=</span> <span class='va'>x_val</span>, y <span class='op'>=</span> <span class='va'>y_val</span>, color <span class='op'>=</span> <span class='va'>cluster</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'>ggplot2</span><span class='fu'>::</span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_point.html'>geom_point</a></span><span class='op'>(</span>size <span class='op'>=</span> <span class='fl'>2</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-8-clustering_files/figure-html5/unnamed-chunk-14-1.png" width="624" /></p> -</div> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>km.res</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/stats/kmeans.html'>kmeans</a></span><span class='op'>(</span><span class='va'>test_data</span>, centers <span class='op'>=</span> <span class='fl'>3</span>, nstart <span class='op'>=</span> <span class='fl'>1</span><span class='op'>)</span></span> -<span><span class='va'>cluster_k3</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/cbind.html'>cbind</a></span><span class='op'>(</span><span class='va'>test_data</span>, <span class='st'>"cluster"</span> <span class='op'>=</span> <span class='va'>km.res</span><span class='op'>$</span><span class='va'>cluster</span><span class='op'>)</span></span> -<span><span class='va'>cluster_k3</span><span class='op'>$</span><span class='va'>cluster</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/factor.html'>factor</a></span><span class='op'>(</span><span class='va'>cluster_k3</span><span class='op'>$</span><span class='va'>cluster</span><span class='op'>)</span></span> -<span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggplot.html'>ggplot</a></span><span class='op'>(</span><span class='va'>cluster_k3</span>, <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span><span class='op'>(</span>x <span class='op'>=</span> <span class='va'>x_val</span>, y <span class='op'>=</span> <span class='va'>y_val</span>, color <span class='op'>=</span> <span class='va'>cluster</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'>ggplot2</span><span class='fu'>::</span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_point.html'>geom_point</a></span><span class='op'>(</span>size <span class='op'>=</span> <span class='fl'>2</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-8-clustering_files/figure-html5/unnamed-chunk-15-1.png" width="624" /></p> -</div> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>km.res</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/stats/kmeans.html'>kmeans</a></span><span class='op'>(</span><span class='va'>test_data</span>, centers <span class='op'>=</span> <span class='fl'>3</span>, nstart <span class='op'>=</span> <span class='fl'>1</span><span class='op'>)</span></span> -<span><span class='va'>cluster_k3</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/cbind.html'>cbind</a></span><span class='op'>(</span><span class='va'>test_data</span>, <span class='st'>"cluster"</span> <span class='op'>=</span> <span class='va'>km.res</span><span class='op'>$</span><span class='va'>cluster</span><span class='op'>)</span></span> -<span><span class='va'>cluster_k3</span><span class='op'>$</span><span class='va'>cluster</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/factor.html'>factor</a></span><span class='op'>(</span><span class='va'>cluster_k3</span><span class='op'>$</span><span class='va'>cluster</span><span class='op'>)</span></span> -<span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggplot.html'>ggplot</a></span><span class='op'>(</span><span class='va'>cluster_k3</span>, <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span><span class='op'>(</span>x <span class='op'>=</span> <span class='va'>x_val</span>, y <span class='op'>=</span> <span class='va'>y_val</span>, color <span class='op'>=</span> <span class='va'>cluster</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'>ggplot2</span><span class='fu'>::</span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_point.html'>geom_point</a></span><span class='op'>(</span>size <span class='op'>=</span> <span class='fl'>2</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-8-clustering_files/figure-html5/unnamed-chunk-16-1.png" width="624" /></p> -</div> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>km.res</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/stats/kmeans.html'>kmeans</a></span><span class='op'>(</span><span class='va'>test_data</span>, centers <span class='op'>=</span> <span class='fl'>3</span>, nstart <span class='op'>=</span> <span class='fl'>1</span><span class='op'>)</span></span> -<span><span class='va'>cluster_k3</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/cbind.html'>cbind</a></span><span class='op'>(</span><span class='va'>test_data</span>, <span class='st'>"cluster"</span> <span class='op'>=</span> <span class='va'>km.res</span><span class='op'>$</span><span class='va'>cluster</span><span class='op'>)</span></span> -<span><span class='va'>cluster_k3</span><span class='op'>$</span><span class='va'>cluster</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/factor.html'>factor</a></span><span class='op'>(</span><span class='va'>cluster_k3</span><span class='op'>$</span><span class='va'>cluster</span><span class='op'>)</span></span> -<span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggplot.html'>ggplot</a></span><span class='op'>(</span><span class='va'>cluster_k3</span>, <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span><span class='op'>(</span>x <span class='op'>=</span> <span class='va'>x_val</span>, y <span class='op'>=</span> <span class='va'>y_val</span>, color <span class='op'>=</span> <span class='va'>cluster</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'>ggplot2</span><span class='fu'>::</span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_point.html'>geom_point</a></span><span class='op'>(</span>size <span class='op'>=</span> <span class='fl'>2</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-8-clustering_files/figure-html5/unnamed-chunk-17-1.png" width="624" /></p> -</div> -<h3 id="hierarchical-clustering">Hierarchical clustering</h3> -<p>Another option for clustering is using hierarchical clustering. This is another popular method and results in a dendrogram which you’ve likely seen before.</p> -<p>I’m loosely following the <a href="https://www.displayr.com/what-is-hierarchical-clustering/">tutorial here</a> through this section. Click on the above link for a more in-depth discussion.</p> -<p>Basically, hierarchical clustering starts by treating each sample as a “cluster”. It then does the following steps</p> -<ol type="1"> -<li>Identify the two clusters that are closest together</li> -<li>Merge these two clusters to form a new cluster</li> -</ol> -<p>Steps 1 and two are repeated until only one large cluster remains</p> -<div class="layout-chunk" data-layout="l-body"> -<p><img src="https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2022-11-15-class-8-clustering/img/Hierarchical-clustering-3-1.jpg" /><!-- --></p> -</div> -<p>Each merging step is used to build a dendrogram</p> -<div class="layout-chunk" data-layout="l-body"> -<p><img src="https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2022-11-15-class-8-clustering/img/dendrogram.jpg" /><!-- --></p> -</div> -<p>To get an idea of how this is working, we can use the same toy data we generated above</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>test_data</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/data.frame.html'>data.frame</a></span><span class='op'>(</span><span class='st'>"x_val"</span> <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='fl'>1</span>, <span class='fl'>3</span>, <span class='fl'>10</span>, <span class='fl'>12</span>, <span class='fl'>11</span>,</span> -<span> <span class='fl'>13</span>, <span class='fl'>11</span>, <span class='fl'>3</span>, <span class='fl'>2</span>, <span class='fl'>15</span>,</span> -<span> <span class='fl'>9</span>, <span class='fl'>2</span>, <span class='fl'>13</span>, <span class='fl'>12</span>, <span class='fl'>11</span><span class='op'>)</span>,</span> -<span> <span class='st'>"y_val"</span> <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='fl'>10</span>, <span class='fl'>12</span>, <span class='fl'>3</span>, <span class='fl'>2</span>, <span class='fl'>10</span>,</span> -<span> <span class='fl'>3</span>, <span class='fl'>1</span>, <span class='fl'>10</span>, <span class='fl'>13</span>, <span class='fl'>2</span>,</span> -<span> <span class='fl'>1</span>, <span class='fl'>13</span>, <span class='fl'>12</span>, <span class='fl'>13</span>, <span class='fl'>11</span><span class='op'>)</span><span class='op'>)</span></span> -<span></span> -<span><span class='fu'><a href='https://rdrr.io/r/base/colnames.html'>rownames</a></span><span class='op'>(</span><span class='va'>test_data</span><span class='op'>)</span> <span class='op'><-</span> <span class='va'>letters</span><span class='op'>[</span><span class='fl'>1</span><span class='op'>:</span><span class='fu'><a href='https://rdrr.io/r/base/nrow.html'>nrow</a></span><span class='op'>(</span><span class='va'>test_data</span><span class='op'>)</span><span class='op'>]</span></span> -<span></span> -<span><span class='va'>test_data</span> <span class='op'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%>%</a></span></span> -<span> <span class='fu'>dplyr</span><span class='fu'>::</span><span class='fu'><a href='https://dplyr.tidyverse.org/reference/mutate.html'>mutate</a></span><span class='op'>(</span>sample <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/colnames.html'>rownames</a></span><span class='op'>(</span><span class='va'>.</span><span class='op'>)</span><span class='op'>)</span> <span class='op'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%>%</a></span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggplot.html'>ggplot</a></span><span class='op'>(</span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span><span class='op'>(</span>x <span class='op'>=</span> <span class='va'>x_val</span>, y <span class='op'>=</span> <span class='va'>y_val</span>, label <span class='op'>=</span> <span class='va'>sample</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_point.html'>geom_point</a></span><span class='op'>(</span>size <span class='op'>=</span> <span class='fl'>2</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_text.html'>geom_text</a></span><span class='op'>(</span>hjust<span class='op'>=</span><span class='fl'>2</span>, vjust<span class='op'>=</span><span class='fl'>0</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-8-clustering_files/figure-html5/unnamed-chunk-20-1.png" width="624" /></p> -</div> -<p>First, we should find the distances between the points. Below is the eucledian distances. Notice that the distance is computed for the rows. If we wanted to compute distances for the columns we would need to transform the matrix using <code>t()</code></p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/stats/dist.html'>dist</a></span><span class='op'>(</span><span class='va'>test_data</span><span class='op'>[</span><span class='fl'>1</span><span class='op'>:</span><span class='fl'>5</span>,<span class='op'>]</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code> a b c d -b 2.828427 -c 11.401754 11.401754 -d 13.601471 13.453624 2.236068 -e 10.000000 8.246211 7.071068 8.062258</code></pre> -</div> -<p>We can now run <code>hclust</code> which will perform hierarchical clustering using the output of <code>dist</code></p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>hc</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/stats/hclust.html'>hclust</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/stats/dist.html'>dist</a></span><span class='op'>(</span><span class='va'>test_data</span><span class='op'>)</span><span class='op'>)</span></span> -<span></span> -<span><span class='fu'><a href='https://rdrr.io/r/graphics/plot.default.html'>plot</a></span><span class='op'>(</span><span class='va'>hc</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-8-clustering_files/figure-html5/unnamed-chunk-22-1.png" width="624" /></p> -</div> -<p>Based on the dendrogram above, we can see what points are the most similar (ie were clustered first). We can also see that it makes the most sense to break the data into 3 clusters. We can pull out these clusters using <code>cutree</code></p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>hc_clusters3</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/stats/cutree.html'>cutree</a></span><span class='op'>(</span>tree <span class='op'>=</span> <span class='va'>hc</span>, k <span class='op'>=</span><span class='fl'>3</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>hc_clusters3</span></span></code></pre> -</div> -<pre><code>a b c d e f g h i j k l m n o -1 1 2 2 3 2 2 1 1 2 2 1 3 3 3 </code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>hc_clusters3</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/cbind.html'>cbind</a></span><span class='op'>(</span><span class='va'>test_data</span>, <span class='st'>"cluster"</span> <span class='op'>=</span> <span class='va'>hc_clusters3</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>hc_clusters3</span><span class='op'>$</span><span class='va'>cluster</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/factor.html'>factor</a></span><span class='op'>(</span><span class='va'>hc_clusters3</span><span class='op'>$</span><span class='va'>cluster</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>hc_clusters3</span> <span class='op'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%>%</a></span></span> -<span> <span class='fu'>dplyr</span><span class='fu'>::</span><span class='fu'><a href='https://dplyr.tidyverse.org/reference/mutate.html'>mutate</a></span><span class='op'>(</span>sample <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/colnames.html'>rownames</a></span><span class='op'>(</span><span class='va'>.</span><span class='op'>)</span><span class='op'>)</span> <span class='op'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%>%</a></span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggplot.html'>ggplot</a></span><span class='op'>(</span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span><span class='op'>(</span>x <span class='op'>=</span> <span class='va'>x_val</span>, y <span class='op'>=</span> <span class='va'>y_val</span>, label <span class='op'>=</span> <span class='va'>sample</span>, color <span class='op'>=</span> <span class='va'>cluster</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_point.html'>geom_point</a></span><span class='op'>(</span>size <span class='op'>=</span> <span class='fl'>2</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_text.html'>geom_text</a></span><span class='op'>(</span>hjust<span class='op'>=</span><span class='fl'>2</span>, vjust<span class='op'>=</span><span class='fl'>0</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-8-clustering_files/figure-html5/unnamed-chunk-23-1.png" width="624" /></p> -</div> -<p>And now you can see that the clusters agree exactly with the k - means clusters</p> -<p><strong>Exercise</strong> -Repeat finding clusters using different points on the tree. For example, what if you make 2 clusters? What if you make 4 or 5?</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='co'># TODO repeat finding clusters with different numbers of clusters</span></span></code></pre> -</div> -</div> -<p><strong>Question</strong> -Are the clusters always the same as the k-means clusters? Do they ever differ?</p> -<h2 id="using-dimensionality-reduction-to-visualize-data">Using dimensionality reduction to visualize data</h2> -<p>In the example above, we only had two dimensions and could easily visualize them. What about our example dataset with 50 names and 20 states? How do we visualize that type of data? Even more daunting,what if we have 20,000 genes and 18 samples as part of a RNA-seq experiment, or even worse, 20,000 genes and 30,000 cells as part of a single cell RNA-seq experiment? To visualize this data, we have to use something called dimensionality reduction. PCA is a common dimensionality reduction to use and will work well for lots of data type (like bulk RNA-seq). Other dimensionality reduction tools will need to be used (like UMAP) to visualize single cell RNA-seq and CYTOF datasets (and other single cell approaches).</p> -<h3 id="visualizing-the-data-with-pca">Visualizing the data with PCA</h3> -<p>There is an amazing tutorial on how PCA works <a href="https://web.stanford.edu/class/bios221/book/07-chap.html">here</a>. We will talk a little today about how PCA works, but I highly recommend looking at this book for PCA and to learn many of the important statistical techniques used regularly in computational biology. One thing I like about the book is it includes a lot of R code that you can run yourself so you can really understand how these techniques work.</p> -<p>The overall goal of PCA is to find linear models that best fit the data.</p> -<p>Let’s walk through PCA (following the tutorial in Modern Statistics for Modern Biology) with only Alabama and Colorado to see how it works.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>names_mat</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/utils/read.table.html'>read.csv</a></span><span class='op'>(</span><span class='fu'><a href='https://here.r-lib.org//reference/here.html'>here</a></span><span class='op'>(</span><span class='st'>"class_7-9_data"</span>, <span class='st'>"boy_name_counts.csv"</span><span class='op'>)</span>,</span> -<span> row.names <span class='op'>=</span> <span class='fl'>1</span><span class='op'>)</span> <span class='op'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%>%</a></span></span> -<span> <span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>as.matrix</a></span><span class='op'>(</span><span class='op'>)</span></span> -<span></span> -<span></span> -<span><span class='va'>normalized_mat</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/t.html'>t</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/t.html'>t</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>)</span> <span class='op'>/</span> <span class='fu'><a href='https://rdrr.io/r/base/colSums.html'>colSums</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>)</span><span class='op'>)</span></span> -<span></span> -<span><span class='co'># Selecting just Alabama and Colorado, making a data frame for plotting</span></span> -<span><span class='va'>normalized_dat</span> <span class='op'><-</span> <span class='va'>normalized_mat</span> <span class='op'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%>%</a></span></span> -<span> <span class='va'>data.frame</span> <span class='op'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%>%</a></span></span> -<span> <span class='fu'>dplyr</span><span class='fu'>::</span><span class='fu'><a href='https://dplyr.tidyverse.org/reference/select.html'>select</a></span><span class='op'>(</span><span class='va'>Alabama</span>, <span class='va'>Colorado</span><span class='op'>)</span></span></code></pre> -</div> -</div> -<p>The first way we can think about going from 2 dimensions to 1 dimension is to simply just use the values from one of the dimensions. For example, if we have Alabama and Colorado, we can simply describe the data using only the values for Alabama. This idea is shown as the red points below</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>dim_plot</span> <span class='op'><-</span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggplot.html'>ggplot</a></span><span class='op'>(</span><span class='va'>normalized_dat</span>, <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span><span class='op'>(</span>x <span class='op'>=</span> <span class='va'>Alabama</span>, y <span class='op'>=</span> <span class='va'>Colorado</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_point.html'>geom_point</a></span><span class='op'>(</span>size <span class='op'>=</span> <span class='fl'>2</span><span class='op'>)</span></span> -<span><span class='va'>dim_plot</span> <span class='op'>+</span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_point.html'>geom_point</a></span><span class='op'>(</span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span><span class='op'>(</span>y <span class='op'>=</span> <span class='fl'>0</span><span class='op'>)</span>, colour <span class='op'>=</span> <span class='st'>"red"</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_segment.html'>geom_segment</a></span><span class='op'>(</span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span><span class='op'>(</span>xend <span class='op'>=</span> <span class='va'>Alabama</span>, yend <span class='op'>=</span> <span class='fl'>0</span><span class='op'>)</span>, linetype <span class='op'>=</span> <span class='st'>"dashed"</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-8-clustering_files/figure-html5/unnamed-chunk-26-1.png" width="624" /></p> -</div> -<p>Unfortunately, this loses all of the information from Colorado. Instead, we can also try to find a line of best fit using linear regression. Linear regression is done using a model with response and explanatory variables. A line is fit to the data that attempts to minimize the distance from the response variables to the line. Because there is always a response and explanatory variable, we can perform linear regression to minimize the distance for Colorado or Alabama.</p> -<p>Let’s first minimize the distance for Colorado. To perform linear regression, we will use the <code>lm</code> function. If we want to minimize the distance to Colorado, Colorado will be the response variable and our model will be <code>Colorado ~ Alabama</code></p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>reg1</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/stats/lm.html'>lm</a></span><span class='op'>(</span><span class='va'>Colorado</span> <span class='op'>~</span> <span class='va'>Alabama</span>, data <span class='op'>=</span> <span class='va'>normalized_dat</span><span class='op'>)</span></span> -<span><span class='fu'><a href='https://rdrr.io/r/base/names.html'>names</a></span><span class='op'>(</span><span class='va'>reg1</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code> [1] "coefficients" "residuals" "effects" "rank" - [5] "fitted.values" "assign" "qr" "df.residual" - [9] "xlevels" "call" "terms" "model" </code></pre> -</div> -<p>After running <code>lm</code> the return value is a list. The <code>coefficients</code> will give us the slope and the intercept (think <span class="math inline">\(y = ax + b\)</span> ). We can also use the <code>fitted.values</code> which are the predicted values for Colorado based on the model.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>a1</span> <span class='op'><-</span> <span class='va'>reg1</span><span class='op'>$</span><span class='va'>coefficients</span><span class='op'>[</span><span class='fl'>1</span><span class='op'>]</span> <span class='co'># intercept</span></span> -<span><span class='va'>b1</span> <span class='op'><-</span> <span class='va'>reg1</span><span class='op'>$</span><span class='va'>coefficients</span><span class='op'>[</span><span class='fl'>2</span><span class='op'>]</span> <span class='co'># slope</span></span> -<span><span class='va'>pline1</span> <span class='op'><-</span> <span class='va'>dim_plot</span> <span class='op'>+</span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_abline.html'>geom_abline</a></span><span class='op'>(</span>intercept <span class='op'>=</span> <span class='va'>a1</span>, slope <span class='op'>=</span> <span class='va'>b1</span>,</span> -<span> col <span class='op'>=</span> <span class='st'>"blue"</span><span class='op'>)</span></span> -<span><span class='va'>pline1</span> <span class='op'>+</span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_segment.html'>geom_segment</a></span><span class='op'>(</span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span><span class='op'>(</span>xend <span class='op'>=</span> <span class='va'>Alabama</span>, yend <span class='op'>=</span> <span class='va'>reg1</span><span class='op'>$</span><span class='va'>fitted.values</span><span class='op'>)</span>,</span> -<span> colour <span class='op'>=</span> <span class='st'>"red"</span>, arrow <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/grid/arrow.html'>arrow</a></span><span class='op'>(</span>length <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/grid/unit.html'>unit</a></span><span class='op'>(</span><span class='fl'>0.15</span>, <span class='st'>"cm"</span><span class='op'>)</span><span class='op'>)</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-8-clustering_files/figure-html5/unnamed-chunk-28-1.png" width="624" /></p> -</div> -<p>We can find the variance of the points on the blue line by using Pythagoras’ theorem (because the values have x and y coordinates).</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/stats/cor.html'>var</a></span><span class='op'>(</span><span class='va'>normalized_dat</span><span class='op'>$</span><span class='va'>Alabama</span><span class='op'>)</span> <span class='op'>+</span> <span class='fu'><a href='https://rdrr.io/r/stats/cor.html'>var</a></span><span class='op'>(</span><span class='va'>reg1</span><span class='op'>$</span><span class='va'>fitted.values</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>[1] 0.0001614616</code></pre> -</div> -<p>We can now repeat linear regression and now minimize the distance for Alabama to the regression line (now Alabama is the response variable).</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>reg2</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/stats/lm.html'>lm</a></span><span class='op'>(</span><span class='va'>Alabama</span> <span class='op'>~</span> <span class='va'>Colorado</span>, data <span class='op'>=</span> <span class='va'>normalized_dat</span><span class='op'>)</span></span> -<span><span class='va'>a2</span> <span class='op'><-</span> <span class='va'>reg2</span><span class='op'>$</span><span class='va'>coefficients</span><span class='op'>[</span><span class='fl'>1</span><span class='op'>]</span> <span class='co'># intercept</span></span> -<span><span class='va'>b2</span> <span class='op'><-</span> <span class='va'>reg2</span><span class='op'>$</span><span class='va'>coefficients</span><span class='op'>[</span><span class='fl'>2</span><span class='op'>]</span> <span class='co'># slope</span></span> -<span><span class='va'>pline2</span> <span class='op'><-</span> <span class='va'>dim_plot</span> <span class='op'>+</span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_abline.html'>geom_abline</a></span><span class='op'>(</span>intercept <span class='op'>=</span> <span class='op'>-</span><span class='va'>a2</span><span class='op'>/</span><span class='va'>b2</span>, slope <span class='op'>=</span> <span class='fl'>1</span><span class='op'>/</span><span class='va'>b2</span>,</span> -<span> col <span class='op'>=</span> <span class='st'>"darkgreen"</span><span class='op'>)</span></span> -<span><span class='va'>pline2</span> <span class='op'>+</span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_segment.html'>geom_segment</a></span><span class='op'>(</span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span><span class='op'>(</span>xend<span class='op'>=</span><span class='va'>reg2</span><span class='op'>$</span><span class='va'>fitted.values</span>, yend<span class='op'>=</span><span class='va'>Colorado</span><span class='op'>)</span>,</span> -<span> colour <span class='op'>=</span> <span class='st'>"orange"</span>, arrow <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/grid/arrow.html'>arrow</a></span><span class='op'>(</span>length <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/grid/unit.html'>unit</a></span><span class='op'>(</span><span class='fl'>0.15</span>, <span class='st'>"cm"</span><span class='op'>)</span><span class='op'>)</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-8-clustering_files/figure-html5/unnamed-chunk-30-1.png" width="624" /></p> -</div> -<p>We can also find the variance of the points that are fit to this regression line</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/stats/cor.html'>var</a></span><span class='op'>(</span><span class='va'>normalized_dat</span><span class='op'>$</span><span class='va'>Colorado</span><span class='op'>)</span> <span class='op'>+</span> <span class='fu'><a href='https://rdrr.io/r/stats/cor.html'>var</a></span><span class='op'>(</span><span class='va'>reg2</span><span class='op'>$</span><span class='va'>fitted.values</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>[1] 0.000115524</code></pre> -</div> -<p>So far we have attempted to minimize either the distance of Alabama or Colorado values from the regression line. Instead of minimizing just one distance, PCA tries to minimize the total distance from the line (in both the X and Y directions).</p> -<p>Let’s run PCA and use matrix multiplication to visualize the first PC in our x-y space</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>svda</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/svd.html'>svd</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>as.matrix</a></span><span class='op'>(</span><span class='va'>normalized_dat</span><span class='op'>)</span><span class='op'>)</span></span> -<span><span class='va'>pc</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>as.matrix</a></span><span class='op'>(</span><span class='va'>normalized_dat</span><span class='op'>)</span> <span class='op'><a href='https://rdrr.io/r/base/matmult.html'>%*%</a></span> <span class='va'>svda</span><span class='op'>$</span><span class='va'>v</span><span class='op'>[</span>, <span class='fl'>1</span><span class='op'>]</span> <span class='op'><a href='https://rdrr.io/r/base/matmult.html'>%*%</a></span> <span class='fu'><a href='https://rdrr.io/r/base/t.html'>t</a></span><span class='op'>(</span><span class='va'>svda</span><span class='op'>$</span><span class='va'>v</span><span class='op'>[</span>, <span class='fl'>1</span><span class='op'>]</span><span class='op'>)</span> <span class='co'># Matrix multiplication</span></span> -<span><span class='va'>bp</span> <span class='op'><-</span> <span class='va'>svda</span><span class='op'>$</span><span class='va'>v</span><span class='op'>[</span><span class='fl'>2</span>, <span class='fl'>1</span><span class='op'>]</span> <span class='op'>/</span> <span class='va'>svda</span><span class='op'>$</span><span class='va'>v</span><span class='op'>[</span><span class='fl'>1</span>, <span class='fl'>1</span><span class='op'>]</span></span> -<span><span class='va'>ap</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/mean.html'>mean</a></span><span class='op'>(</span><span class='va'>pc</span><span class='op'>[</span>, <span class='fl'>2</span><span class='op'>]</span><span class='op'>)</span> <span class='op'>-</span> <span class='va'>bp</span> <span class='op'>*</span> <span class='fu'><a href='https://rdrr.io/r/base/mean.html'>mean</a></span><span class='op'>(</span><span class='va'>pc</span><span class='op'>[</span>, <span class='fl'>1</span><span class='op'>]</span><span class='op'>)</span></span> -<span><span class='va'>dim_plot</span> <span class='op'>+</span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_segment.html'>geom_segment</a></span><span class='op'>(</span>xend <span class='op'>=</span> <span class='va'>pc</span><span class='op'>[</span>, <span class='fl'>1</span><span class='op'>]</span>, yend <span class='op'>=</span> <span class='va'>pc</span><span class='op'>[</span>, <span class='fl'>2</span><span class='op'>]</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_abline.html'>geom_abline</a></span><span class='op'>(</span>intercept <span class='op'>=</span> <span class='va'>ap</span>, slope <span class='op'>=</span> <span class='va'>bp</span>, col <span class='op'>=</span> <span class='st'>"purple"</span>, lwd <span class='op'>=</span> <span class='fl'>1.5</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-8-clustering_files/figure-html5/unnamed-chunk-32-1.png" width="624" /></p> -</div> -<p>We can now find the variacne of the points in the PC space</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/apply.html'>apply</a></span><span class='op'>(</span><span class='va'>pc</span>, <span class='fl'>2</span>, <span class='va'>var</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>[1] 8.633852e-05 7.907309e-05</code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/sum.html'>sum</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/apply.html'>apply</a></span><span class='op'>(</span><span class='va'>pc</span>, <span class='fl'>2</span>, <span class='va'>var</span><span class='op'>)</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>[1] 0.0001654116</code></pre> -</div> -<p>Notice that this variance is the largest of the three lines we have fit.</p> -<p>From Modern Stats for Modern Biology</p> -<blockquote> -<p>If we are minimizing in both horizontal and vertical directions we are in fact minimizing the orthogonal projections onto the line from each point.</p> -<p>The total variability of the points is measured by the sum of squares ofthe projection of the points onto the center of gravity, which is the origin (0,0) if the data are centered. This is called the total variance or the inertia of the point cloud. This inertia can be decomposed into the sum of the squares of the projections onto the line plus the variances along that line. For a fixed variance, minimizing the projection distances also maximizes the variance along that line. Often we define the first principal component as the line with maximum variance.</p> -</blockquote> -<p>Although it’s good to know the inner workings of PCA, we can simply run this PCA analysis using <code>prcomp</code>.</p> -<p>Now that we have learned about some of the clustering techniques, we are going to continue working with the same data we used to talk about matrices, the top 100 boy and girl names by state for 2020. We will want to use the normalized data for these examples.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>names_mat</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/utils/read.table.html'>read.csv</a></span><span class='op'>(</span><span class='fu'><a href='https://here.r-lib.org//reference/here.html'>here</a></span><span class='op'>(</span><span class='st'>"class_7-9_data"</span>, <span class='st'>"boy_name_counts.csv"</span><span class='op'>)</span>,</span> -<span> row.names <span class='op'>=</span> <span class='fl'>1</span><span class='op'>)</span> <span class='op'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%>%</a></span></span> -<span> <span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>as.matrix</a></span><span class='op'>(</span><span class='op'>)</span></span> -<span></span> -<span></span> -<span><span class='va'>normalized_mat</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/t.html'>t</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/t.html'>t</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>)</span> <span class='op'>/</span> <span class='fu'><a href='https://rdrr.io/r/base/colSums.html'>colSums</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>)</span><span class='op'>)</span></span></code></pre> -</div> -</div> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>names.pca</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/stats/prcomp.html'>prcomp</a></span><span class='op'>(</span><span class='va'>normalized_mat</span><span class='op'>)</span></span></code></pre> -</div> -</div> -<p>The values for the dimensionality reduction are found in the <code>x</code> slot.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>pca_vals</span> <span class='op'><-</span> <span class='va'>names.pca</span><span class='op'>$</span><span class='va'>x</span> <span class='op'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%>%</a></span></span> -<span> <span class='fu'><a href='https://rdrr.io/r/base/data.frame.html'>data.frame</a></span><span class='op'>(</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>pca_vals</span><span class='op'>[</span><span class='fl'>1</span><span class='op'>:</span><span class='fl'>4</span>, <span class='fl'>1</span><span class='op'>:</span><span class='fl'>4</span><span class='op'>]</span></span></code></pre> -</div> -<pre><code> PC1 PC2 PC3 PC4 -William -0.047369020 0.0205532201 -0.03357595 -0.01476594 -James -0.039425249 0.0051117061 -0.02086795 -0.01309033 -John 0.008912962 -0.0008331344 -0.03046000 -0.01522468 -Elijah -0.052513118 -0.0058489913 -0.02466740 0.01209649</code></pre> -</div> -<p>We can also find the percent of variance explained by each component using the <code>sdev</code> slot</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>names.pca</span><span class='op'>$</span><span class='va'>sdev</span><span class='op'>[</span><span class='fl'>1</span><span class='op'>:</span><span class='fl'>5</span><span class='op'>]</span></span></code></pre> -</div> -<pre><code>[1] 0.036137672 0.016696954 0.013635319 0.008543108 0.005674905</code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>percentVar</span> <span class='op'><-</span> <span class='va'>names.pca</span><span class='op'>$</span><span class='va'>sdev</span><span class='op'>^</span><span class='fl'>2</span> <span class='op'>/</span> <span class='fu'><a href='https://rdrr.io/r/base/sum.html'>sum</a></span><span class='op'>(</span> <span class='va'>names.pca</span><span class='op'>$</span><span class='va'>sdev</span><span class='op'>^</span><span class='fl'>2</span> <span class='op'>)</span></span></code></pre> -</div> -</div> -<p>Now we can combine the two to make a PCA plot</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggplot.html'>ggplot</a></span><span class='op'>(</span><span class='va'>pca_vals</span>, <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span><span class='op'>(</span>x <span class='op'>=</span> <span class='va'>PC1</span>, y <span class='op'>=</span> <span class='va'>PC2</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_point.html'>geom_point</a></span><span class='op'>(</span>size <span class='op'>=</span> <span class='fl'>2</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/labs.html'>xlab</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/paste.html'>paste0</a></span><span class='op'>(</span><span class='st'>"PC1: "</span>,<span class='fu'><a href='https://rdrr.io/r/base/Round.html'>round</a></span><span class='op'>(</span><span class='va'>percentVar</span><span class='op'>[</span><span class='fl'>1</span><span class='op'>]</span> <span class='op'>*</span> <span class='fl'>100</span><span class='op'>)</span>,<span class='st'>"% variance"</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/labs.html'>ylab</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/paste.html'>paste0</a></span><span class='op'>(</span><span class='st'>"PC2: "</span>,<span class='fu'><a href='https://rdrr.io/r/base/Round.html'>round</a></span><span class='op'>(</span><span class='va'>percentVar</span><span class='op'>[</span><span class='fl'>2</span><span class='op'>]</span> <span class='op'>*</span> <span class='fl'>100</span><span class='op'>)</span>,<span class='st'>"% variance"</span><span class='op'>)</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-8-clustering_files/figure-html5/unnamed-chunk-38-1.png" width="624" /></p> -</div> -<h2 id="implementing-clustering-on-our-dataset">Implementing clustering on our dataset</h2> -<p>Now that we’ve learned how to visualize our data, we will be able to more easily see the clustering results. Let’s put together everything we’ve learned so far and try out the different clustering methods on our names data.</p> -<h3 id="k-means-clustering-of-names">K means clustering of names</h3> -<p>The first thing we need to do is decide if we want to cluster the states or the names. Our first question is what names have the most similar usage? To answer this question, we will need to cluster the names.</p> -<p>From the PCA plot above, it doesn’t look like there are strong clusters. Let’s start with 2 clusters.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/Random.html'>set.seed</a></span><span class='op'>(</span><span class='fl'>123</span><span class='op'>)</span></span> -<span><span class='va'>km.res2</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/stats/kmeans.html'>kmeans</a></span><span class='op'>(</span><span class='va'>normalized_mat</span>, centers <span class='op'>=</span> <span class='fl'>2</span>, nstart <span class='op'>=</span> <span class='fl'>25</span><span class='op'>)</span></span> -<span><span class='va'>km.res2</span><span class='op'>$</span><span class='va'>cluster</span></span></code></pre> -</div> -<pre><code> William James John Elijah Noah Liam Mason - 1 1 2 1 1 1 2 - Oliver Henry Jackson Samuel Jaxon Asher Grayson - 1 1 2 2 2 2 2 - Levi Michael Carter Benjamin Charles Wyatt Thomas - 2 2 2 1 2 2 2 - Aiden Luke David Owen Daniel Logan Joseph - 2 2 2 2 2 2 2 - Lucas Joshua Jack Alexander Maverick Gabriel Ethan - 2 2 2 2 2 2 2 - Eli Isaac Hunter Ezra Theodore - 2 2 2 2 2 </code></pre> -</div> -<p>We can again add this information to the plot</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>pca_cluster</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/cbind.html'>cbind</a></span><span class='op'>(</span><span class='va'>pca_vals</span>, <span class='st'>"cluster"</span> <span class='op'>=</span> <span class='va'>km.res2</span><span class='op'>$</span><span class='va'>cluster</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>pca_cluster</span><span class='op'>$</span><span class='va'>cluster</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/factor.html'>factor</a></span><span class='op'>(</span><span class='va'>pca_cluster</span><span class='op'>$</span><span class='va'>cluster</span><span class='op'>)</span></span> -<span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggplot.html'>ggplot</a></span><span class='op'>(</span><span class='va'>pca_cluster</span>, <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span><span class='op'>(</span>x <span class='op'>=</span> <span class='va'>PC1</span>, y <span class='op'>=</span> <span class='va'>PC2</span>, color <span class='op'>=</span> <span class='va'>cluster</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_point.html'>geom_point</a></span><span class='op'>(</span>size <span class='op'>=</span> <span class='fl'>2</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/labs.html'>xlab</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/paste.html'>paste0</a></span><span class='op'>(</span><span class='st'>"PC1: "</span>,<span class='fu'><a href='https://rdrr.io/r/base/Round.html'>round</a></span><span class='op'>(</span><span class='va'>percentVar</span><span class='op'>[</span><span class='fl'>1</span><span class='op'>]</span> <span class='op'>*</span> <span class='fl'>100</span><span class='op'>)</span>,<span class='st'>"% variance"</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/labs.html'>ylab</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/paste.html'>paste0</a></span><span class='op'>(</span><span class='st'>"PC2: "</span>,<span class='fu'><a href='https://rdrr.io/r/base/Round.html'>round</a></span><span class='op'>(</span><span class='va'>percentVar</span><span class='op'>[</span><span class='fl'>2</span><span class='op'>]</span> <span class='op'>*</span> <span class='fl'>100</span><span class='op'>)</span>,<span class='st'>"% variance"</span><span class='op'>)</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-8-clustering_files/figure-html5/unnamed-chunk-40-1.png" width="624" /></p> -</div> -<p>Let’s try again with 3 clusters</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/Random.html'>set.seed</a></span><span class='op'>(</span><span class='fl'>123</span><span class='op'>)</span></span> -<span><span class='va'>km.res3</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/stats/kmeans.html'>kmeans</a></span><span class='op'>(</span><span class='va'>normalized_mat</span>, centers <span class='op'>=</span> <span class='fl'>3</span>, nstart <span class='op'>=</span> <span class='fl'>25</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>pca_cluster</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/cbind.html'>cbind</a></span><span class='op'>(</span><span class='va'>pca_vals</span>, <span class='st'>"cluster"</span> <span class='op'>=</span> <span class='va'>km.res3</span><span class='op'>$</span><span class='va'>cluster</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>pca_cluster</span><span class='op'>$</span><span class='va'>cluster</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/factor.html'>factor</a></span><span class='op'>(</span><span class='va'>pca_cluster</span><span class='op'>$</span><span class='va'>cluster</span><span class='op'>)</span></span> -<span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggplot.html'>ggplot</a></span><span class='op'>(</span><span class='va'>pca_cluster</span>, <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span><span class='op'>(</span>x <span class='op'>=</span> <span class='va'>PC1</span>, y <span class='op'>=</span> <span class='va'>PC2</span>, color <span class='op'>=</span> <span class='va'>cluster</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_point.html'>geom_point</a></span><span class='op'>(</span>size <span class='op'>=</span> <span class='fl'>2</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/labs.html'>xlab</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/paste.html'>paste0</a></span><span class='op'>(</span><span class='st'>"PC1: "</span>,<span class='fu'><a href='https://rdrr.io/r/base/Round.html'>round</a></span><span class='op'>(</span><span class='va'>percentVar</span><span class='op'>[</span><span class='fl'>1</span><span class='op'>]</span> <span class='op'>*</span> <span class='fl'>100</span><span class='op'>)</span>,<span class='st'>"% variance"</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/labs.html'>ylab</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/paste.html'>paste0</a></span><span class='op'>(</span><span class='st'>"PC2: "</span>,<span class='fu'><a href='https://rdrr.io/r/base/Round.html'>round</a></span><span class='op'>(</span><span class='va'>percentVar</span><span class='op'>[</span><span class='fl'>2</span><span class='op'>]</span> <span class='op'>*</span> <span class='fl'>100</span><span class='op'>)</span>,<span class='st'>"% variance"</span><span class='op'>)</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-8-clustering_files/figure-html5/unnamed-chunk-41-1.png" width="624" /></p> -</div> -<p><strong>Exercise</strong> -Try with 4 clusters, what names cluster together?</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='co'># TODO Repeat with 4 clusters and repeat what names cluster together</span></span></code></pre> -</div> -</div> -<h3 id="hierarchical-clustering-of-names">Hierarchical clustering of names</h3> -<p>Now let’s repeat the clustering of names using hierarchical clustering</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>hc</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/stats/hclust.html'>hclust</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/stats/dist.html'>dist</a></span><span class='op'>(</span><span class='va'>normalized_mat</span><span class='op'>)</span><span class='op'>)</span></span> -<span></span> -<span><span class='fu'><a href='https://rdrr.io/r/graphics/plot.default.html'>plot</a></span><span class='op'>(</span><span class='va'>hc</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-8-clustering_files/figure-html5/unnamed-chunk-43-1.png" width="624" /></p> -</div> -<p>Based on the above plot, it seems like 3 clusters might be a good starting point</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>hc_clusters3</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/stats/cutree.html'>cutree</a></span><span class='op'>(</span>tree <span class='op'>=</span> <span class='va'>hc</span>, k <span class='op'>=</span><span class='fl'>3</span><span class='op'>)</span></span> -<span></span> -<span></span> -<span><span class='va'>hc_clusters3</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/cbind.html'>cbind</a></span><span class='op'>(</span><span class='va'>pca_vals</span>, <span class='st'>"cluster"</span> <span class='op'>=</span> <span class='va'>hc_clusters3</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>hc_clusters3</span><span class='op'>$</span><span class='va'>cluster</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/factor.html'>factor</a></span><span class='op'>(</span><span class='va'>hc_clusters3</span><span class='op'>$</span><span class='va'>cluster</span><span class='op'>)</span></span> -<span></span> -<span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggplot.html'>ggplot</a></span><span class='op'>(</span><span class='va'>hc_clusters3</span>, <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span><span class='op'>(</span>x <span class='op'>=</span> <span class='va'>PC1</span>, y <span class='op'>=</span> <span class='va'>PC2</span>, color <span class='op'>=</span> <span class='va'>cluster</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_point.html'>geom_point</a></span><span class='op'>(</span>size <span class='op'>=</span> <span class='fl'>2</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/labs.html'>xlab</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/paste.html'>paste0</a></span><span class='op'>(</span><span class='st'>"PC1: "</span>,<span class='fu'><a href='https://rdrr.io/r/base/Round.html'>round</a></span><span class='op'>(</span><span class='va'>percentVar</span><span class='op'>[</span><span class='fl'>1</span><span class='op'>]</span> <span class='op'>*</span> <span class='fl'>100</span><span class='op'>)</span>,<span class='st'>"% variance"</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/labs.html'>ylab</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/paste.html'>paste0</a></span><span class='op'>(</span><span class='st'>"PC2: "</span>,<span class='fu'><a href='https://rdrr.io/r/base/Round.html'>round</a></span><span class='op'>(</span><span class='va'>percentVar</span><span class='op'>[</span><span class='fl'>2</span><span class='op'>]</span> <span class='op'>*</span> <span class='fl'>100</span><span class='op'>)</span>,<span class='st'>"% variance"</span><span class='op'>)</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-8-clustering_files/figure-html5/unnamed-chunk-44-1.png" width="624" data-distill-preview=1 /></p> -</div> -<p><strong>Exercise</strong> -What two values are their own cluster? <em>Hint either remake the plot with the points labeled or look at the dendrogram above.</em></p> -<h3 id="repeating-by-clustering-states">Repeating by clustering states</h3> -<p>What if our question is what states have the most similar name usage? We will answer this by instead clustering on the states.</p> -<p>Again we will start by making a PCA plot. This time we will need to transform the matrix first before running PCA to run it on the sates instead</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>states_pca</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/stats/prcomp.html'>prcomp</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/t.html'>t</a></span><span class='op'>(</span><span class='va'>normalized_mat</span><span class='op'>)</span><span class='op'>)</span></span></code></pre> -</div> -</div> -<p>We can again pull out the values for the PCA from the <code>x</code> slot and the percent of the variance explained by each PC by using the <code>sdev</code> slot.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>pca_vals</span> <span class='op'><-</span> <span class='va'>states_pca</span><span class='op'>$</span><span class='va'>x</span> <span class='op'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%>%</a></span></span> -<span> <span class='fu'><a href='https://rdrr.io/r/base/data.frame.html'>data.frame</a></span><span class='op'>(</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>percentVar</span> <span class='op'><-</span> <span class='va'>states_pca</span><span class='op'>$</span><span class='va'>sdev</span><span class='op'>^</span><span class='fl'>2</span> <span class='op'>/</span> <span class='fu'><a href='https://rdrr.io/r/base/sum.html'>sum</a></span><span class='op'>(</span> <span class='va'>states_pca</span><span class='op'>$</span><span class='va'>sdev</span><span class='op'>^</span><span class='fl'>2</span> <span class='op'>)</span></span></code></pre> -</div> -</div> -<p>Now we can combine the two to make a PCA plot</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggplot.html'>ggplot</a></span><span class='op'>(</span><span class='va'>pca_vals</span>, <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span><span class='op'>(</span>x <span class='op'>=</span> <span class='va'>PC1</span>, y <span class='op'>=</span> <span class='va'>PC2</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_point.html'>geom_point</a></span><span class='op'>(</span>size <span class='op'>=</span> <span class='fl'>2</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/labs.html'>xlab</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/paste.html'>paste0</a></span><span class='op'>(</span><span class='st'>"PC1: "</span>,<span class='fu'><a href='https://rdrr.io/r/base/Round.html'>round</a></span><span class='op'>(</span><span class='va'>percentVar</span><span class='op'>[</span><span class='fl'>1</span><span class='op'>]</span> <span class='op'>*</span> <span class='fl'>100</span><span class='op'>)</span>,<span class='st'>"% variance"</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/labs.html'>ylab</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/paste.html'>paste0</a></span><span class='op'>(</span><span class='st'>"PC2: "</span>,<span class='fu'><a href='https://rdrr.io/r/base/Round.html'>round</a></span><span class='op'>(</span><span class='va'>percentVar</span><span class='op'>[</span><span class='fl'>2</span><span class='op'>]</span> <span class='op'>*</span> <span class='fl'>100</span><span class='op'>)</span>,<span class='st'>"% variance"</span><span class='op'>)</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-8-clustering_files/figure-html5/unnamed-chunk-47-1.png" width="624" /></p> -</div> -<p>We can now start by looking at 3 clusters using the kmeans clustering algorithm. Again, we will need to first transform the data to cluster the states rather than the names</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/base/Random.html'>set.seed</a></span><span class='op'>(</span><span class='fl'>123</span><span class='op'>)</span></span> -<span><span class='va'>km.res3</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/stats/kmeans.html'>kmeans</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/t.html'>t</a></span><span class='op'>(</span><span class='va'>normalized_mat</span><span class='op'>)</span>, centers <span class='op'>=</span> <span class='fl'>3</span>, nstart <span class='op'>=</span> <span class='fl'>25</span><span class='op'>)</span></span> -<span><span class='va'>km.res3</span><span class='op'>$</span><span class='va'>cluster</span></span></code></pre> -</div> -<pre><code> Alabama Alaska Arizona Arkansas California - 1 2 3 1 3 - Colorado Connecticut Delaware Florida Georgia - 2 3 3 3 1 - Hawaii Idaho Illinois Indiana Iowa - 3 2 3 2 2 - Kansas Kentucky Louisiana Maine Maryland - 2 1 1 2 3 </code></pre> -</div> -<p>Notice now we are clustering by the state instead of the names.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>pca_cluster</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/cbind.html'>cbind</a></span><span class='op'>(</span><span class='va'>pca_vals</span>, <span class='st'>"cluster"</span> <span class='op'>=</span> <span class='va'>km.res3</span><span class='op'>$</span><span class='va'>cluster</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>pca_cluster</span><span class='op'>$</span><span class='va'>cluster</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/factor.html'>factor</a></span><span class='op'>(</span><span class='va'>pca_cluster</span><span class='op'>$</span><span class='va'>cluster</span><span class='op'>)</span></span> -<span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggplot.html'>ggplot</a></span><span class='op'>(</span><span class='va'>pca_cluster</span>, <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span><span class='op'>(</span>x <span class='op'>=</span> <span class='va'>PC1</span>, y <span class='op'>=</span> <span class='va'>PC2</span>, color <span class='op'>=</span> <span class='va'>cluster</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_point.html'>geom_point</a></span><span class='op'>(</span>size <span class='op'>=</span> <span class='fl'>2</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/labs.html'>xlab</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/paste.html'>paste0</a></span><span class='op'>(</span><span class='st'>"PC1: "</span>,<span class='fu'><a href='https://rdrr.io/r/base/Round.html'>round</a></span><span class='op'>(</span><span class='va'>percentVar</span><span class='op'>[</span><span class='fl'>1</span><span class='op'>]</span> <span class='op'>*</span> <span class='fl'>100</span><span class='op'>)</span>,<span class='st'>"% variance"</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/labs.html'>ylab</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/paste.html'>paste0</a></span><span class='op'>(</span><span class='st'>"PC2: "</span>,<span class='fu'><a href='https://rdrr.io/r/base/Round.html'>round</a></span><span class='op'>(</span><span class='va'>percentVar</span><span class='op'>[</span><span class='fl'>2</span><span class='op'>]</span> <span class='op'>*</span> <span class='fl'>100</span><span class='op'>)</span>,<span class='st'>"% variance"</span><span class='op'>)</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-8-clustering_files/figure-html5/unnamed-chunk-49-1.png" width="624" /></p> -</div> -<p>This seems to pretty nicely segregate our data.</p> -<h3 id="hierarchical-clustering-of-states">Hierarchical clustering of states</h3> -<p>Now let’s repeat the clustering of names using hierarchical clustering, again we will need to transform the data first.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>hc</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/stats/hclust.html'>hclust</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/stats/dist.html'>dist</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/t.html'>t</a></span><span class='op'>(</span><span class='va'>normalized_mat</span><span class='op'>)</span><span class='op'>)</span><span class='op'>)</span></span> -<span></span> -<span><span class='fu'><a href='https://rdrr.io/r/graphics/plot.default.html'>plot</a></span><span class='op'>(</span><span class='va'>hc</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-8-clustering_files/figure-html5/unnamed-chunk-50-1.png" width="624" /></p> -</div> -<p>In the plot above we see 3 clear clusters</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>hc_clusters3</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/stats/cutree.html'>cutree</a></span><span class='op'>(</span>tree <span class='op'>=</span> <span class='va'>hc</span>, k <span class='op'>=</span><span class='fl'>3</span><span class='op'>)</span></span> -<span></span> -<span></span> -<span><span class='va'>hc_clusters3</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/cbind.html'>cbind</a></span><span class='op'>(</span><span class='va'>pca_vals</span>, <span class='st'>"cluster"</span> <span class='op'>=</span> <span class='va'>hc_clusters3</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>hc_clusters3</span><span class='op'>$</span><span class='va'>cluster</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/factor.html'>factor</a></span><span class='op'>(</span><span class='va'>hc_clusters3</span><span class='op'>$</span><span class='va'>cluster</span><span class='op'>)</span></span> -<span></span> -<span><span class='fu'><a href='https://ggplot2.tidyverse.org/reference/ggplot.html'>ggplot</a></span><span class='op'>(</span><span class='va'>hc_clusters3</span>, <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/aes.html'>aes</a></span><span class='op'>(</span>x <span class='op'>=</span> <span class='va'>PC1</span>, y <span class='op'>=</span> <span class='va'>PC2</span>, color <span class='op'>=</span> <span class='va'>cluster</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/geom_point.html'>geom_point</a></span><span class='op'>(</span>size <span class='op'>=</span> <span class='fl'>2</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/labs.html'>xlab</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/paste.html'>paste0</a></span><span class='op'>(</span><span class='st'>"PC1: "</span>,<span class='fu'><a href='https://rdrr.io/r/base/Round.html'>round</a></span><span class='op'>(</span><span class='va'>percentVar</span><span class='op'>[</span><span class='fl'>1</span><span class='op'>]</span> <span class='op'>*</span> <span class='fl'>100</span><span class='op'>)</span>,<span class='st'>"% variance"</span><span class='op'>)</span><span class='op'>)</span> <span class='op'>+</span></span> -<span> <span class='fu'><a href='https://ggplot2.tidyverse.org/reference/labs.html'>ylab</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/paste.html'>paste0</a></span><span class='op'>(</span><span class='st'>"PC2: "</span>,<span class='fu'><a href='https://rdrr.io/r/base/Round.html'>round</a></span><span class='op'>(</span><span class='va'>percentVar</span><span class='op'>[</span><span class='fl'>2</span><span class='op'>]</span> <span class='op'>*</span> <span class='fl'>100</span><span class='op'>)</span>,<span class='st'>"% variance"</span><span class='op'>)</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-8-clustering_files/figure-html5/unnamed-chunk-51-1.png" width="624" /></p> -</div> -<p><strong>Exercise</strong></p> -<p>Try out several different cluster numbers for both the kmeans clustering and the hierarchical clustering. Do you ever find cases where they differ? What if you try different numbers of starts for kmeans?</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='co'># TODO test out several hierarchical and k means clustering cluster numbers</span></span></code></pre> -</div> -</div> -<h2 id="im-a-biologist-why-should-i-care">I’m a biologist, why should I care?</h2> -<ul> -<li>Clustering and visualizations are important for any question you are answering -<ul> -<li>Clustering and dimensionality reduction are key aspects of single cell RNA-seq analysis</li> -<li>CYTOF also relies on clustering and dimensionality reduction techniques</li> -<li>Even a project where you’ve taken several measurements (that you expect to be related) can be used to cluster your samples</li> -<li>Phylogenetic trees are just a form of hierarchical clustering</li> -</ul></li> -<li>You will likely encounter clustering in papers that you read. My goal is to improve your understanding of the techniques so you can better interpret them on your own</li> -</ul> -<h2 id="acknowldgements-and-additional-references">Acknowldgements and additional references</h2> -<p>The content of this class borrows heavily from previous tutorials:</p> -<ul> -<li>K- means clustering -<ul> -<li><a href="https://towardsdatascience.com/how-does-k-means-clustering-in-machine-learning-work-fdaaaf5acfa0">Background</a></li> -<li><a href="https://analyticslog.com/blog/2021/3/7/nstart-value-k-means-clustering-in-r-programmin">Video</a></li> -<li><a href="https://www.datanovia.com/en/lessons/k-means-clustering-in-r-algorith-and-practical-examples/">R example</a></li> -</ul></li> -<li>Hierarchical clustering -<ul> -<li><a href="https://www.displayr.com/what-is-hierarchical-clustering/">Background</a></li> -<li><a href="https://www.r-bloggers.com/2016/01/hierarchical-clustering-in-r-2/">R example</a></li> -</ul></li> -<li>PCAs -<ul> -<li><a href="https://web.stanford.edu/class/bios221/book/07-chap.html">Tutorial</a></li> -</ul> -<div class="sourceCode" id="cb15"><pre class="sourceCode r distill-force-highlighting-css"><code class="sourceCode r"></code></pre></div></li> -</ul> -<!--radix_placeholder_article_footer--> -<!--/radix_placeholder_article_footer--> -</div> - -<div class="d-appendix"> -</div> - -<!-- dynamically load mathjax for compatibility with self-contained --> -<script> - (function () { - var script = document.createElement("script"); - script.type = "text/javascript"; - script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"; - document.getElementsByTagName("head")[0].appendChild(script); - })(); -</script> - -<!--radix_placeholder_site_after_body--> -<!--/radix_placeholder_site_after_body--> -<!--radix_placeholder_appendices--> -<div class="appendix-bottom"></div> -<!--/radix_placeholder_appendices--> -<!--radix_placeholder_navigation_after_body--> -<!--/radix_placeholder_navigation_after_body--> - -</body> - -</html> diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap.html b/_posts/2022-11-16-class-9-heatmap/class-9-heatmap.html deleted file mode 100644 index 099d1f3..0000000 --- a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap.html +++ /dev/null @@ -1,2204 +0,0 @@ -<!DOCTYPE html> - -<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang=""> - -<head> - <meta charset="utf-8"/> - <meta name="viewport" content="width=device-width, initial-scale=1"/> - <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"/> - <meta name="generator" content="distill" /> - - <style type="text/css"> - /* Hide doc at startup (prevent jankiness while JS renders/transforms) */ - body { - visibility: hidden; - } - </style> - - <!--radix_placeholder_import_source--> - <!--/radix_placeholder_import_source--> - -<style type="text/css">code{white-space: pre;}</style> -<style type="text/css" data-origin="pandoc"> -pre > code.sourceCode { white-space: pre; position: relative; } -pre > code.sourceCode > span { display: inline-block; line-height: 1.25; } -pre > code.sourceCode > span:empty { height: 1.2em; } -.sourceCode { overflow: visible; } -code.sourceCode > span { color: inherit; text-decoration: inherit; } -div.sourceCode { margin: 1em 0; } -pre.sourceCode { margin: 0; } -@media screen { -div.sourceCode { overflow: auto; } -} -@media print { -pre > code.sourceCode { white-space: pre-wrap; } -pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; } -} -pre.numberSource code - { counter-reset: source-line 0; } -pre.numberSource code > span - { position: relative; left: -4em; counter-increment: source-line; } -pre.numberSource code > span > a:first-child::before - { content: counter(source-line); - position: relative; left: -1em; text-align: right; vertical-align: baseline; - border: none; display: inline-block; - -webkit-touch-callout: none; -webkit-user-select: none; - -khtml-user-select: none; -moz-user-select: none; - -ms-user-select: none; user-select: none; - padding: 0 4px; width: 4em; - color: #aaaaaa; - } -pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; } -div.sourceCode - { color: #00769e; background-color: #f1f3f5; } -@media screen { -pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; } -} -code span { color: #00769e; } /* Normal */ -code span.al { color: #ad0000; } /* Alert */ -code span.an { color: #5e5e5e; } /* Annotation */ -code span.at { color: #657422; } /* Attribute */ -code span.bn { color: #ad0000; } /* BaseN */ -code span.bu { } /* BuiltIn */ -code span.cf { color: #00769e; } /* ControlFlow */ -code span.ch { color: #20794d; } /* Char */ -code span.cn { color: #8f5902; } /* Constant */ -code span.co { color: #5e5e5e; } /* Comment */ -code span.cv { color: #5e5e5e; font-style: italic; } /* CommentVar */ -code span.do { color: #5e5e5e; font-style: italic; } /* Documentation */ -code span.dt { color: #ad0000; } /* DataType */ -code span.dv { color: #ad0000; } /* DecVal */ -code span.er { color: #ad0000; } /* Error */ -code span.ex { } /* Extension */ -code span.fl { color: #ad0000; } /* Float */ -code span.fu { color: #4758ab; } /* Function */ -code span.im { } /* Import */ -code span.in { color: #5e5e5e; } /* Information */ -code span.kw { color: #00769e; } /* Keyword */ -code span.op { color: #5e5e5e; } /* Operator */ -code span.ot { color: #00769e; } /* Other */ -code span.pp { color: #ad0000; } /* Preprocessor */ -code span.sc { color: #5e5e5e; } /* SpecialChar */ -code span.ss { color: #20794d; } /* SpecialString */ -code span.st { color: #20794d; } /* String */ -code span.va { color: #111111; } /* Variable */ -code span.vs { color: #20794d; } /* VerbatimString */ -code span.wa { color: #5e5e5e; font-style: italic; } /* Warning */ -</style> - - - <!--radix_placeholder_meta_tags--> - <title>Class 9: Introduction to heatmaps</title> - - - - <!-- https://schema.org/Article --> - <meta property="article:published" itemprop="datePublished" content="2022-12-09"/> - <meta property="article:created" itemprop="dateCreated" content="2022-12-09"/> - <meta name="article:author" content="Kristen Wells"/> - - <!-- https://developers.facebook.com/docs/sharing/webmasters#markup --> - <meta property="og:title" content="Class 9: Introduction to heatmaps"/> - <meta property="og:type" content="article"/> - <meta property="og:locale" content="en_US"/> - - <!-- https://dev.twitter.com/cards/types/summary --> - <meta property="twitter:card" content="summary"/> - <meta property="twitter:title" content="Class 9: Introduction to heatmaps"/> - - <!--/radix_placeholder_meta_tags--> - <!--radix_placeholder_rmarkdown_metadata--> - - <script type="text/json" id="radix-rmarkdown-metadata"> - {"type":"list","attributes":{"names":{"type":"character","attributes":{},"value":["title","author","output","draft","date"]}},"value":[{"type":"character","attributes":{},"value":["Class 9: Introduction to heatmaps"]},{"type":"list","attributes":{},"value":[{"type":"list","attributes":{"names":{"type":"character","attributes":{},"value":["name","url","affiliation","orcid_id"]}},"value":[{"type":"character","attributes":{},"value":["Kristen Wells"]},{"type":"character","attributes":{},"value":["https://github.com/kwells4"]},{"type":"character","attributes":{},"value":["RNA Bioscience Iniative, Barbara Davis Diabetes Center"]},{"type":"character","attributes":{},"value":["0000-0002-7466-8164"]}]}]},{"type":"list","attributes":{"names":{"type":"character","attributes":{},"value":["distill::distill_article"]}},"value":[{"type":"list","attributes":{"names":{"type":"character","attributes":{},"value":["self_contained","toc"]}},"value":[{"type":"logical","attributes":{},"value":[false]},{"type":"logical","attributes":{},"value":[true]}]}]},{"type":"logical","attributes":{},"value":[false]},{"type":"character","attributes":{},"value":["12-09-2022"]}]} - </script> - <!--/radix_placeholder_rmarkdown_metadata--> - - <script type="text/json" id="radix-resource-manifest"> - {"type":"character","attributes":{},"value":["class-9-heatmap_files/anchor-4.2.2/anchor.min.js","class-9-heatmap_files/bowser-1.9.3/bowser.min.js","class-9-heatmap_files/distill-2.2.21/template.v2.js","class-9-heatmap_files/figure-html5/unnamed-chunk-10-1.png","class-9-heatmap_files/figure-html5/unnamed-chunk-13-1.png","class-9-heatmap_files/figure-html5/unnamed-chunk-14-1.png","class-9-heatmap_files/figure-html5/unnamed-chunk-15-1.png","class-9-heatmap_files/figure-html5/unnamed-chunk-18-1.png","class-9-heatmap_files/figure-html5/unnamed-chunk-20-1.png","class-9-heatmap_files/figure-html5/unnamed-chunk-22-1.png","class-9-heatmap_files/figure-html5/unnamed-chunk-26-1.png","class-9-heatmap_files/figure-html5/unnamed-chunk-27-1.png","class-9-heatmap_files/figure-html5/unnamed-chunk-29-1.png","class-9-heatmap_files/figure-html5/unnamed-chunk-31-1.png","class-9-heatmap_files/figure-html5/unnamed-chunk-33-1.png","class-9-heatmap_files/figure-html5/unnamed-chunk-34-1.png","class-9-heatmap_files/figure-html5/unnamed-chunk-35-1.png","class-9-heatmap_files/figure-html5/unnamed-chunk-38-1.png","class-9-heatmap_files/figure-html5/unnamed-chunk-39-1.png","class-9-heatmap_files/figure-html5/unnamed-chunk-4-1.png","class-9-heatmap_files/figure-html5/unnamed-chunk-42-1.png","class-9-heatmap_files/figure-html5/unnamed-chunk-43-1.png","class-9-heatmap_files/figure-html5/unnamed-chunk-44-1.png","class-9-heatmap_files/figure-html5/unnamed-chunk-47-1.png","class-9-heatmap_files/figure-html5/unnamed-chunk-5-1.png","class-9-heatmap_files/figure-html5/unnamed-chunk-7-1.png","class-9-heatmap_files/header-attrs-2.14/header-attrs.js","class-9-heatmap_files/jquery-3.6.0/jquery-3.6.0.js","class-9-heatmap_files/jquery-3.6.0/jquery-3.6.0.min.js","class-9-heatmap_files/jquery-3.6.0/jquery-3.6.0.min.map","class-9-heatmap_files/popper-2.6.0/popper.min.js","class-9-heatmap_files/tippy-6.2.7/tippy-bundle.umd.min.js","class-9-heatmap_files/tippy-6.2.7/tippy-light-border.css","class-9-heatmap_files/tippy-6.2.7/tippy.css","class-9-heatmap_files/tippy-6.2.7/tippy.umd.min.js","class-9-heatmap_files/webcomponents-2.0.0/webcomponents.js"]} - </script> - <!--radix_placeholder_navigation_in_header--> - <!--/radix_placeholder_navigation_in_header--> - <!--radix_placeholder_distill--> - - <style type="text/css"> - - body { - background-color: white; - } - - .pandoc-table { - width: 100%; - } - - .pandoc-table>caption { - margin-bottom: 10px; - } - - .pandoc-table th:not([align]) { - text-align: left; - } - - .pagedtable-footer { - font-size: 15px; - } - - d-byline .byline { - grid-template-columns: 2fr 2fr; - } - - d-byline .byline h3 { - margin-block-start: 1.5em; - } - - d-byline .byline .authors-affiliations h3 { - margin-block-start: 0.5em; - } - - .authors-affiliations .orcid-id { - width: 16px; - height:16px; - margin-left: 4px; - margin-right: 4px; - vertical-align: middle; - padding-bottom: 2px; - } - - d-title .dt-tags { - margin-top: 1em; - grid-column: text; - } - - .dt-tags .dt-tag { - text-decoration: none; - display: inline-block; - color: rgba(0,0,0,0.6); - padding: 0em 0.4em; - margin-right: 0.5em; - margin-bottom: 0.4em; - font-size: 70%; - border: 1px solid rgba(0,0,0,0.2); - border-radius: 3px; - text-transform: uppercase; - font-weight: 500; - } - - d-article table.gt_table td, - d-article table.gt_table th { - border-bottom: none; - font-size: 100%; - } - - .html-widget { - margin-bottom: 2.0em; - } - - .l-screen-inset { - padding-right: 16px; - } - - .l-screen .caption { - margin-left: 10px; - } - - .shaded { - background: rgb(247, 247, 247); - padding-top: 20px; - padding-bottom: 20px; - border-top: 1px solid rgba(0, 0, 0, 0.1); - border-bottom: 1px solid rgba(0, 0, 0, 0.1); - } - - .shaded .html-widget { - margin-bottom: 0; - border: 1px solid rgba(0, 0, 0, 0.1); - } - - .shaded .shaded-content { - background: white; - } - - .text-output { - margin-top: 0; - line-height: 1.5em; - } - - .hidden { - display: none !important; - } - - d-article { - padding-top: 2.5rem; - padding-bottom: 30px; - } - - d-appendix { - padding-top: 30px; - } - - d-article>p>img { - width: 100%; - } - - d-article h2 { - margin: 1rem 0 1.5rem 0; - } - - d-article h3 { - margin-top: 1.5rem; - } - - d-article iframe { - border: 1px solid rgba(0, 0, 0, 0.1); - margin-bottom: 2.0em; - width: 100%; - } - - /* Tweak code blocks */ - - d-article div.sourceCode code, - d-article pre code { - font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; - } - - d-article pre, - d-article div.sourceCode, - d-article div.sourceCode pre { - overflow: auto; - } - - d-article div.sourceCode { - background-color: white; - } - - d-article div.sourceCode pre { - padding-left: 10px; - font-size: 12px; - border-left: 2px solid rgba(0,0,0,0.1); - } - - d-article pre { - font-size: 12px; - color: black; - background: none; - margin-top: 0; - text-align: left; - white-space: pre; - word-spacing: normal; - word-break: normal; - word-wrap: normal; - line-height: 1.5; - - -moz-tab-size: 4; - -o-tab-size: 4; - tab-size: 4; - - -webkit-hyphens: none; - -moz-hyphens: none; - -ms-hyphens: none; - hyphens: none; - } - - d-article pre a { - border-bottom: none; - } - - d-article pre a:hover { - border-bottom: none; - text-decoration: underline; - } - - d-article details { - grid-column: text; - margin-bottom: 0.8em; - } - - @media(min-width: 768px) { - - d-article pre, - d-article div.sourceCode, - d-article div.sourceCode pre { - overflow: visible !important; - } - - d-article div.sourceCode pre { - padding-left: 18px; - font-size: 14px; - } - - d-article pre { - font-size: 14px; - } - - } - - figure img.external { - background: white; - border: 1px solid rgba(0, 0, 0, 0.1); - box-shadow: 0 1px 8px rgba(0, 0, 0, 0.1); - padding: 18px; - box-sizing: border-box; - } - - /* CSS for d-contents */ - - .d-contents { - grid-column: text; - color: rgba(0,0,0,0.8); - font-size: 0.9em; - padding-bottom: 1em; - margin-bottom: 1em; - padding-bottom: 0.5em; - margin-bottom: 1em; - padding-left: 0.25em; - justify-self: start; - } - - @media(min-width: 1000px) { - .d-contents.d-contents-float { - height: 0; - grid-column-start: 1; - grid-column-end: 4; - justify-self: center; - padding-right: 3em; - padding-left: 2em; - } - } - - .d-contents nav h3 { - font-size: 18px; - margin-top: 0; - margin-bottom: 1em; - } - - .d-contents li { - list-style-type: none - } - - .d-contents nav > ul { - padding-left: 0; - } - - .d-contents ul { - padding-left: 1em - } - - .d-contents nav ul li { - margin-top: 0.6em; - margin-bottom: 0.2em; - } - - .d-contents nav a { - font-size: 13px; - border-bottom: none; - text-decoration: none - color: rgba(0, 0, 0, 0.8); - } - - .d-contents nav a:hover { - text-decoration: underline solid rgba(0, 0, 0, 0.6) - } - - .d-contents nav > ul > li > a { - font-weight: 600; - } - - .d-contents nav > ul > li > ul { - font-weight: inherit; - } - - .d-contents nav > ul > li > ul > li { - margin-top: 0.2em; - } - - - .d-contents nav ul { - margin-top: 0; - margin-bottom: 0.25em; - } - - .d-article-with-toc h2:nth-child(2) { - margin-top: 0; - } - - - /* Figure */ - - .figure { - position: relative; - margin-bottom: 2.5em; - margin-top: 1.5em; - } - - .figure .caption { - color: rgba(0, 0, 0, 0.6); - font-size: 12px; - line-height: 1.5em; - } - - .figure img.external { - background: white; - border: 1px solid rgba(0, 0, 0, 0.1); - box-shadow: 0 1px 8px rgba(0, 0, 0, 0.1); - padding: 18px; - box-sizing: border-box; - } - - .figure .caption a { - color: rgba(0, 0, 0, 0.6); - } - - .figure .caption b, - .figure .caption strong, { - font-weight: 600; - color: rgba(0, 0, 0, 1.0); - } - - /* Citations */ - - d-article .citation { - color: inherit; - cursor: inherit; - } - - div.hanging-indent{ - margin-left: 1em; text-indent: -1em; - } - - /* Citation hover box */ - - .tippy-box[data-theme~=light-border] { - background-color: rgba(250, 250, 250, 0.95); - } - - .tippy-content > p { - margin-bottom: 0; - padding: 2px; - } - - - /* Tweak 1000px media break to show more text */ - - @media(min-width: 1000px) { - .base-grid, - distill-header, - d-title, - d-abstract, - d-article, - d-appendix, - distill-appendix, - d-byline, - d-footnote-list, - d-citation-list, - distill-footer { - grid-template-columns: [screen-start] 1fr [page-start kicker-start] 80px [middle-start] 50px [text-start kicker-end] 65px 65px 65px 65px 65px 65px 65px 65px [text-end gutter-start] 65px [middle-end] 65px [page-end gutter-end] 1fr [screen-end]; - grid-column-gap: 16px; - } - - .grid { - grid-column-gap: 16px; - } - - d-article { - font-size: 1.06rem; - line-height: 1.7em; - } - figure .caption, .figure .caption, figure figcaption { - font-size: 13px; - } - } - - @media(min-width: 1180px) { - .base-grid, - distill-header, - d-title, - d-abstract, - d-article, - d-appendix, - distill-appendix, - d-byline, - d-footnote-list, - d-citation-list, - distill-footer { - grid-template-columns: [screen-start] 1fr [page-start kicker-start] 60px [middle-start] 60px [text-start kicker-end] 60px 60px 60px 60px 60px 60px 60px 60px [text-end gutter-start] 60px [middle-end] 60px [page-end gutter-end] 1fr [screen-end]; - grid-column-gap: 32px; - } - - .grid { - grid-column-gap: 32px; - } - } - - - /* Get the citation styles for the appendix (not auto-injected on render since - we do our own rendering of the citation appendix) */ - - d-appendix .citation-appendix, - .d-appendix .citation-appendix { - font-size: 11px; - line-height: 15px; - border-left: 1px solid rgba(0, 0, 0, 0.1); - padding-left: 18px; - border: 1px solid rgba(0,0,0,0.1); - background: rgba(0, 0, 0, 0.02); - padding: 10px 18px; - border-radius: 3px; - color: rgba(150, 150, 150, 1); - overflow: hidden; - margin-top: -12px; - white-space: pre-wrap; - word-wrap: break-word; - } - - /* Include appendix styles here so they can be overridden */ - - d-appendix { - contain: layout style; - font-size: 0.8em; - line-height: 1.7em; - margin-top: 60px; - margin-bottom: 0; - border-top: 1px solid rgba(0, 0, 0, 0.1); - color: rgba(0,0,0,0.5); - padding-top: 60px; - padding-bottom: 48px; - } - - d-appendix h3 { - grid-column: page-start / text-start; - font-size: 15px; - font-weight: 500; - margin-top: 1em; - margin-bottom: 0; - color: rgba(0,0,0,0.65); - } - - d-appendix h3 + * { - margin-top: 1em; - } - - d-appendix ol { - padding: 0 0 0 15px; - } - - @media (min-width: 768px) { - d-appendix ol { - padding: 0 0 0 30px; - margin-left: -30px; - } - } - - d-appendix li { - margin-bottom: 1em; - } - - d-appendix a { - color: rgba(0, 0, 0, 0.6); - } - - d-appendix > * { - grid-column: text; - } - - d-appendix > d-footnote-list, - d-appendix > d-citation-list, - d-appendix > distill-appendix { - grid-column: screen; - } - - /* Include footnote styles here so they can be overridden */ - - d-footnote-list { - contain: layout style; - } - - d-footnote-list > * { - grid-column: text; - } - - d-footnote-list a.footnote-backlink { - color: rgba(0,0,0,0.3); - padding-left: 0.5em; - } - - - - /* Anchor.js */ - - .anchorjs-link { - /*transition: all .25s linear; */ - text-decoration: none; - border-bottom: none; - } - *:hover > .anchorjs-link { - margin-left: -1.125em !important; - text-decoration: none; - border-bottom: none; - } - - /* Social footer */ - - .social_footer { - margin-top: 30px; - margin-bottom: 0; - color: rgba(0,0,0,0.67); - } - - .disqus-comments { - margin-right: 30px; - } - - .disqus-comment-count { - border-bottom: 1px solid rgba(0, 0, 0, 0.4); - cursor: pointer; - } - - #disqus_thread { - margin-top: 30px; - } - - .article-sharing a { - border-bottom: none; - margin-right: 8px; - } - - .article-sharing a:hover { - border-bottom: none; - } - - .sidebar-section.subscribe { - font-size: 12px; - line-height: 1.6em; - } - - .subscribe p { - margin-bottom: 0.5em; - } - - - .article-footer .subscribe { - font-size: 15px; - margin-top: 45px; - } - - - .sidebar-section.custom { - font-size: 12px; - line-height: 1.6em; - } - - .custom p { - margin-bottom: 0.5em; - } - - /* Styles for listing layout (hide title) */ - .layout-listing d-title, .layout-listing .d-title { - display: none; - } - - /* Styles for posts lists (not auto-injected) */ - - - .posts-with-sidebar { - padding-left: 45px; - padding-right: 45px; - } - - .posts-list .description h2, - .posts-list .description p { - font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial, sans-serif; - } - - .posts-list .description h2 { - font-weight: 700; - border-bottom: none; - padding-bottom: 0; - } - - .posts-list h2.post-tag { - border-bottom: 1px solid rgba(0, 0, 0, 0.2); - padding-bottom: 12px; - } - .posts-list { - margin-top: 60px; - margin-bottom: 24px; - } - - .posts-list .post-preview { - text-decoration: none; - overflow: hidden; - display: block; - border-bottom: 1px solid rgba(0, 0, 0, 0.1); - padding: 24px 0; - } - - .post-preview-last { - border-bottom: none !important; - } - - .posts-list .posts-list-caption { - grid-column: screen; - font-weight: 400; - } - - .posts-list .post-preview h2 { - margin: 0 0 6px 0; - line-height: 1.2em; - font-style: normal; - font-size: 24px; - } - - .posts-list .post-preview p { - margin: 0 0 12px 0; - line-height: 1.4em; - font-size: 16px; - } - - .posts-list .post-preview .thumbnail { - box-sizing: border-box; - margin-bottom: 24px; - position: relative; - max-width: 500px; - } - .posts-list .post-preview img { - width: 100%; - display: block; - } - - .posts-list .metadata { - font-size: 12px; - line-height: 1.4em; - margin-bottom: 18px; - } - - .posts-list .metadata > * { - display: inline-block; - } - - .posts-list .metadata .publishedDate { - margin-right: 2em; - } - - .posts-list .metadata .dt-authors { - display: block; - margin-top: 0.3em; - margin-right: 2em; - } - - .posts-list .dt-tags { - display: block; - line-height: 1em; - } - - .posts-list .dt-tags .dt-tag { - display: inline-block; - color: rgba(0,0,0,0.6); - padding: 0.3em 0.4em; - margin-right: 0.2em; - margin-bottom: 0.4em; - font-size: 60%; - border: 1px solid rgba(0,0,0,0.2); - border-radius: 3px; - text-transform: uppercase; - font-weight: 500; - } - - .posts-list img { - opacity: 1; - } - - .posts-list img[data-src] { - opacity: 0; - } - - .posts-more { - clear: both; - } - - - .posts-sidebar { - font-size: 16px; - } - - .posts-sidebar h3 { - font-size: 16px; - margin-top: 0; - margin-bottom: 0.5em; - font-weight: 400; - text-transform: uppercase; - } - - .sidebar-section { - margin-bottom: 30px; - } - - .categories ul { - list-style-type: none; - margin: 0; - padding: 0; - } - - .categories li { - color: rgba(0, 0, 0, 0.8); - margin-bottom: 0; - } - - .categories li>a { - border-bottom: none; - } - - .categories li>a:hover { - border-bottom: 1px solid rgba(0, 0, 0, 0.4); - } - - .categories .active { - font-weight: 600; - } - - .categories .category-count { - color: rgba(0, 0, 0, 0.4); - } - - - @media(min-width: 768px) { - .posts-list .post-preview h2 { - font-size: 26px; - } - .posts-list .post-preview .thumbnail { - float: right; - width: 30%; - margin-bottom: 0; - } - .posts-list .post-preview .description { - float: left; - width: 45%; - } - .posts-list .post-preview .metadata { - float: left; - width: 20%; - margin-top: 8px; - } - .posts-list .post-preview p { - margin: 0 0 12px 0; - line-height: 1.5em; - font-size: 16px; - } - .posts-with-sidebar .posts-list { - float: left; - width: 75%; - } - .posts-with-sidebar .posts-sidebar { - float: right; - width: 20%; - margin-top: 60px; - padding-top: 24px; - padding-bottom: 24px; - } - } - - - /* Improve display for browsers without grid (IE/Edge <= 15) */ - - .downlevel { - line-height: 1.6em; - font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial, sans-serif; - margin: 0; - } - - .downlevel .d-title { - padding-top: 6rem; - padding-bottom: 1.5rem; - } - - .downlevel .d-title h1 { - font-size: 50px; - font-weight: 700; - line-height: 1.1em; - margin: 0 0 0.5rem; - } - - .downlevel .d-title p { - font-weight: 300; - font-size: 1.2rem; - line-height: 1.55em; - margin-top: 0; - } - - .downlevel .d-byline { - padding-top: 0.8em; - padding-bottom: 0.8em; - font-size: 0.8rem; - line-height: 1.8em; - } - - .downlevel .section-separator { - border: none; - border-top: 1px solid rgba(0, 0, 0, 0.1); - } - - .downlevel .d-article { - font-size: 1.06rem; - line-height: 1.7em; - padding-top: 1rem; - padding-bottom: 2rem; - } - - - .downlevel .d-appendix { - padding-left: 0; - padding-right: 0; - max-width: none; - font-size: 0.8em; - line-height: 1.7em; - margin-bottom: 0; - color: rgba(0,0,0,0.5); - padding-top: 40px; - padding-bottom: 48px; - } - - .downlevel .footnotes ol { - padding-left: 13px; - } - - .downlevel .base-grid, - .downlevel .distill-header, - .downlevel .d-title, - .downlevel .d-abstract, - .downlevel .d-article, - .downlevel .d-appendix, - .downlevel .distill-appendix, - .downlevel .d-byline, - .downlevel .d-footnote-list, - .downlevel .d-citation-list, - .downlevel .distill-footer, - .downlevel .appendix-bottom, - .downlevel .posts-container { - padding-left: 40px; - padding-right: 40px; - } - - @media(min-width: 768px) { - .downlevel .base-grid, - .downlevel .distill-header, - .downlevel .d-title, - .downlevel .d-abstract, - .downlevel .d-article, - .downlevel .d-appendix, - .downlevel .distill-appendix, - .downlevel .d-byline, - .downlevel .d-footnote-list, - .downlevel .d-citation-list, - .downlevel .distill-footer, - .downlevel .appendix-bottom, - .downlevel .posts-container { - padding-left: 150px; - padding-right: 150px; - max-width: 900px; - } - } - - .downlevel pre code { - display: block; - border-left: 2px solid rgba(0, 0, 0, .1); - padding: 0 0 0 20px; - font-size: 14px; - } - - .downlevel code, .downlevel pre { - color: black; - background: none; - font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; - text-align: left; - white-space: pre; - word-spacing: normal; - word-break: normal; - word-wrap: normal; - line-height: 1.5; - - -moz-tab-size: 4; - -o-tab-size: 4; - tab-size: 4; - - -webkit-hyphens: none; - -moz-hyphens: none; - -ms-hyphens: none; - hyphens: none; - } - - .downlevel .posts-list .post-preview { - color: inherit; - } - - - - </style> - - <script type="application/javascript"> - - function is_downlevel_browser() { - if (bowser.isUnsupportedBrowser({ msie: "12", msedge: "16"}, - window.navigator.userAgent)) { - return true; - } else { - return window.load_distill_framework === undefined; - } - } - - // show body when load is complete - function on_load_complete() { - - // add anchors - if (window.anchors) { - window.anchors.options.placement = 'left'; - window.anchors.add('d-article > h2, d-article > h3, d-article > h4, d-article > h5'); - } - - - // set body to visible - document.body.style.visibility = 'visible'; - - // force redraw for leaflet widgets - if (window.HTMLWidgets) { - var maps = window.HTMLWidgets.findAll(".leaflet"); - $.each(maps, function(i, el) { - var map = this.getMap(); - map.invalidateSize(); - map.eachLayer(function(layer) { - if (layer instanceof L.TileLayer) - layer.redraw(); - }); - }); - } - - // trigger 'shown' so htmlwidgets resize - $('d-article').trigger('shown'); - } - - function init_distill() { - - init_common(); - - // create front matter - var front_matter = $('<d-front-matter></d-front-matter>'); - $('#distill-front-matter').wrap(front_matter); - - // create d-title - $('.d-title').changeElementType('d-title'); - - // create d-byline - var byline = $('<d-byline></d-byline>'); - $('.d-byline').replaceWith(byline); - - // create d-article - var article = $('<d-article></d-article>'); - $('.d-article').wrap(article).children().unwrap(); - - // move posts container into article - $('.posts-container').appendTo($('d-article')); - - // create d-appendix - $('.d-appendix').changeElementType('d-appendix'); - - // flag indicating that we have appendix items - var appendix = $('.appendix-bottom').children('h3').length > 0; - - // replace footnotes with <d-footnote> - $('.footnote-ref').each(function(i, val) { - appendix = true; - var href = $(this).attr('href'); - var id = href.replace('#', ''); - var fn = $('#' + id); - var fn_p = $('#' + id + '>p'); - fn_p.find('.footnote-back').remove(); - var text = fn_p.html(); - var dtfn = $('<d-footnote></d-footnote>'); - dtfn.html(text); - $(this).replaceWith(dtfn); - }); - // remove footnotes - $('.footnotes').remove(); - - // move refs into #references-listing - $('#references-listing').replaceWith($('#refs')); - - $('h1.appendix, h2.appendix').each(function(i, val) { - $(this).changeElementType('h3'); - }); - $('h3.appendix').each(function(i, val) { - var id = $(this).attr('id'); - $('.d-contents a[href="#' + id + '"]').parent().remove(); - appendix = true; - $(this).nextUntil($('h1, h2, h3')).addBack().appendTo($('d-appendix')); - }); - - // show d-appendix if we have appendix content - $("d-appendix").css('display', appendix ? 'grid' : 'none'); - - // localize layout chunks to just output - $('.layout-chunk').each(function(i, val) { - - // capture layout - var layout = $(this).attr('data-layout'); - - // apply layout to markdown level block elements - var elements = $(this).children().not('details, div.sourceCode, pre, script'); - elements.each(function(i, el) { - var layout_div = $('<div class="' + layout + '"></div>'); - if (layout_div.hasClass('shaded')) { - var shaded_content = $('<div class="shaded-content"></div>'); - $(this).wrap(shaded_content); - $(this).parent().wrap(layout_div); - } else { - $(this).wrap(layout_div); - } - }); - - - // unwrap the layout-chunk div - $(this).children().unwrap(); - }); - - // remove code block used to force highlighting css - $('.distill-force-highlighting-css').parent().remove(); - - // remove empty line numbers inserted by pandoc when using a - // custom syntax highlighting theme - $('code.sourceCode a:empty').remove(); - - // load distill framework - load_distill_framework(); - - // wait for window.distillRunlevel == 4 to do post processing - function distill_post_process() { - - if (!window.distillRunlevel || window.distillRunlevel < 4) - return; - - // hide author/affiliations entirely if we have no authors - var front_matter = JSON.parse($("#distill-front-matter").html()); - var have_authors = front_matter.authors && front_matter.authors.length > 0; - if (!have_authors) - $('d-byline').addClass('hidden'); - - // article with toc class - $('.d-contents').parent().addClass('d-article-with-toc'); - - // strip links that point to # - $('.authors-affiliations').find('a[href="#"]').removeAttr('href'); - - // add orcid ids - $('.authors-affiliations').find('.author').each(function(i, el) { - var orcid_id = front_matter.authors[i].orcidID; - if (orcid_id) { - var a = $('<a></a>'); - a.attr('href', 'https://orcid.org/' + orcid_id); - var img = $('<img></img>'); - img.addClass('orcid-id'); - img.attr('alt', 'ORCID ID'); - img.attr('src','data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2ZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo1N0NEMjA4MDI1MjA2ODExOTk0QzkzNTEzRjZEQTg1NyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDozM0NDOEJGNEZGNTcxMUUxODdBOEVCODg2RjdCQ0QwOSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDozM0NDOEJGM0ZGNTcxMUUxODdBOEVCODg2RjdCQ0QwOSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IE1hY2ludG9zaCI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkZDN0YxMTc0MDcyMDY4MTE5NUZFRDc5MUM2MUUwNEREIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjU3Q0QyMDgwMjUyMDY4MTE5OTRDOTM1MTNGNkRBODU3Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+84NovQAAAR1JREFUeNpiZEADy85ZJgCpeCB2QJM6AMQLo4yOL0AWZETSqACk1gOxAQN+cAGIA4EGPQBxmJA0nwdpjjQ8xqArmczw5tMHXAaALDgP1QMxAGqzAAPxQACqh4ER6uf5MBlkm0X4EGayMfMw/Pr7Bd2gRBZogMFBrv01hisv5jLsv9nLAPIOMnjy8RDDyYctyAbFM2EJbRQw+aAWw/LzVgx7b+cwCHKqMhjJFCBLOzAR6+lXX84xnHjYyqAo5IUizkRCwIENQQckGSDGY4TVgAPEaraQr2a4/24bSuoExcJCfAEJihXkWDj3ZAKy9EJGaEo8T0QSxkjSwORsCAuDQCD+QILmD1A9kECEZgxDaEZhICIzGcIyEyOl2RkgwAAhkmC+eAm0TAAAAABJRU5ErkJggg=='); - a.append(img); - $(this).append(a); - } - }); - - // hide elements of author/affiliations grid that have no value - function hide_byline_column(caption) { - $('d-byline').find('h3:contains("' + caption + '")').parent().css('visibility', 'hidden'); - } - - // affiliations - var have_affiliations = false; - for (var i = 0; i<front_matter.authors.length; ++i) { - var author = front_matter.authors[i]; - if (author.affiliation !== " ") { - have_affiliations = true; - break; - } - } - if (!have_affiliations) - $('d-byline').find('h3:contains("Affiliations")').css('visibility', 'hidden'); - - // published date - if (!front_matter.publishedDate) - hide_byline_column("Published"); - - // document object identifier - var doi = $('d-byline').find('h3:contains("DOI")'); - var doi_p = doi.next().empty(); - if (!front_matter.doi) { - // if we have a citation and valid citationText then link to that - if ($('#citation').length > 0 && front_matter.citationText) { - doi.html('Citation'); - $('<a href="#citation"></a>') - .text(front_matter.citationText) - .appendTo(doi_p); - } else { - hide_byline_column("DOI"); - } - } else { - $('<a></a>') - .attr('href', "https://doi.org/" + front_matter.doi) - .html(front_matter.doi) - .appendTo(doi_p); - } - - // change plural form of authors/affiliations - if (front_matter.authors.length === 1) { - var grid = $('.authors-affiliations'); - grid.children('h3:contains("Authors")').text('Author'); - grid.children('h3:contains("Affiliations")').text('Affiliation'); - } - - // remove d-appendix and d-footnote-list local styles - $('d-appendix > style:first-child').remove(); - $('d-footnote-list > style:first-child').remove(); - - // move appendix-bottom entries to the bottom - $('.appendix-bottom').appendTo('d-appendix').children().unwrap(); - $('.appendix-bottom').remove(); - - // hoverable references - $('span.citation[data-cites]').each(function() { - const citeChild = $(this).children()[0] - // Do not process if @xyz has been used without escaping and without bibliography activated - // https://github.com/rstudio/distill/issues/466 - if (citeChild === undefined) return true - - if (citeChild.nodeName == "D-FOOTNOTE") { - var fn = citeChild - $(this).html(fn.shadowRoot.querySelector("sup")) - $(this).id = fn.id - fn.remove() - } - var refs = $(this).attr('data-cites').split(" "); - var refHtml = refs.map(function(ref) { - // Could use CSS.escape too here, we insure backward compatibility in navigator - return "<p>" + $('div[id="ref-' + ref + '"]').html() + "</p>"; - }).join("\n"); - window.tippy(this, { - allowHTML: true, - content: refHtml, - maxWidth: 500, - interactive: true, - interactiveBorder: 10, - theme: 'light-border', - placement: 'bottom-start' - }); - }); - - // fix footnotes in tables (#411) - // replacing broken distill.pub feature - $('table d-footnote').each(function() { - // we replace internal showAtNode methode which is triggered when hovering a footnote - this.hoverBox.showAtNode = function(node) { - // ported from https://github.com/distillpub/template/pull/105/files - calcOffset = function(elem) { - let x = elem.offsetLeft; - let y = elem.offsetTop; - // Traverse upwards until an `absolute` element is found or `elem` - // becomes null. - while (elem = elem.offsetParent && elem.style.position != 'absolute') { - x += elem.offsetLeft; - y += elem.offsetTop; - } - - return { left: x, top: y }; - } - // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetTop - const bbox = node.getBoundingClientRect(); - const offset = calcOffset(node); - this.show([offset.left + bbox.width, offset.top + bbox.height]); - } - }) - - // clear polling timer - clearInterval(tid); - - // show body now that everything is ready - on_load_complete(); - } - - var tid = setInterval(distill_post_process, 50); - distill_post_process(); - - } - - function init_downlevel() { - - init_common(); - - // insert hr after d-title - $('.d-title').after($('<hr class="section-separator"/>')); - - // check if we have authors - var front_matter = JSON.parse($("#distill-front-matter").html()); - var have_authors = front_matter.authors && front_matter.authors.length > 0; - - // manage byline/border - if (!have_authors) - $('.d-byline').remove(); - $('.d-byline').after($('<hr class="section-separator"/>')); - $('.d-byline a').remove(); - - // remove toc - $('.d-contents').remove(); - - // move appendix elements - $('h1.appendix, h2.appendix').each(function(i, val) { - $(this).changeElementType('h3'); - }); - $('h3.appendix').each(function(i, val) { - $(this).nextUntil($('h1, h2, h3')).addBack().appendTo($('.d-appendix')); - }); - - - // inject headers into references and footnotes - var refs_header = $('<h3></h3>'); - refs_header.text('References'); - $('#refs').prepend(refs_header); - - var footnotes_header = $('<h3></h3'); - footnotes_header.text('Footnotes'); - $('.footnotes').children('hr').first().replaceWith(footnotes_header); - - // move appendix-bottom entries to the bottom - $('.appendix-bottom').appendTo('.d-appendix').children().unwrap(); - $('.appendix-bottom').remove(); - - // remove appendix if it's empty - if ($('.d-appendix').children().length === 0) - $('.d-appendix').remove(); - - // prepend separator above appendix - $('.d-appendix').before($('<hr class="section-separator" style="clear: both"/>')); - - // trim code - $('pre>code').each(function(i, val) { - $(this).html($.trim($(this).html())); - }); - - // move posts-container right before article - $('.posts-container').insertBefore($('.d-article')); - - $('body').addClass('downlevel'); - - on_load_complete(); - } - - - function init_common() { - - // jquery plugin to change element types - (function($) { - $.fn.changeElementType = function(newType) { - var attrs = {}; - - $.each(this[0].attributes, function(idx, attr) { - attrs[attr.nodeName] = attr.nodeValue; - }); - - this.replaceWith(function() { - return $("<" + newType + "/>", attrs).append($(this).contents()); - }); - }; - })(jQuery); - - // prevent underline for linked images - $('a > img').parent().css({'border-bottom' : 'none'}); - - // mark non-body figures created by knitr chunks as 100% width - $('.layout-chunk').each(function(i, val) { - var figures = $(this).find('img, .html-widget'); - // ignore leaflet img layers (#106) - figures = figures.filter(':not(img[class*="leaflet"])') - if ($(this).attr('data-layout') !== "l-body") { - figures.css('width', '100%'); - } else { - figures.css('max-width', '100%'); - figures.filter("[width]").each(function(i, val) { - var fig = $(this); - fig.css('width', fig.attr('width') + 'px'); - }); - - } - }); - - // auto-append index.html to post-preview links in file: protocol - // and in rstudio ide preview - $('.post-preview').each(function(i, val) { - if (window.location.protocol === "file:") - $(this).attr('href', $(this).attr('href') + "index.html"); - }); - - // get rid of index.html references in header - if (window.location.protocol !== "file:") { - $('.distill-site-header a[href]').each(function(i,val) { - $(this).attr('href', $(this).attr('href').replace(/^index[.]html/, "./")); - }); - } - - // add class to pandoc style tables - $('tr.header').parent('thead').parent('table').addClass('pandoc-table'); - $('.kable-table').children('table').addClass('pandoc-table'); - - // add figcaption style to table captions - $('caption').parent('table').addClass("figcaption"); - - // initialize posts list - if (window.init_posts_list) - window.init_posts_list(); - - // implmement disqus comment link - $('.disqus-comment-count').click(function() { - window.headroom_prevent_pin = true; - $('#disqus_thread').toggleClass('hidden'); - if (!$('#disqus_thread').hasClass('hidden')) { - var offset = $(this).offset(); - $(window).resize(); - $('html, body').animate({ - scrollTop: offset.top - 35 - }); - } - }); - } - - document.addEventListener('DOMContentLoaded', function() { - if (is_downlevel_browser()) - init_downlevel(); - else - window.addEventListener('WebComponentsReady', init_distill); - }); - - </script> - - <!--/radix_placeholder_distill--> - <script src="class-9-heatmap_files/header-attrs-2.14/header-attrs.js"></script> - <script src="class-9-heatmap_files/jquery-3.6.0/jquery-3.6.0.min.js"></script> - <script src="class-9-heatmap_files/popper-2.6.0/popper.min.js"></script> - <link href="class-9-heatmap_files/tippy-6.2.7/tippy.css" rel="stylesheet" /> - <link href="class-9-heatmap_files/tippy-6.2.7/tippy-light-border.css" rel="stylesheet" /> - <script src="class-9-heatmap_files/tippy-6.2.7/tippy.umd.min.js"></script> - <script src="class-9-heatmap_files/anchor-4.2.2/anchor.min.js"></script> - <script src="class-9-heatmap_files/bowser-1.9.3/bowser.min.js"></script> - <script src="class-9-heatmap_files/webcomponents-2.0.0/webcomponents.js"></script> - <script src="class-9-heatmap_files/distill-2.2.21/template.v2.js"></script> - <!--radix_placeholder_site_in_header--> - <!--/radix_placeholder_site_in_header--> - - -</head> - -<body> - -<!--radix_placeholder_front_matter--> - -<script id="distill-front-matter" type="text/json"> -{"title":"Class 9: Introduction to heatmaps","authors":[{"author":"Kristen Wells","authorURL":"https://github.com/kwells4","affiliation":"RNA Bioscience Iniative, Barbara Davis Diabetes Center","affiliationURL":"#","orcidID":"0000-0002-7466-8164"}],"publishedDate":"2022-12-09T00:00:00.000-07:00","citationText":"Wells, 2022"} -</script> - -<!--/radix_placeholder_front_matter--> -<!--radix_placeholder_navigation_before_body--> -<!--/radix_placeholder_navigation_before_body--> -<!--radix_placeholder_site_before_body--> -<!--/radix_placeholder_site_before_body--> - -<div class="d-title"> -<h1>Class 9: Introduction to heatmaps</h1> -<!--radix_placeholder_categories--> -<!--/radix_placeholder_categories--> - -</div> - -<div class="d-byline"> - Kristen Wells <a href="https://github.com/kwells4" class="uri">https://github.com/kwells4</a> (RNA Bioscience Iniative, Barbara Davis Diabetes Center) - -<br/>12-09-2022 -</div> - -<div class="d-article"> -<div class="d-contents d-contents-float"> -<nav class="l-text toc figcaption" id="TOC"> -<h3>Contents</h3> -<ul> -<li><a href="#goals-for-this-class" id="toc-goals-for-this-class">Goals for this class</a></li> -<li><a href="#load-packages" id="toc-load-packages">Load packages</a></li> -<li><a href="#download-files" id="toc-download-files">Download files</a></li> -<li><a href="#making-a-heatmap" id="toc-making-a-heatmap">Making a heatmap</a> -<ul> -<li><a href="#cleaning-up-by-normalizing-values" id="toc-cleaning-up-by-normalizing-values">Cleaning up by normalizing values</a></li> -<li><a href="#cleaning-up-by-scaling-values" id="toc-cleaning-up-by-scaling-values">Cleaning up by scaling values</a></li> -<li><a href="#changing-the-color-palette" id="toc-changing-the-color-palette">Changing the color palette</a></li> -<li><a href="#adding-annotations" id="toc-adding-annotations">Adding annotations</a></li> -<li><a href="#clustering" id="toc-clustering">Clustering</a></li> -<li><a href="#remove-column-and-row-names" id="toc-remove-column-and-row-names">Remove column and row names</a></li> -<li><a href="#other-aesthetics" id="toc-other-aesthetics">Other aesthetics</a></li> -</ul></li> -<li><a href="#acknowldgements-and-additional-references" id="toc-acknowldgements-and-additional-references">Acknowldgements and additional references</a></li> -<li><a href="#im-a-biologist-why-should-i-care" id="toc-im-a-biologist-why-should-i-care">I’m a biologist, why should I care?</a></li> -</ul> -</nav> -</div> -<p><em>The Rmarkdown for this class is <a href="https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2022-11-16-class-9-heatmap/class-9-heatmap.Rmd">on github</a></em></p> -<h2 id="goals-for-this-class">Goals for this class</h2> -<ul> -<li>Learn how to make a heat map using <code>pheatmap</code></li> -<li>Understand how data is generally processed before making a heat map, understand what interpretations can be made given the processing.</li> -<li>Learn how to change the aesthetics of a heat map</li> -<li>Learn how to visualize and access clustering information from the heat map</li> -</ul> -<h2 id="load-packages">Load packages</h2> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='kw'><a href='https://rdrr.io/r/base/library.html'>library</a></span><span class='op'>(</span><span class='va'><a href='https://tidyverse.tidyverse.org'>tidyverse</a></span><span class='op'>)</span></span> -<span><span class='kw'><a href='https://rdrr.io/r/base/library.html'>library</a></span><span class='op'>(</span><span class='va'>pheatmap</span><span class='op'>)</span> <span class='co'># install.packages("pheatmap")</span></span> -<span><span class='kw'><a href='https://rdrr.io/r/base/library.html'>library</a></span><span class='op'>(</span><span class='va'><a href='https://sjmgarnier.github.io/viridis/'>viridis</a></span><span class='op'>)</span> <span class='co'># install.packages("viridis")</span></span> -<span><span class='kw'><a href='https://rdrr.io/r/base/library.html'>library</a></span><span class='op'>(</span><span class='va'>MetBrewer</span><span class='op'>)</span> <span class='co'># install.packages("MetBrewer")</span></span> -<span><span class='kw'><a href='https://rdrr.io/r/base/library.html'>library</a></span><span class='op'>(</span><span class='va'><a href='https://here.r-lib.org/'>here</a></span><span class='op'>)</span></span></code></pre> -</div> -</div> -<h2 id="download-files">Download files</h2> -<p>Before we get started, let’s download all of the files you will need for the next three classes.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='co'># conditionally download all of the files used in rmarkdown from github </span></span> -<span><span class='kw'><a href='https://rdrr.io/r/base/source.html'>source</a></span><span class='op'>(</span><span class='st'>"https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2022-11-10-class-7-matricies/download_files.R"</span><span class='op'>)</span></span></code></pre> -</div> -</div> -<h2 id="making-a-heatmap">Making a heatmap</h2> -<p>Today we are going to continue working with the same data we used to talk about matrices and clustering, the top 100 boy and girl names by state for 2020.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>male_names_mat</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/utils/read.table.html'>read.csv</a></span><span class='op'>(</span><span class='fu'><a href='https://here.r-lib.org//reference/here.html'>here</a></span><span class='op'>(</span><span class='st'>"class_7-9_data"</span>, <span class='st'>"boy_name_counts.csv"</span><span class='op'>)</span>,</span> -<span> row.names <span class='op'>=</span> <span class='fl'>1</span><span class='op'>)</span> <span class='op'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%>%</a></span></span> -<span> <span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>as.matrix</a></span><span class='op'>(</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>female_names_mat</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/utils/read.table.html'>read.csv</a></span><span class='op'>(</span><span class='fu'><a href='https://here.r-lib.org//reference/here.html'>here</a></span><span class='op'>(</span><span class='st'>"class_7-9_data"</span>, <span class='st'>"girl_name_counts.csv"</span><span class='op'>)</span>,</span> -<span> row.names <span class='op'>=</span> <span class='fl'>1</span><span class='op'>)</span> <span class='op'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%>%</a></span></span> -<span> <span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>as.matrix</a></span><span class='op'>(</span><span class='op'>)</span></span></code></pre> -</div> -</div> -<p>We’ve loaded in both the boy and the girl names as separate matrices, we can combine these using <code>rbind</code> to bind the rows</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>names_mat</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/cbind.html'>rbind</a></span><span class='op'>(</span><span class='va'>male_names_mat</span>, <span class='va'>female_names_mat</span><span class='op'>)</span></span></code></pre> -</div> -</div> -<p>To make a heatmap, we will use the pheatmap package</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/pkg/pheatmap/man/pheatmap.html'>pheatmap</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-9-heatmap_files/figure-html5/unnamed-chunk-4-1.png" width="624" /></p> -</div> -<p>Notice here we can only see the names for California</p> -<h3 id="cleaning-up-by-normalizing-values">Cleaning up by normalizing values</h3> -<p>It’s pretty hard to see much strucutre in the data just using the raw values. Let’s try with our normalized values</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>normalized_mat</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/t.html'>t</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/t.html'>t</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>)</span> <span class='op'>/</span> <span class='fu'><a href='https://rdrr.io/r/base/colSums.html'>colSums</a></span><span class='op'>(</span><span class='va'>names_mat</span><span class='op'>)</span><span class='op'>)</span></span> -<span><span class='fu'><a href='https://rdrr.io/pkg/pheatmap/man/pheatmap.html'>pheatmap</a></span><span class='op'>(</span><span class='va'>normalized_mat</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-9-heatmap_files/figure-html5/unnamed-chunk-5-1.png" width="624" /></p> -</div> -<p>You can see that when we try to normalize the values by dividing each number by the total number for the state, the trends in the data are much more clear and we don’t only see the data for California.</p> -<h3 id="cleaning-up-by-scaling-values">Cleaning up by scaling values</h3> -<p>Another popular way to normalize the data for a heatmap is called a z-score. This is also know a mean-centered scaled data. The z-score is calculated as follows</p> -<div> -<span class="math display">\[ -zscore = \frac{x - \mu}{\sigma} -\]</span> -<div> - -<p>Where x is each value <span class="math inline">\(\mu\)</span> is the mean for the values and <span class="math inline">\(\sigma\)</span> is the standard deviation for the values. Here, <span class="math inline">\(x - \mu\)</span> is called “centering” and dividing by <span class="math inline">\(\sigma\)</span> is called “scaling”</p> -<p>In R, we can scale the data using the <code>scale</code> function. Scaling is done on the columns, so here we can use the original matrix without any transformations</p> -<p><code>scale</code> takes 3 arguments</p> -<pre><code>x - a numeric matrix(like object). - -center - either a logical value or numeric-alike vector of length equal to the -number of columns of x, where ‘numeric-alike’ means that as.numeric(.) will be -applied successfully if is.numeric(.) is not true. - -scale - either a logical value or a numeric-alike vector of length equal to the -number of columns of x.</code></pre> -<p>The <code>center</code> refers to <span class="math inline">\(x - \mu\)</span> from the equation above and <code>scale</code> refers to dividing by <span class="math inline">\(\sigma\)</span>. We will set both to be true to be a z-score.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>scaled_mat</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/scale.html'>scale</a></span><span class='op'>(</span><span class='va'>names_mat</span>, scale <span class='op'>=</span> <span class='cn'>TRUE</span>, center <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span></span></code></pre> -</div> -</div> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/pkg/pheatmap/man/pheatmap.html'>pheatmap</a></span><span class='op'>(</span><span class='va'>scaled_mat</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-9-heatmap_files/figure-html5/unnamed-chunk-7-1.png" width="624" /></p> -</div> -<p>Notice how we again can see more structure in the data.</p> -<p>The scale shows both negative and positive values. Negative values had counts less than the mean, positive values had counts above the mean, and 0 means the value was equal to the mean. An important note here, values that are negative do not mean they were zero. For example, the scaled value for “Grayson” in California is negative:</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>scaled_mat</span><span class='op'>[</span><span class='st'>"Grayson"</span>, <span class='st'>"California"</span><span class='op'>]</span></span></code></pre> -</div> -<pre><code>[1] -1.043828</code></pre> -</div> -<p>but there are still several hundred individuals named “Grayson” in California.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>names_mat</span><span class='op'>[</span><span class='st'>"Grayson"</span>, <span class='st'>"California"</span><span class='op'>]</span></span></code></pre> -</div> -<pre><code>[1] 453</code></pre> -</div> -<p><strong>Note if you want a z-score of gene expression data, you will want to center and scale by the genes not the samples. Most gene expression data is stored as gene x sample so you will likely need to transform the matrix before scaling:</strong></p> -<pre><code>scaled_mat <- t(scale(t(unscaled_mat), scale = TRUE, center = TRUE))</code></pre> -<p><strong>Exercise</strong> -Looking at the three heatmaps, what is the most popular name? What heatmap is easiest to interpret?</p> -<h3 id="changing-the-color-palette">Changing the color palette</h3> -<p>The default color palette for pheatmap isn’t always the color palette you want. One color palette I like is the magma color from the <code>viridis</code> package. To use this package you can just call any of the color functions. and provide the number of colors you want in the palette. We will use the <code>magma</code> function below.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/pkg/pheatmap/man/pheatmap.html'>pheatmap</a></span><span class='op'>(</span><span class='va'>scaled_mat</span>, color <span class='op'>=</span> <span class='fu'><a href='https://sjmgarnier.github.io/viridisLite/reference/viridis.html'>magma</a></span><span class='op'>(</span><span class='fl'>100</span><span class='op'>)</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-9-heatmap_files/figure-html5/unnamed-chunk-10-1.png" width="624" /></p> -</div> -<p>You can also add custom color palettes using <code>colorRampPalette</code>. This creates a function to generate a color palette with your colors for any number of values:</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>color_function</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/grDevices/colorRamp.html'>colorRampPalette</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='st'>"navy"</span>, <span class='st'>"white"</span>, <span class='st'>"red"</span><span class='op'>)</span><span class='op'>)</span></span> -<span><span class='va'>color_function</span></span></code></pre> -</div> -<pre><code>function (n) -{ - x <- ramp(seq.int(0, 1, length.out = n)) - if (ncol(x) == 4L) - rgb(x[, 1L], x[, 2L], x[, 3L], x[, 4L], maxColorValue = 255) - else rgb(x[, 1L], x[, 2L], x[, 3L], maxColorValue = 255) -} -<bytecode: 0x7fa771faaaa0> -<environment: 0x7fa71300c4a8></code></pre> -</div> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'>color_function</span><span class='op'>(</span><span class='fl'>10</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code> [1] "#000080" "#38389C" "#7171B8" "#AAAAD4" "#E2E2F0" "#FFE2E2" - [7] "#FFAAAA" "#FF7171" "#FF3838" "#FF0000"</code></pre> -</div> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/pkg/pheatmap/man/pheatmap.html'>pheatmap</a></span><span class='op'>(</span><span class='va'>scaled_mat</span>, color <span class='op'>=</span> <span class='fu'>color_function</span><span class='op'>(</span><span class='fl'>100</span><span class='op'>)</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-9-heatmap_files/figure-html5/unnamed-chunk-13-1.png" width="624" /></p> -</div> -<p>You can also run this in one line of code and not save the function</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/pkg/pheatmap/man/pheatmap.html'>pheatmap</a></span><span class='op'>(</span><span class='va'>scaled_mat</span>, color <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/grDevices/colorRamp.html'>colorRampPalette</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='st'>"navy"</span>, <span class='st'>"white"</span>, <span class='st'>"red"</span><span class='op'>)</span><span class='op'>)</span><span class='op'>(</span><span class='fl'>100</span><span class='op'>)</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-9-heatmap_files/figure-html5/unnamed-chunk-14-1.png" width="624" /></p> -</div> -<p>You can even use custom color palettes with any HEX color codes you want. A personal favorite of mine is a blue/yellow palette from the <code>ArchR</code> package.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>blueYellow</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='st'>"#352A86"</span>, <span class='st'>"#343DAE"</span>, <span class='st'>"#0262E0"</span>, <span class='st'>"#1389D2"</span>, <span class='st'>"#2DB7A3"</span>,</span> -<span> <span class='st'>"#A5BE6A"</span>, <span class='st'>"#F8BA43"</span>, <span class='st'>"#F6DA23"</span>, <span class='st'>"#F8FA0D"</span><span class='op'>)</span></span> -<span></span> -<span><span class='fu'><a href='https://rdrr.io/pkg/pheatmap/man/pheatmap.html'>pheatmap</a></span><span class='op'>(</span><span class='va'>scaled_mat</span>, color <span class='op'>=</span> <span class='va'>blueYellow</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-9-heatmap_files/figure-html5/unnamed-chunk-15-1.png" width="624" /></p> -</div> -<p><strong>Exercise</strong> -Make a heatmap with your own color palette</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='co'># TODO make the heatmap with your unique color palette</span></span></code></pre> -</div> -</div> -<h3 id="adding-annotations">Adding annotations</h3> -<p>We can help interpretation by adding row and column annotations to the plot. Let’s first add some row annotations showing if the name is a male or a female name. We start by making a data frame of the names and indicating if the name was from the male or female database.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>names_annotation</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/data.frame.html'>data.frame</a></span><span class='op'>(</span><span class='st'>"sex"</span> <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span><span class='op'>(</span><span class='st'>"female"</span>, <span class='fu'><a href='https://rdrr.io/r/base/nrow.html'>nrow</a></span><span class='op'>(</span><span class='va'>female_names_mat</span><span class='op'>)</span><span class='op'>)</span>,</span> -<span> <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span><span class='op'>(</span><span class='st'>"male"</span>, <span class='fu'><a href='https://rdrr.io/r/base/nrow.html'>nrow</a></span><span class='op'>(</span><span class='va'>male_names_mat</span><span class='op'>)</span><span class='op'>)</span><span class='op'>)</span>,</span> -<span> row.names <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/colnames.html'>rownames</a></span><span class='op'>(</span><span class='va'>female_names_mat</span><span class='op'>)</span>,</span> -<span> <span class='fu'><a href='https://rdrr.io/r/base/colnames.html'>rownames</a></span><span class='op'>(</span><span class='va'>male_names_mat</span><span class='op'>)</span><span class='op'>)</span><span class='op'>)</span></span> -<span></span> -<span><span class='fu'><a href='https://rdrr.io/r/utils/head.html'>head</a></span><span class='op'>(</span><span class='va'>names_annotation</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code> sex -Ava female -Olivia female -Emma female -Charlotte female -Harper female -Amelia female</code></pre> -</div> -<p>Note here the row names are the same as the row names of our matrix and we have one column named “sex”</p> -<p>We can now add this to the plot using the <code>annotation_row</code>. The key here is that the row names of your matrix must be the same as the row names of your data frame.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>blueYellow</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='st'>"#352A86"</span>, <span class='st'>"#343DAE"</span>, <span class='st'>"#0262E0"</span>, <span class='st'>"#1389D2"</span>, <span class='st'>"#2DB7A3"</span>,</span> -<span> <span class='st'>"#A5BE6A"</span>, <span class='st'>"#F8BA43"</span>, <span class='st'>"#F6DA23"</span>, <span class='st'>"#F8FA0D"</span><span class='op'>)</span></span> -<span></span> -<span><span class='fu'><a href='https://rdrr.io/pkg/pheatmap/man/pheatmap.html'>pheatmap</a></span><span class='op'>(</span><span class='va'>scaled_mat</span>,</span> -<span> color <span class='op'>=</span> <span class='va'>blueYellow</span>,</span> -<span> annotation_row <span class='op'>=</span> <span class='va'>names_annotation</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-9-heatmap_files/figure-html5/unnamed-chunk-18-1.png" width="624" /></p> -</div> -<p>Now you can see very clearly what names were in the female database and what names were in the male database. Again, we can change the default colors by using a <code>list</code> object. Here the names of the <code>list</code> must match the column names in your data frame and the names of the colors in the list must match the levels of that column.</p> -<p>We can either use the name of colors:</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>all_colors</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/list.html'>list</a></span><span class='op'>(</span><span class='st'>"sex"</span> <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='st'>"male"</span> <span class='op'>=</span> <span class='st'>"red"</span>, <span class='st'>"female"</span> <span class='op'>=</span> <span class='st'>"yellow"</span><span class='op'>)</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>all_colors</span></span></code></pre> -</div> -<pre><code>$sex - male female - "red" "yellow" </code></pre> -</div> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/pkg/pheatmap/man/pheatmap.html'>pheatmap</a></span><span class='op'>(</span><span class='va'>scaled_mat</span>,</span> -<span> color <span class='op'>=</span> <span class='va'>blueYellow</span>,</span> -<span> annotation_row <span class='op'>=</span> <span class='va'>names_annotation</span>,</span> -<span> annotation_colors <span class='op'>=</span> <span class='va'>all_colors</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-9-heatmap_files/figure-html5/unnamed-chunk-20-1.png" width="624" /></p> -</div> -<p>Or a HEX code:</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>all_colors</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/list.html'>list</a></span><span class='op'>(</span><span class='st'>"sex"</span> <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='st'>"male"</span> <span class='op'>=</span> <span class='st'>"#B067A3"</span>, <span class='st'>"female"</span> <span class='op'>=</span> <span class='st'>"#9C954D"</span><span class='op'>)</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>all_colors</span></span></code></pre> -</div> -<pre><code>$sex - male female -"#B067A3" "#9C954D" </code></pre> -</div> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/pkg/pheatmap/man/pheatmap.html'>pheatmap</a></span><span class='op'>(</span><span class='va'>scaled_mat</span>,</span> -<span> color <span class='op'>=</span> <span class='va'>blueYellow</span>,</span> -<span> annotation_row <span class='op'>=</span> <span class='va'>names_annotation</span>,</span> -<span> annotation_colors <span class='op'>=</span> <span class='va'>all_colors</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-9-heatmap_files/figure-html5/unnamed-chunk-22-1.png" width="624" /></p> -</div> -<p><strong>Exercise</strong> -Add your own colors to the row annotations</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='co'># TODO Add your own row annotaiton colors</span></span></code></pre> -</div> -</div> -<p>We can also add annotations to the columns using the same approach. Let’s load in some of the data I’ve compiled for the states</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>state_info</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/utils/read.table.html'>read.csv</a></span><span class='op'>(</span><span class='fu'><a href='https://here.r-lib.org//reference/here.html'>here</a></span><span class='op'>(</span><span class='st'>"class_7-9_data"</span>, <span class='st'>"state_info.csv"</span><span class='op'>)</span><span class='op'>)</span></span> -<span></span> -<span><span class='fu'><a href='https://rdrr.io/r/utils/head.html'>head</a></span><span class='op'>(</span><span class='va'>state_info</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code> State Location Size Density -1 Alabama South Middle 4 -2 Alaska West Small 6 -3 Arizona West Middle 4 -4 Arkansas South Middle 5 -5 California West Large 2 -6 Colorado West Middle 5</code></pre> -</div> -<p>This table has information about the location, the size (based on population as small middle or large) and the density (on a scale of 1-6).</p> -<p>We first will need to reformat so that the row names are the sates. Now the row names must be the same as the column names in the matrix.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>state_info</span> <span class='op'><-</span> <span class='fu'>tibble</span><span class='fu'>::</span><span class='fu'><a href='https://tibble.tidyverse.org/reference/rownames.html'>column_to_rownames</a></span><span class='op'>(</span><span class='va'>state_info</span>, <span class='st'>"State"</span><span class='op'>)</span></span> -<span></span> -<span></span> -<span><span class='fu'><a href='https://rdrr.io/r/utils/head.html'>head</a></span><span class='op'>(</span><span class='va'>state_info</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code> Location Size Density -Alabama South Middle 4 -Alaska West Small 6 -Arizona West Middle 4 -Arkansas South Middle 5 -California West Large 2 -Colorado West Middle 5</code></pre> -</div> -<p>We can now pass this data frame to <code>annotation_col</code> in <code>pheatmap</code></p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/pkg/pheatmap/man/pheatmap.html'>pheatmap</a></span><span class='op'>(</span><span class='va'>scaled_mat</span>,</span> -<span> color <span class='op'>=</span> <span class='va'>blueYellow</span>,</span> -<span> annotation_col <span class='op'>=</span> <span class='va'>state_info</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-9-heatmap_files/figure-html5/unnamed-chunk-26-1.png" width="624" /></p> -</div> -<p>You can see that we now have three levels of annotation on our heatmap. One thing to notice is that our population density is given as a scale of colors because it is seen as a numeric score. If we instead use this as a factor, this scale will go away:</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>state_info</span><span class='op'>$</span><span class='va'>Density</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/factor.html'>factor</a></span><span class='op'>(</span><span class='va'>state_info</span><span class='op'>$</span><span class='va'>Density</span><span class='op'>)</span></span> -<span></span> -<span><span class='fu'><a href='https://rdrr.io/pkg/pheatmap/man/pheatmap.html'>pheatmap</a></span><span class='op'>(</span><span class='va'>scaled_mat</span>,</span> -<span> color <span class='op'>=</span> <span class='va'>blueYellow</span>,</span> -<span> annotation_col <span class='op'>=</span> <span class='va'>state_info</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-9-heatmap_files/figure-html5/unnamed-chunk-27-1.png" width="624" /></p> -</div> -<p>As before, we can add in our own color palettes by using a named list where the list names correspond to the column names of our data frame. Here, I’m going to use the package <code>MetBrewer</code> to generate palettes for me. <a href="https://github.com/BlakeRMills/MetBrewer">You can see all possible palette options here</a></p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>location_colors</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/pkg/MetBrewer/man/met.brewer.html'>met.brewer</a></span><span class='op'>(</span><span class='st'>"Pissaro"</span>,</span> -<span> n <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/length.html'>length</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/unique.html'>unique</a></span><span class='op'>(</span><span class='va'>state_info</span><span class='op'>$</span><span class='va'>Location</span><span class='op'>)</span><span class='op'>)</span><span class='op'>)</span> <span class='op'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%>%</a></span></span> -<span> <span class='fu'><a href='https://rdrr.io/r/base/character.html'>as.character</a></span><span class='op'>(</span><span class='op'>)</span></span> -<span></span> -<span><span class='fu'><a href='https://rdrr.io/r/base/names.html'>names</a></span><span class='op'>(</span><span class='va'>location_colors</span><span class='op'>)</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/unique.html'>unique</a></span><span class='op'>(</span><span class='va'>state_info</span><span class='op'>$</span><span class='va'>Location</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>location_colors</span></span></code></pre> -</div> -<pre><code> South West New_England Midwest - "#4c825d" "#8cae9e" "#8dc7dc" "#0e2a4d" </code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>size_colors</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/pkg/MetBrewer/man/met.brewer.html'>met.brewer</a></span><span class='op'>(</span><span class='st'>"Navajo"</span>,</span> -<span> n <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/length.html'>length</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/unique.html'>unique</a></span><span class='op'>(</span><span class='va'>state_info</span><span class='op'>$</span><span class='va'>Size</span><span class='op'>)</span><span class='op'>)</span><span class='op'>)</span> <span class='op'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%>%</a></span></span> -<span> <span class='fu'><a href='https://rdrr.io/r/base/character.html'>as.character</a></span><span class='op'>(</span><span class='op'>)</span></span> -<span></span> -<span><span class='fu'><a href='https://rdrr.io/r/base/names.html'>names</a></span><span class='op'>(</span><span class='va'>size_colors</span><span class='op'>)</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/unique.html'>unique</a></span><span class='op'>(</span><span class='va'>state_info</span><span class='op'>$</span><span class='va'>Size</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>size_colors</span></span></code></pre> -</div> -<pre><code> Middle Small Large -"#660d20" "#e59a52" "#edce79" </code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>density_colors</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/pkg/MetBrewer/man/met.brewer.html'>met.brewer</a></span><span class='op'>(</span><span class='st'>"Juarez"</span>,</span> -<span> n <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/length.html'>length</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/levels.html'>levels</a></span><span class='op'>(</span><span class='va'>state_info</span><span class='op'>$</span><span class='va'>Density</span><span class='op'>)</span><span class='op'>)</span><span class='op'>)</span> <span class='op'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%>%</a></span></span> -<span> <span class='fu'><a href='https://rdrr.io/r/base/character.html'>as.character</a></span><span class='op'>(</span><span class='op'>)</span></span> -<span></span> -<span><span class='fu'><a href='https://rdrr.io/r/base/names.html'>names</a></span><span class='op'>(</span><span class='va'>density_colors</span><span class='op'>)</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/levels.html'>levels</a></span><span class='op'>(</span><span class='va'>state_info</span><span class='op'>$</span><span class='va'>Density</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>density_colors</span></span></code></pre> -</div> -<pre><code> 1 2 3 4 5 6 -"#a82203" "#208cc0" "#f1af3a" "#cf5e4e" "#637b31" "#003967" </code></pre> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>all_colors</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/list.html'>list</a></span><span class='op'>(</span><span class='st'>"Location"</span> <span class='op'>=</span> <span class='va'>location_colors</span>,</span> -<span> <span class='st'>"Size"</span> <span class='op'>=</span> <span class='va'>size_colors</span>,</span> -<span> <span class='st'>"Density"</span> <span class='op'>=</span> <span class='va'>density_colors</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>all_colors</span></span></code></pre> -</div> -<pre><code>$Location - South West New_England Midwest - "#4c825d" "#8cae9e" "#8dc7dc" "#0e2a4d" - -$Size - Middle Small Large -"#660d20" "#e59a52" "#edce79" - -$Density - 1 2 3 4 5 6 -"#a82203" "#208cc0" "#f1af3a" "#cf5e4e" "#637b31" "#003967" </code></pre> -</div> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/pkg/pheatmap/man/pheatmap.html'>pheatmap</a></span><span class='op'>(</span><span class='va'>scaled_mat</span>,</span> -<span> color <span class='op'>=</span> <span class='va'>blueYellow</span>,</span> -<span> annotation_col <span class='op'>=</span> <span class='va'>state_info</span>,</span> -<span> annotation_colors <span class='op'>=</span> <span class='va'>all_colors</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-9-heatmap_files/figure-html5/unnamed-chunk-29-1.png" width="624" /></p> -</div> -<p>Finally, we can add in the annotation from the rows as well. First we can add in the colors we had before</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>all_colors</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='va'>all_colors</span>, </span> -<span> <span class='fu'><a href='https://rdrr.io/r/base/list.html'>list</a></span><span class='op'>(</span><span class='st'>"sex"</span> <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='st'>"male"</span> <span class='op'>=</span> <span class='st'>"#B067A3"</span>, <span class='st'>"female"</span> <span class='op'>=</span> <span class='st'>"#9C954D"</span><span class='op'>)</span><span class='op'>)</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>all_colors</span></span></code></pre> -</div> -<pre><code>$Location - South West New_England Midwest - "#4c825d" "#8cae9e" "#8dc7dc" "#0e2a4d" - -$Size - Middle Small Large -"#660d20" "#e59a52" "#edce79" - -$Density - 1 2 3 4 5 6 -"#a82203" "#208cc0" "#f1af3a" "#cf5e4e" "#637b31" "#003967" - -$sex - male female -"#B067A3" "#9C954D" </code></pre> -</div> -<p>And then add the <code>names_annotation</code> back into the argument for <code>annotation_row</code></p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/pkg/pheatmap/man/pheatmap.html'>pheatmap</a></span><span class='op'>(</span><span class='va'>scaled_mat</span>,</span> -<span> color <span class='op'>=</span> <span class='va'>blueYellow</span>,</span> -<span> annotation_col <span class='op'>=</span> <span class='va'>state_info</span>,</span> -<span> annotation_row <span class='op'>=</span> <span class='va'>names_annotation</span>,</span> -<span> annotation_colors <span class='op'>=</span> <span class='va'>all_colors</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-9-heatmap_files/figure-html5/unnamed-chunk-31-1.png" width="624" data-distill-preview=1 /></p> -</div> -<p><strong>Exercise</strong> -What happens if <code>all_colors</code> only has some of the colors in the annotation data frames?</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='co'># TODO try making the heatmap with a list that only contains color arguments for</span></span> -<span><span class='co'># some of the columns in the annotation data frames</span></span></code></pre> -</div> -</div> -<p>Notice how the <code>annotation_colors</code> argument accepts the color arguments for both the rows and the columns. The important things about this argument to color the annotation is</p> -<ol type="1"> -<li>It must be a list</li> -<li>The names of the list must be in the columns for the <code>annotation_row</code> or <code>annotation_col</code> data frame</li> -<li>The names of the colors must match the values in the matching column</li> -<li>You do not need to have all columns present in your color list - any missing columns will be given the default colors</li> -</ol> -<p>There are also a few important aspects of the annotation data frames -1. The rownames of <code>annotation_row</code> must match the rownames of the matrix (although the order does not need to be the same) -2. The rownames of <code>annotation_col</code> must match the column names of the matrix (although the order does not need to be the same) -3. You can add as many annotations to the rows and columns that you want. You just need to include these as columns in either the <code>annotation_row</code> or <code>annotation_col</code> data frame.</p> -<h3 id="clustering">Clustering</h3> -<p>One aspect of the plots that you’ve probably noticed is dendrograms for both the rows and the columns. The clustering is done using <code>hclust</code>like we did in the clustering lecture.</p> -<p>Just like with our clustering methods we can cut the dendrogram based on an expected number of clusters to group either the states or the names. <code>pheatmap</code> has a function that uses <code>cutree</code> to identify clusters and physically separates these clusters with a white space using <code>cutree_rows</code> and <code>cutree_cols</code>. First, we can visualize three clusters of the names.</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/pkg/pheatmap/man/pheatmap.html'>pheatmap</a></span><span class='op'>(</span><span class='va'>scaled_mat</span>,</span> -<span> color <span class='op'>=</span> <span class='va'>blueYellow</span>,</span> -<span> annotation_col <span class='op'>=</span> <span class='va'>state_info</span>,</span> -<span> annotation_row <span class='op'>=</span> <span class='va'>names_annotation</span>,</span> -<span> annotation_colors <span class='op'>=</span> <span class='va'>all_colors</span>,</span> -<span> cutree_rows <span class='op'>=</span> <span class='fl'>3</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-9-heatmap_files/figure-html5/unnamed-chunk-33-1.png" width="624" /></p> -</div> -<p>Or we can visualize three clusters of the states</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/pkg/pheatmap/man/pheatmap.html'>pheatmap</a></span><span class='op'>(</span><span class='va'>scaled_mat</span>,</span> -<span> color <span class='op'>=</span> <span class='va'>blueYellow</span>,</span> -<span> annotation_col <span class='op'>=</span> <span class='va'>state_info</span>,</span> -<span> annotation_row <span class='op'>=</span> <span class='va'>names_annotation</span>,</span> -<span> annotation_colors <span class='op'>=</span> <span class='va'>all_colors</span>,</span> -<span> cutree_cols <span class='op'>=</span> <span class='fl'>3</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-9-heatmap_files/figure-html5/unnamed-chunk-34-1.png" width="624" /></p> -</div> -<p>We could even visuzalize both at once</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/pkg/pheatmap/man/pheatmap.html'>pheatmap</a></span><span class='op'>(</span><span class='va'>scaled_mat</span>,</span> -<span> color <span class='op'>=</span> <span class='va'>blueYellow</span>,</span> -<span> annotation_col <span class='op'>=</span> <span class='va'>state_info</span>,</span> -<span> annotation_row <span class='op'>=</span> <span class='va'>names_annotation</span>,</span> -<span> annotation_colors <span class='op'>=</span> <span class='va'>all_colors</span>,</span> -<span> cutree_rows <span class='op'>=</span> <span class='fl'>3</span>,</span> -<span> cutree_cols <span class='op'>=</span> <span class='fl'>3</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-9-heatmap_files/figure-html5/unnamed-chunk-35-1.png" width="624" /></p> -</div> -<p><strong>Exercise</strong> -Try making the heatmap with different numbers of clusters. What number of clusters makes the most sense?</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='co'># TODO Make the heatmap cutting to make different numbers of clusters</span></span></code></pre> -</div> -</div> -<p>As with using <code>cutree</code> ourselves, you can pick any number of clusters to visualize in this way.</p> -<p>In addition to visualizing these clusters, we can also pull the clustering information out of the heatmap object. First we can save the plot to a variable. Right now we are setting <code>silent</code> to <code>TRUE</code> so the heatmap isn’t drawn</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>heatmap</span> <span class='op'><-</span> <span class='fu'><a href='https://rdrr.io/pkg/pheatmap/man/pheatmap.html'>pheatmap</a></span><span class='op'>(</span><span class='va'>scaled_mat</span>,</span> -<span> color <span class='op'>=</span> <span class='va'>blueYellow</span>,</span> -<span> annotation_col <span class='op'>=</span> <span class='va'>state_info</span>,</span> -<span> annotation_row <span class='op'>=</span> <span class='va'>names_annotation</span>,</span> -<span> annotation_colors <span class='op'>=</span> <span class='va'>all_colors</span>,</span> -<span> cutree_rows <span class='op'>=</span> <span class='fl'>3</span>,</span> -<span> cutree_cols <span class='op'>=</span> <span class='fl'>3</span>,</span> -<span> silent <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span></span> -<span></span> -<span><span class='fu'><a href='https://rdrr.io/r/base/names.html'>names</a></span><span class='op'>(</span><span class='va'>heatmap</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code>[1] "tree_row" "tree_col" "kmeans" "gtable" </code></pre> -</div> -<p>The <code>hclust</code> object for the row are in <code>tree_row</code> and the <code>hclust</code> object for the column are in <code>tree_col</code></p> -<p>We can plot just the dendrogram as we did previously</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/graphics/plot.default.html'>plot</a></span><span class='op'>(</span><span class='va'>heatmap</span><span class='op'>$</span><span class='va'>tree_col</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-9-heatmap_files/figure-html5/unnamed-chunk-38-1.png" width="624" /></p> -</div> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/graphics/plot.default.html'>plot</a></span><span class='op'>(</span><span class='va'>heatmap</span><span class='op'>$</span><span class='va'>tree_row</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-9-heatmap_files/figure-html5/unnamed-chunk-39-1.png" width="1152" /></p> -</div> -<p>We can also now use <code>cutree</code> on these <code>hclust</code> objects in the exact same way we did in the clustering lecture to pull out clusters</p> -<p>Columns:</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/stats/cutree.html'>cutree</a></span><span class='op'>(</span>tree <span class='op'>=</span> <span class='va'>heatmap</span><span class='op'>$</span><span class='va'>tree_col</span>, k <span class='op'>=</span> <span class='fl'>3</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code> Alabama Alaska Arizona Arkansas California - 1 2 3 1 3 - Colorado Connecticut Delaware Florida Georgia - 2 3 3 3 1 - Hawaii Idaho Illinois Indiana Iowa - 3 2 3 2 2 - Kansas Kentucky Louisiana Maine Maryland - 2 1 1 2 3 </code></pre> -</div> -<p>Rows:</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/r/stats/cutree.html'>cutree</a></span><span class='op'>(</span>tree <span class='op'>=</span> <span class='va'>heatmap</span><span class='op'>$</span><span class='va'>tree_row</span>, k <span class='op'>=</span> <span class='fl'>3</span><span class='op'>)</span></span></code></pre> -</div> -<pre><code> William James John Elijah Noah Liam Mason - 1 1 2 1 1 1 2 - Oliver Henry Jackson Samuel Jaxon Asher Grayson - 1 2 2 3 3 2 2 - Levi Michael Carter Benjamin Charles Wyatt Thomas - 2 2 2 2 3 2 3 - Aiden Luke David Owen Daniel Logan Joseph - 3 3 3 2 2 2 3 - Lucas Joshua Jack Alexander Maverick Gabriel Ethan - 2 3 2 2 3 3 2 - Eli Isaac Hunter Ezra Theodore Ava Olivia - 3 3 3 3 2 1 1 - Emma Charlotte Harper Amelia Elizabeth Evelyn Isabella - 1 1 2 1 3 2 2 - Ella Avery Abigail Sophia Layla Mia Madison - 3 3 3 2 3 2 3 - Lily Ellie Nova Eleanor Zoey Brooklyn Riley - 3 3 3 3 3 3 3 - Nora Aria Mila Stella Natalie Luna Penelope - 3 3 3 3 3 3 3 - Aurora Claire - 3 3 </code></pre> -</div> -<p><strong>Exercise</strong> -What names are the most similar? What states are the most similar?</p> -<p>Another option is to remove the clustering all together using <code>cluster_rows</code> and <code>cluster_cols</code></p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/pkg/pheatmap/man/pheatmap.html'>pheatmap</a></span><span class='op'>(</span><span class='va'>scaled_mat</span>,</span> -<span> color <span class='op'>=</span> <span class='va'>blueYellow</span>,</span> -<span> annotation_col <span class='op'>=</span> <span class='va'>state_info</span>,</span> -<span> annotation_row <span class='op'>=</span> <span class='va'>names_annotation</span>,</span> -<span> annotation_colors <span class='op'>=</span> <span class='va'>all_colors</span>,</span> -<span> cluster_rows <span class='op'>=</span> <span class='cn'>FALSE</span>,</span> -<span> cluster_cols <span class='op'>=</span> <span class='cn'>FALSE</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-9-heatmap_files/figure-html5/unnamed-chunk-42-1.png" width="624" /></p> -</div> -<p>If we don’t cluster, the order of the rows and columns is taken directly from the order of the matrix. We can change to alphabetical order as follows</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>scaled_mat_ord</span> <span class='op'><-</span> <span class='va'>scaled_mat</span><span class='op'>[</span><span class='fu'><a href='https://rdrr.io/r/base/order.html'>order</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/colnames.html'>rownames</a></span><span class='op'>(</span><span class='va'>scaled_mat</span><span class='op'>)</span><span class='op'>)</span>, <span class='op'>]</span></span> -<span></span> -<span><span class='fu'><a href='https://rdrr.io/pkg/pheatmap/man/pheatmap.html'>pheatmap</a></span><span class='op'>(</span><span class='va'>scaled_mat_ord</span>,</span> -<span> color <span class='op'>=</span> <span class='va'>blueYellow</span>,</span> -<span> annotation_col <span class='op'>=</span> <span class='va'>state_info</span>,</span> -<span> annotation_row <span class='op'>=</span> <span class='va'>names_annotation</span>,</span> -<span> annotation_colors <span class='op'>=</span> <span class='va'>all_colors</span>,</span> -<span> cluster_rows <span class='op'>=</span> <span class='cn'>FALSE</span>,</span> -<span> cluster_cols <span class='op'>=</span> <span class='cn'>FALSE</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-9-heatmap_files/figure-html5/unnamed-chunk-43-1.png" width="624" /></p> -</div> -<p>We could even order the states by the density</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='va'>state_info</span> <span class='op'><-</span> <span class='va'>state_info</span> <span class='op'><a href='https://magrittr.tidyverse.org/reference/pipe.html'>%>%</a></span></span> -<span> <span class='fu'>dplyr</span><span class='fu'>::</span><span class='fu'><a href='https://dplyr.tidyverse.org/reference/arrange.html'>arrange</a></span><span class='op'>(</span><span class='va'>Density</span><span class='op'>)</span></span> -<span></span> -<span><span class='va'>scaled_mat_ord</span> <span class='op'><-</span> <span class='va'>scaled_mat</span><span class='op'>[</span> , <span class='fu'><a href='https://rdrr.io/r/base/order.html'>order</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/match.html'>match</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/colnames.html'>colnames</a></span><span class='op'>(</span><span class='va'>scaled_mat</span><span class='op'>)</span>,</span> -<span> <span class='fu'><a href='https://rdrr.io/r/base/colnames.html'>rownames</a></span><span class='op'>(</span><span class='va'>state_info</span><span class='op'>)</span><span class='op'>)</span><span class='op'>)</span><span class='op'>]</span></span> -<span></span> -<span><span class='fu'><a href='https://rdrr.io/pkg/pheatmap/man/pheatmap.html'>pheatmap</a></span><span class='op'>(</span><span class='va'>scaled_mat_ord</span>,</span> -<span> color <span class='op'>=</span> <span class='va'>blueYellow</span>,</span> -<span> annotation_col <span class='op'>=</span> <span class='va'>state_info</span>,</span> -<span> annotation_row <span class='op'>=</span> <span class='va'>names_annotation</span>,</span> -<span> annotation_colors <span class='op'>=</span> <span class='va'>all_colors</span>,</span> -<span> cluster_rows <span class='op'>=</span> <span class='cn'>FALSE</span>,</span> -<span> cluster_cols <span class='op'>=</span> <span class='cn'>FALSE</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-9-heatmap_files/figure-html5/unnamed-chunk-44-1.png" width="624" /></p> -</div> -<p><strong>Exercise</strong> -Order the heatmap by density, but cluster the names</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='co'># TODO order the heatmap by density but cluster the names</span></span></code></pre> -</div> -</div> -<p><strong>Exercise</strong> -Order the heatmap by location, but cluster the names</p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='co'># TODO order the heatmap by location and cluster the names</span></span></code></pre> -</div> -</div> -<h3 id="remove-column-and-row-names">Remove column and row names</h3> -<p>One other helpful way to adjust your heatmap is to remove the row and column names. You can control if the row and column names are seen using <code>show_rownames</code> and <code>show_colnames</code></p> -<div class="layout-chunk" data-layout="l-body"> -<div class="sourceCode"> -<pre class="sourceCode r"><code class="sourceCode r"><span><span class='fu'><a href='https://rdrr.io/pkg/pheatmap/man/pheatmap.html'>pheatmap</a></span><span class='op'>(</span><span class='va'>scaled_mat</span>,</span> -<span> color <span class='op'>=</span> <span class='va'>blueYellow</span>,</span> -<span> annotation_col <span class='op'>=</span> <span class='va'>state_info</span>,</span> -<span> annotation_row <span class='op'>=</span> <span class='va'>names_annotation</span>,</span> -<span> annotation_colors <span class='op'>=</span> <span class='va'>all_colors</span>,</span> -<span> show_rownames <span class='op'>=</span> <span class='cn'>FALSE</span>,</span> -<span> show_colnames <span class='op'>=</span> <span class='cn'>FALSE</span><span class='op'>)</span></span></code></pre> -</div> -<p><img src="class-9-heatmap_files/figure-html5/unnamed-chunk-47-1.png" width="624" /></p> -</div> -<h3 id="other-aesthetics">Other aesthetics</h3> -<p>There are many possible adjustments you can make, we’ve just gone through the adjustments I use the most often. To see all possible arguments see <code>?pheatmap</code></p> -<h2 id="acknowldgements-and-additional-references">Acknowldgements and additional references</h2> -<p>The content of this class borrows heavily from previous tutorials:</p> -<p><a href="https://davetang.org/muse/2018/05/15/making-a-heatmap-in-r-with-the-pheatmap-package/">making heatmaps</a></p> -<h2 id="im-a-biologist-why-should-i-care">I’m a biologist, why should I care?</h2> -<ul> -<li>Heatmaps are common tools to visualize data -<ul> -<li>They are frequently used for sequencing data - RNA-seq, scRNA-seq, ATAC-seq</li> -<li>They are a good way of showing lots of data</li> -<li>Because of the scaling, they can be misleading so it’s good to know how to interpret them</li> -</ul></li> -<li>You will likely encounter heatmaps in papers that you read. My goal is to improve your understanding of the techniques so you can better interpret them on your own</li> -</ul> -<div class="sourceCode" id="cb20"><pre class="sourceCode r distill-force-highlighting-css"><code class="sourceCode r"></code></pre></div> -<!--radix_placeholder_article_footer--> -<!--/radix_placeholder_article_footer--> -</div> - -<div class="d-appendix"> -</div> - -<!-- dynamically load mathjax for compatibility with self-contained --> -<script> - (function () { - var script = document.createElement("script"); - script.type = "text/javascript"; - script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"; - document.getElementsByTagName("head")[0].appendChild(script); - })(); -</script> - -<!--radix_placeholder_site_after_body--> -<!--/radix_placeholder_site_after_body--> -<!--radix_placeholder_appendices--> -<div class="appendix-bottom"></div> -<!--/radix_placeholder_appendices--> -<!--radix_placeholder_navigation_after_body--> -<!--/radix_placeholder_navigation_after_body--> - -</body> - -</html> diff --git a/_posts/2022-11-10-class-7-matricies/class7_matricies.Rmd b/_posts/2023-12-08-class-8-matricies/class8_matricies.Rmd similarity index 94% rename from _posts/2022-11-10-class-7-matricies/class7_matricies.Rmd rename to _posts/2023-12-08-class-8-matricies/class8_matricies.Rmd index 6425eae..1afea85 100644 --- a/_posts/2022-11-10-class-7-matricies/class7_matricies.Rmd +++ b/_posts/2023-12-08-class-8-matricies/class8_matricies.Rmd @@ -1,5 +1,5 @@ --- -title: "Class 7: Introduction to matricies" +title: "Class 8: Introduction to matricies" author: - name: "Kristen Wells" url: https://github.com/kwells4 @@ -18,7 +18,7 @@ knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE) ``` -*The Rmarkdown for this class is [on github](https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2022-11-10-class-7-matricies/class7_matricies.Rmd)* +*The Rmarkdown for this class is [on github](https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2023-12-08-class-8-matricies/class8_matricies.Rmd)* ## Goals for this class * Learn what is a matrix @@ -38,7 +38,7 @@ Before we get started, let's download all of the files you will need for the nex ```{r} # conditionally download all of the files used in rmarkdown from github -source("https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2022-11-10-class-7-matricies/download_files.R") +source("https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2023-12-08-class-8-matricies/download_files.R") ``` ## What is a matrix? @@ -124,7 +124,7 @@ What value is in row 2 and column 3 of `new_mat`? ```{r} # TODO find the value in the matrix at row 2 and column 3 -new_mat[2,3] + ``` **If we can make a matrix from a data frame, what's the difference?** @@ -261,7 +261,7 @@ Multiply, subtract, and divide the two matrices `M1` and `M2` ```{r} # TODO multiply, subtract and divide M1 and M2 -M1 * M2 + ``` ### Matrix multiplication @@ -295,7 +295,7 @@ For this next section, let's use some data that I downloaded from the social sec We can now read in the data and convert it to a matrix ```{r} -names_mat <- read.csv(here("class_7-9_data", "boy_name_counts.csv"), +names_mat <- read.csv(here("class_8-10_data", "boy_name_counts.csv"), row.names = 1) %>% as.matrix() @@ -368,7 +368,7 @@ Find the maximum value in the for "Noah" ```{r} # TODO Find the maximum value for Noah and the whole matrix -max(names_mat["Noah",]) + ``` We can also find the mean, median, and standard deviation of any part of the matrix @@ -561,18 +561,7 @@ Can you make the same plot as above but use our normalized values? ```{r} # TODO make plot above with normalized values # Hint start with normalized_dat -pivot_columns <- colnames(normalized_dat) -normalized_mat <- normalized_dat %>% - data.frame %>% - rownames_to_column("name") %>% - pivot_longer(cols = all_of(pivot_columns), - values_to = "count", names_to = "state") - -ggplot(normalized_mat, aes(x = name, y = count, fill = name)) + - geom_violin() + - theme(axis.text.x = element_text(angle = 90, - vjust = 0.5, hjust=1)) ``` ## I'm a biologist, why should I care? diff --git a/_posts/2022-11-10-class-7-matricies/class7_matricies_files/anchor-4.2.2/anchor.min.js b/_posts/2023-12-08-class-8-matricies/class8_matricies_files/anchor-4.2.2/anchor.min.js similarity index 100% rename from _posts/2022-11-10-class-7-matricies/class7_matricies_files/anchor-4.2.2/anchor.min.js rename to _posts/2023-12-08-class-8-matricies/class8_matricies_files/anchor-4.2.2/anchor.min.js diff --git a/_posts/2022-11-10-class-7-matricies/class7_matricies_files/bowser-1.9.3/bowser.min.js b/_posts/2023-12-08-class-8-matricies/class8_matricies_files/bowser-1.9.3/bowser.min.js similarity index 100% rename from _posts/2022-11-10-class-7-matricies/class7_matricies_files/bowser-1.9.3/bowser.min.js rename to _posts/2023-12-08-class-8-matricies/class8_matricies_files/bowser-1.9.3/bowser.min.js diff --git a/_posts/2022-11-10-class-7-matricies/class7_matricies_files/distill-2.2.21/template.v2.js b/_posts/2023-12-08-class-8-matricies/class8_matricies_files/distill-2.2.21/template.v2.js similarity index 100% rename from _posts/2022-11-10-class-7-matricies/class7_matricies_files/distill-2.2.21/template.v2.js rename to _posts/2023-12-08-class-8-matricies/class8_matricies_files/distill-2.2.21/template.v2.js diff --git a/_posts/2022-11-10-class-7-matricies/class7_matricies_files/figure-html5/unnamed-chunk-63-1.png b/_posts/2023-12-08-class-8-matricies/class8_matricies_files/figure-html5/unnamed-chunk-63-1.png similarity index 100% rename from _posts/2022-11-10-class-7-matricies/class7_matricies_files/figure-html5/unnamed-chunk-63-1.png rename to _posts/2023-12-08-class-8-matricies/class8_matricies_files/figure-html5/unnamed-chunk-63-1.png diff --git a/_posts/2022-11-10-class-7-matricies/class7_matricies_files/header-attrs-2.14/header-attrs.js b/_posts/2023-12-08-class-8-matricies/class8_matricies_files/header-attrs-2.14/header-attrs.js similarity index 100% rename from _posts/2022-11-10-class-7-matricies/class7_matricies_files/header-attrs-2.14/header-attrs.js rename to _posts/2023-12-08-class-8-matricies/class8_matricies_files/header-attrs-2.14/header-attrs.js diff --git a/_posts/2022-11-10-class-7-matricies/class7_matricies_files/jquery-3.6.0/jquery-3.6.0.js b/_posts/2023-12-08-class-8-matricies/class8_matricies_files/jquery-3.6.0/jquery-3.6.0.js similarity index 100% rename from _posts/2022-11-10-class-7-matricies/class7_matricies_files/jquery-3.6.0/jquery-3.6.0.js rename to _posts/2023-12-08-class-8-matricies/class8_matricies_files/jquery-3.6.0/jquery-3.6.0.js diff --git a/_posts/2022-11-10-class-7-matricies/class7_matricies_files/jquery-3.6.0/jquery-3.6.0.min.js b/_posts/2023-12-08-class-8-matricies/class8_matricies_files/jquery-3.6.0/jquery-3.6.0.min.js similarity index 100% rename from _posts/2022-11-10-class-7-matricies/class7_matricies_files/jquery-3.6.0/jquery-3.6.0.min.js rename to _posts/2023-12-08-class-8-matricies/class8_matricies_files/jquery-3.6.0/jquery-3.6.0.min.js diff --git a/_posts/2022-11-10-class-7-matricies/class7_matricies_files/jquery-3.6.0/jquery-3.6.0.min.map b/_posts/2023-12-08-class-8-matricies/class8_matricies_files/jquery-3.6.0/jquery-3.6.0.min.map similarity index 100% rename from _posts/2022-11-10-class-7-matricies/class7_matricies_files/jquery-3.6.0/jquery-3.6.0.min.map rename to _posts/2023-12-08-class-8-matricies/class8_matricies_files/jquery-3.6.0/jquery-3.6.0.min.map diff --git a/_posts/2022-11-10-class-7-matricies/class7_matricies_files/popper-2.6.0/popper.min.js b/_posts/2023-12-08-class-8-matricies/class8_matricies_files/popper-2.6.0/popper.min.js similarity index 100% rename from _posts/2022-11-10-class-7-matricies/class7_matricies_files/popper-2.6.0/popper.min.js rename to _posts/2023-12-08-class-8-matricies/class8_matricies_files/popper-2.6.0/popper.min.js diff --git a/_posts/2022-11-10-class-7-matricies/class7_matricies_files/tippy-6.2.7/tippy-bundle.umd.min.js b/_posts/2023-12-08-class-8-matricies/class8_matricies_files/tippy-6.2.7/tippy-bundle.umd.min.js similarity index 100% rename from _posts/2022-11-10-class-7-matricies/class7_matricies_files/tippy-6.2.7/tippy-bundle.umd.min.js rename to _posts/2023-12-08-class-8-matricies/class8_matricies_files/tippy-6.2.7/tippy-bundle.umd.min.js diff --git a/_posts/2022-11-10-class-7-matricies/class7_matricies_files/tippy-6.2.7/tippy-light-border.css b/_posts/2023-12-08-class-8-matricies/class8_matricies_files/tippy-6.2.7/tippy-light-border.css similarity index 100% rename from _posts/2022-11-10-class-7-matricies/class7_matricies_files/tippy-6.2.7/tippy-light-border.css rename to _posts/2023-12-08-class-8-matricies/class8_matricies_files/tippy-6.2.7/tippy-light-border.css diff --git a/_posts/2022-11-10-class-7-matricies/class7_matricies_files/tippy-6.2.7/tippy.css b/_posts/2023-12-08-class-8-matricies/class8_matricies_files/tippy-6.2.7/tippy.css similarity index 100% rename from _posts/2022-11-10-class-7-matricies/class7_matricies_files/tippy-6.2.7/tippy.css rename to _posts/2023-12-08-class-8-matricies/class8_matricies_files/tippy-6.2.7/tippy.css diff --git a/_posts/2022-11-10-class-7-matricies/class7_matricies_files/tippy-6.2.7/tippy.umd.min.js b/_posts/2023-12-08-class-8-matricies/class8_matricies_files/tippy-6.2.7/tippy.umd.min.js similarity index 100% rename from _posts/2022-11-10-class-7-matricies/class7_matricies_files/tippy-6.2.7/tippy.umd.min.js rename to _posts/2023-12-08-class-8-matricies/class8_matricies_files/tippy-6.2.7/tippy.umd.min.js diff --git a/_posts/2022-11-10-class-7-matricies/class7_matricies_files/webcomponents-2.0.0/webcomponents.js b/_posts/2023-12-08-class-8-matricies/class8_matricies_files/webcomponents-2.0.0/webcomponents.js similarity index 100% rename from _posts/2022-11-10-class-7-matricies/class7_matricies_files/webcomponents-2.0.0/webcomponents.js rename to _posts/2023-12-08-class-8-matricies/class8_matricies_files/webcomponents-2.0.0/webcomponents.js diff --git a/_posts/2022-11-10-class-7-matricies/download_files.R b/_posts/2023-12-08-class-8-matricies/download_files.R similarity index 94% rename from _posts/2022-11-10-class-7-matricies/download_files.R rename to _posts/2023-12-08-class-8-matricies/download_files.R index 2304572..1fe6316 100644 --- a/_posts/2022-11-10-class-7-matricies/download_files.R +++ b/_posts/2023-12-08-class-8-matricies/download_files.R @@ -1,5 +1,5 @@ library(here) -data_dir <- here("class_7-9_data") +data_dir <- here("class_8-10_data") dir.create(data_dir, showWarnings = FALSE) files_to_dl <- list( diff --git a/_posts/2022-11-10-class-7-matricies/img/matrix_image.jpg b/_posts/2023-12-08-class-8-matricies/img/matrix_image.jpg similarity index 100% rename from _posts/2022-11-10-class-7-matricies/img/matrix_image.jpg rename to _posts/2023-12-08-class-8-matricies/img/matrix_image.jpg diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering.Rmd b/_posts/2023-12-11-class-9-clustering/class-9-clustering.Rmd similarity index 94% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering.Rmd rename to _posts/2023-12-11-class-9-clustering/class-9-clustering.Rmd index 984b842..1a148cd 100644 --- a/_posts/2022-11-15-class-8-clustering/class-8-clustering.Rmd +++ b/_posts/2023-12-11-class-9-clustering/class-9-clustering.Rmd @@ -1,5 +1,5 @@ --- -title: "Class 8: Introduction to clustering and PCA" +title: "Class 9: Introduction to clustering and PCA" author: - name: "Kristen Wells" url: https://github.com/kwells4 @@ -16,7 +16,7 @@ draft: false knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE) ``` -*The Rmarkdown for this class is [on github](https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2022-11-15-class-8-clustering/class-8-clustering.Rmd)* +*The Rmarkdown for this class is [on github](https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2023-12-11-class-9-clustering/class-9-clustering.Rmd)* ## Goals for this class * Learn about different types of clustering @@ -38,7 +38,7 @@ Before we get started, let's download all of the files you will need for the nex ```{r} # conditionally download all of the files used in rmarkdown from github -source("https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2022-11-10-class-7-matricies/download_files.R") +source("https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2023-12-08-class-8-matricies/download_files.R") ``` ## What is clustering @@ -60,7 +60,7 @@ k-means clustering uses the distance between points as a measure of similarity. Consider the dataset below ```{r, echo = FALSE} -knitr::include_graphics("https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2022-11-15-class-8-clustering/img/unclustered.jpg") +knitr::include_graphics("https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2023-12-11-class-9-clustering/img/unclustered.jpg") ``` In the figure above you would probably say that there are 3 clear clusters. Let's start by giving a k of 3. @@ -69,7 +69,7 @@ First the centroids are placed randomly and the distance from each point to each ```{r, echo = FALSE} -knitr::include_graphics("https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2022-11-15-class-8-clustering/img/clustering1.jpg") +knitr::include_graphics("https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2023-12-11-class-9-clustering/img/clustering1.jpg") ``` Next, the mean distance from all points belonging to a cluster to that cluser's centroid is calculated. @@ -79,7 +79,7 @@ Then, the "centroids" are moved to that mean value that was calculated and the p This is done until the distance between the centroid and the nearest points doesn't change. All points that are closest to the centroid are placed in that cluster ```{r, echo = FALSE} -knitr::include_graphics("https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2022-11-15-class-8-clustering/img/final_clustering.jpg") +knitr::include_graphics("https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2023-12-11-class-9-clustering/img/final_clustering.jpg") ``` Let's try clustering on our own example: @@ -162,17 +162,7 @@ Repeat the process above, but compute for 4 clusters ```{r} # TODO find k = 4 clusters -set.seed(123) -kres <- kmeans(test_data, centers = 4, nstart = 25) - -plot_df <- cbind(test_data, "cluster" = kres$cluster) - - -plot_df$cluster <- factor(plot_df$cluster) -plot_df$cluster -ggplot(plot_df, aes(x = x_val, y = y_val, color = cluster)) + - geom_point() ``` @@ -223,13 +213,13 @@ Basically, hierarchical clustering starts by treating each sample as a "cluster" Steps 1 and two are repeated until only one large cluster remains ```{r, echo = FALSE} -knitr::include_graphics("https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2022-11-15-class-8-clustering/img/Hierarchical-clustering-3-1.jpg") +knitr::include_graphics("https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2023-12-11-class-9-clustering/img/Hierarchical-clustering-3-1.jpg") ``` Each merging step is used to build a dendrogram ```{r, echo = FALSE} -knitr::include_graphics("https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2022-11-15-class-8-clustering/img/dendrogram.jpg") +knitr::include_graphics("https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2023-12-11-class-9-clustering/img/dendrogram.jpg") ``` To get an idea of how this is working, we can use the same toy data we generated above @@ -292,13 +282,7 @@ Repeat finding clusters using different points on the tree. For example, what if ```{r} # TODO repeat finding clusters with different numbers of clusters -new_clusters <- cutree(hc, k = 4) -plot_df <- cbind(test_data, "cluster" = new_clusters) - -plot_df$cluster <- factor(plot_df$cluster) -ggplot2::ggplot(plot_df, aes(x = x_val, y = y_val, color = cluster)) + - geom_point(size = 2) ``` **Question** @@ -316,7 +300,7 @@ The overall goal of PCA is to find linear models that best fit the data. Let's walk through PCA (following the tutorial in Modern Statistics for Modern Biology) with only Alabama and Colorado to see how it works. ```{r} -names_mat <- read.csv(here("class_7-9_data", "boy_name_counts.csv"), +names_mat <- read.csv(here("class_8-10_data", "boy_name_counts.csv"), row.names = 1) %>% as.matrix() @@ -506,20 +490,6 @@ Try with 4 clusters, what names cluster together? ```{r} # TODO Repeat with 4 clusters and repeat what names cluster together -set.seed(123) -four_clusters <- kmeans(normalized_mat, centers = 4, nstart = 25) - -four_clusters$cluster - -plot_data <- cbind(pca_vals, "cluster" = four_clusters$cluster) - -plot_data$cluster <- factor(plot_data$cluster) - -plot_data %>% - tibble::rownames_to_column("name") %>% - ggplot(aes(x = PC1, y = PC2, color = cluster, label = name)) + - geom_point(size = 2) + - geom_text(hjust=1, vjust=0) ``` diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/anchor-4.2.2/anchor.min.js b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/anchor-4.2.2/anchor.min.js similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/anchor-4.2.2/anchor.min.js rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/anchor-4.2.2/anchor.min.js diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/bowser-1.9.3/bowser.min.js b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/bowser-1.9.3/bowser.min.js similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/bowser-1.9.3/bowser.min.js rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/bowser-1.9.3/bowser.min.js diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/distill-2.2.21/template.v2.js b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/distill-2.2.21/template.v2.js similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/distill-2.2.21/template.v2.js rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/distill-2.2.21/template.v2.js diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-11-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-11-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-11-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-11-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-12-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-12-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-12-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-12-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-14-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-14-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-14-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-14-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-15-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-15-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-15-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-15-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-16-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-16-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-16-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-16-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-17-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-17-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-17-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-17-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-18-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-18-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-18-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-18-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-19-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-19-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-19-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-19-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-20-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-20-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-20-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-20-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-22-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-22-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-22-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-22-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-23-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-23-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-23-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-23-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-24-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-24-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-24-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-24-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-26-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-26-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-26-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-26-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-28-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-28-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-28-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-28-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-30-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-30-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-30-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-30-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-32-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-32-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-32-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-32-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-33-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-33-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-33-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-33-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-35-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-35-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-35-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-35-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-36-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-36-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-36-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-36-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-37-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-37-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-37-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-37-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-38-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-38-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-38-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-38-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-39-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-39-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-39-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-39-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-40-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-40-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-40-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-40-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-41-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-41-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-41-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-41-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-42-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-42-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-42-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-42-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-43-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-43-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-43-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-43-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-44-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-44-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-44-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-44-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-45-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-45-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-45-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-45-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-46-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-46-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-46-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-46-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-47-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-47-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-47-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-47-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-48-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-48-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-48-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-48-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-49-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-49-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-49-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-49-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-50-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-50-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-50-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-50-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-51-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-51-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-51-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-51-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-6-1.png b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-6-1.png similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/figure-html5/unnamed-chunk-6-1.png rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/figure-html5/unnamed-chunk-6-1.png diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/header-attrs-2.14/header-attrs.js b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/header-attrs-2.14/header-attrs.js similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/header-attrs-2.14/header-attrs.js rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/header-attrs-2.14/header-attrs.js diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/jquery-3.6.0/jquery-3.6.0.js b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/jquery-3.6.0/jquery-3.6.0.js similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/jquery-3.6.0/jquery-3.6.0.js rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/jquery-3.6.0/jquery-3.6.0.js diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/jquery-3.6.0/jquery-3.6.0.min.js b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/jquery-3.6.0/jquery-3.6.0.min.js similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/jquery-3.6.0/jquery-3.6.0.min.js rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/jquery-3.6.0/jquery-3.6.0.min.js diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/jquery-3.6.0/jquery-3.6.0.min.map b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/jquery-3.6.0/jquery-3.6.0.min.map similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/jquery-3.6.0/jquery-3.6.0.min.map rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/jquery-3.6.0/jquery-3.6.0.min.map diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/popper-2.6.0/popper.min.js b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/popper-2.6.0/popper.min.js similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/popper-2.6.0/popper.min.js rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/popper-2.6.0/popper.min.js diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/tippy-6.2.7/tippy-bundle.umd.min.js b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/tippy-6.2.7/tippy-bundle.umd.min.js similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/tippy-6.2.7/tippy-bundle.umd.min.js rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/tippy-6.2.7/tippy-bundle.umd.min.js diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/tippy-6.2.7/tippy-light-border.css b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/tippy-6.2.7/tippy-light-border.css similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/tippy-6.2.7/tippy-light-border.css rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/tippy-6.2.7/tippy-light-border.css diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/tippy-6.2.7/tippy.css b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/tippy-6.2.7/tippy.css similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/tippy-6.2.7/tippy.css rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/tippy-6.2.7/tippy.css diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/tippy-6.2.7/tippy.umd.min.js b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/tippy-6.2.7/tippy.umd.min.js similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/tippy-6.2.7/tippy.umd.min.js rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/tippy-6.2.7/tippy.umd.min.js diff --git a/_posts/2022-11-15-class-8-clustering/class-8-clustering_files/webcomponents-2.0.0/webcomponents.js b/_posts/2023-12-11-class-9-clustering/class-9-clustering_files/webcomponents-2.0.0/webcomponents.js similarity index 100% rename from _posts/2022-11-15-class-8-clustering/class-8-clustering_files/webcomponents-2.0.0/webcomponents.js rename to _posts/2023-12-11-class-9-clustering/class-9-clustering_files/webcomponents-2.0.0/webcomponents.js diff --git a/_posts/2022-11-15-class-8-clustering/img/Hierarchical-clustering-3-1.jpg b/_posts/2023-12-11-class-9-clustering/img/Hierarchical-clustering-3-1.jpg similarity index 100% rename from _posts/2022-11-15-class-8-clustering/img/Hierarchical-clustering-3-1.jpg rename to _posts/2023-12-11-class-9-clustering/img/Hierarchical-clustering-3-1.jpg diff --git a/_posts/2022-11-15-class-8-clustering/img/clustering1.jpg b/_posts/2023-12-11-class-9-clustering/img/clustering1.jpg similarity index 100% rename from _posts/2022-11-15-class-8-clustering/img/clustering1.jpg rename to _posts/2023-12-11-class-9-clustering/img/clustering1.jpg diff --git a/_posts/2022-11-15-class-8-clustering/img/dendrogram.jpg b/_posts/2023-12-11-class-9-clustering/img/dendrogram.jpg similarity index 100% rename from _posts/2022-11-15-class-8-clustering/img/dendrogram.jpg rename to _posts/2023-12-11-class-9-clustering/img/dendrogram.jpg diff --git a/_posts/2022-11-15-class-8-clustering/img/final_clustering.jpg b/_posts/2023-12-11-class-9-clustering/img/final_clustering.jpg similarity index 100% rename from _posts/2022-11-15-class-8-clustering/img/final_clustering.jpg rename to _posts/2023-12-11-class-9-clustering/img/final_clustering.jpg diff --git a/_posts/2022-11-15-class-8-clustering/img/unclustered.jpg b/_posts/2023-12-11-class-9-clustering/img/unclustered.jpg similarity index 100% rename from _posts/2022-11-15-class-8-clustering/img/unclustered.jpg rename to _posts/2023-12-11-class-9-clustering/img/unclustered.jpg diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap.Rmd b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap.Rmd similarity index 98% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap.Rmd rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap.Rmd index 0665988..b4b003c 100644 --- a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap.Rmd +++ b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap.Rmd @@ -1,5 +1,5 @@ --- -title: "Class 9: Introduction to heatmaps" +title: "Class 10: Introduction to heatmaps" author: - name: "Kristen Wells" url: https://github.com/kwells4 @@ -12,7 +12,7 @@ output: draft: false --- -*The Rmarkdown for this class is [on github](https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2022-11-16-class-9-heatmap/class-9-heatmap.Rmd)* +*The Rmarkdown for this class is [on github](https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2023-12-12-class-10-heatmap/class-10-heatmap.Rmd)* ## Goals for this class * Learn how to make a heat map using `pheatmap` @@ -35,18 +35,18 @@ Before we get started, let's download all of the files you will need for the nex ```{r} # conditionally download all of the files used in rmarkdown from github -source("https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2022-11-10-class-7-matricies/download_files.R") +source("https://raw.githubusercontent.com/rnabioco/bmsc-7810-pbda/main/_posts/2023-12-08-class-8-matricies/download_files.R") ``` ## Making a heatmap Today we are going to continue working with the same data we used to talk about matrices and clustering, the top 100 boy and girl names by state for 2020. ```{r} -male_names_mat <- read.csv(here("class_7-9_data", "boy_name_counts.csv"), +male_names_mat <- read.csv(here("class_8-10_data", "boy_name_counts.csv"), row.names = 1) %>% as.matrix() -female_names_mat <- read.csv(here("class_7-9_data", "girl_name_counts.csv"), +female_names_mat <- read.csv(here("class_8-10_data", "girl_name_counts.csv"), row.names = 1) %>% as.matrix() ``` diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/anchor-4.2.2/anchor.min.js b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/anchor-4.2.2/anchor.min.js similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/anchor-4.2.2/anchor.min.js rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/anchor-4.2.2/anchor.min.js diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/bowser-1.9.3/bowser.min.js b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/bowser-1.9.3/bowser.min.js similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/bowser-1.9.3/bowser.min.js rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/bowser-1.9.3/bowser.min.js diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/distill-2.2.21/template.v2.js b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/distill-2.2.21/template.v2.js similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/distill-2.2.21/template.v2.js rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/distill-2.2.21/template.v2.js diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-10-1.png b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-10-1.png similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-10-1.png rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-10-1.png diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-13-1.png b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-13-1.png similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-13-1.png rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-13-1.png diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-14-1.png b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-14-1.png similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-14-1.png rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-14-1.png diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-15-1.png b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-15-1.png similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-15-1.png rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-15-1.png diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-18-1.png b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-18-1.png similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-18-1.png rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-18-1.png diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-20-1.png b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-20-1.png similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-20-1.png rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-20-1.png diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-22-1.png b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-22-1.png similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-22-1.png rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-22-1.png diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-26-1.png b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-26-1.png similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-26-1.png rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-26-1.png diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-27-1.png b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-27-1.png similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-27-1.png rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-27-1.png diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-29-1.png b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-29-1.png similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-29-1.png rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-29-1.png diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-31-1.png b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-31-1.png similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-31-1.png rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-31-1.png diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-33-1.png b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-33-1.png similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-33-1.png rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-33-1.png diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-34-1.png b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-34-1.png similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-34-1.png rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-34-1.png diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-35-1.png b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-35-1.png similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-35-1.png rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-35-1.png diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-38-1.png b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-38-1.png similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-38-1.png rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-38-1.png diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-39-1.png b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-39-1.png similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-39-1.png rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-39-1.png diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-4-1.png b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-4-1.png similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-4-1.png rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-4-1.png diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-42-1.png b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-42-1.png similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-42-1.png rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-42-1.png diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-43-1.png b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-43-1.png similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-43-1.png rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-43-1.png diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-44-1.png b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-44-1.png similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-44-1.png rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-44-1.png diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-47-1.png b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-47-1.png similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-47-1.png rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-47-1.png diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-5-1.png b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-5-1.png similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-5-1.png rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-5-1.png diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-7-1.png b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-7-1.png similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/figure-html5/unnamed-chunk-7-1.png rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/figure-html5/unnamed-chunk-7-1.png diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/header-attrs-2.14/header-attrs.js b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/header-attrs-2.14/header-attrs.js similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/header-attrs-2.14/header-attrs.js rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/header-attrs-2.14/header-attrs.js diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/jquery-3.6.0/jquery-3.6.0.js b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/jquery-3.6.0/jquery-3.6.0.js similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/jquery-3.6.0/jquery-3.6.0.js rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/jquery-3.6.0/jquery-3.6.0.js diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/jquery-3.6.0/jquery-3.6.0.min.js b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/jquery-3.6.0/jquery-3.6.0.min.js similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/jquery-3.6.0/jquery-3.6.0.min.js rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/jquery-3.6.0/jquery-3.6.0.min.js diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/jquery-3.6.0/jquery-3.6.0.min.map b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/jquery-3.6.0/jquery-3.6.0.min.map similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/jquery-3.6.0/jquery-3.6.0.min.map rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/jquery-3.6.0/jquery-3.6.0.min.map diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/popper-2.6.0/popper.min.js b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/popper-2.6.0/popper.min.js similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/popper-2.6.0/popper.min.js rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/popper-2.6.0/popper.min.js diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/tippy-6.2.7/tippy-bundle.umd.min.js b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/tippy-6.2.7/tippy-bundle.umd.min.js similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/tippy-6.2.7/tippy-bundle.umd.min.js rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/tippy-6.2.7/tippy-bundle.umd.min.js diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/tippy-6.2.7/tippy-light-border.css b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/tippy-6.2.7/tippy-light-border.css similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/tippy-6.2.7/tippy-light-border.css rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/tippy-6.2.7/tippy-light-border.css diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/tippy-6.2.7/tippy.css b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/tippy-6.2.7/tippy.css similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/tippy-6.2.7/tippy.css rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/tippy-6.2.7/tippy.css diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/tippy-6.2.7/tippy.umd.min.js b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/tippy-6.2.7/tippy.umd.min.js similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/tippy-6.2.7/tippy.umd.min.js rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/tippy-6.2.7/tippy.umd.min.js diff --git a/_posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/webcomponents-2.0.0/webcomponents.js b/_posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/webcomponents-2.0.0/webcomponents.js similarity index 100% rename from _posts/2022-11-16-class-9-heatmap/class-9-heatmap_files/webcomponents-2.0.0/webcomponents.js rename to _posts/2023-12-12-class-10-heatmap/class-10-heatmap_files/webcomponents-2.0.0/webcomponents.js