Appendix B — R Code for Figures and Analyses

This online appendix lists the R source files used to produce some of the figures and analyses in each chapter, with links to the source code on GitHub.

This is included here because it may be useful to readers to see the complete context in which many examples were developed, beyond the code displayed in the text. And also because you may want to use or adapt the code for your own work or to develop related examples using the same ideas with different datasets.

It is incomplete because it was constructed by scanning the chapter source files for special comments, of the form <!-- fig.code: R/Davis-reg.R --> that were manually embedded in the chapter .qmd files as I wrote this, but not always. Making this less incomplete proved to be a challenge because it involved scanning the text to find the corresponding R code files that had been included that had been included in chunks.

Files marked ⚠ (if any) do not yet have a descriptive title in their header.

Chapter 1: Warm-up Exercises

Chapter 3: Getting Started

Chapter 4: Plots of Multivariate Data

Chapter 5: Dimension Reduction

Chapter 6: Overview of Linear models

Chapter 7: Plots for Univariate Response Models

Chapter 8: Topics in Linear Models

Chapter 9: Collinearity & Ridge Regression

Chapter 10: Hotelling’s \(T^2\)

Chapter 11: Multivariate Linear Models

Chapter 12: Visualizing Multivariate Models

Chapter 14: Multivariate Influence and Robust Estimation

Chapter 15: Discriminant analysis

Utilities

These R files are source()d by one or more of the scripts above or used directly in a chapter. They define custom functions and helpers, some used across multiple chapters.

  • penguin-colors.R — Define penguin colors and themes
  • matrix2latex.R — convert matrix to latex
  • ggvectors.R — Draw labeled vectors in a ggplot scene
  • text.usr.R — Add text to a plot at normalized device coordinates
  • text_usr.R — Add text to a plot at normalized device coordinates
  • pvPlot.R — Partial variables plots to visualize partial correlation