10  Multivariate Data

Overview

So far we’ve worked with two variables at a time, but often we have more - sometimes many more. Here we’ll introduce several useful tools for working with multivariate data, using Chapter 10 of Essential R Course Notes. Note that this is a very brief overview, and that we won’t discuss many multivariate tools such as PCA, ordination, and others.

Objectives

Upon completion of this lesson, you should be able to:


  1. make three-way frequency tables,
  2. make pairs plots using the function pairs(),
  3. use lattice graphics to make plots conditioned on a third variable,
  4. carry out Principal Components Analysis (PCA), and
  5. carry out heirarchical clustering and k-means clustering.

Data and R Code Files

The R code file and data files for this lesson can be found on the Essential R - Notes on learning R page.

R logo

10.1 Multiple Variables

In this video we’ll demonstrate the use of table() for three-way frequency tables and the use of pairs() to create correlation plot matrices, which are very useful in exploratory analysis.

Video - STAT 484 Lesson: 10.1

10.2 Lattice Graphics

Here we’ll introduce some functions from the package ‘lattice’ which allow making groups of plots, with groups defined by a variable.

Video - STAT 484 Lesson: 10.2

10.3 An Example with Data Import, pairs(), and by()

Here I work through a brief example, beginning with importing data, then checking for correlation with pairs(), and finally demonstrating how to use by() to extract some group means. Note that I didn’t exclude one of the factor variables here, and you can see how it is displayed in the last row and column of the scatterplot matrix.

Video - STAT 484 Lesson: 10.3

10.4 Principal Components Analysis

Here we will demonstrate Principal Components Analysis, or PCA, which can be a useful way to get some idea of which variables are contributing the most variability to a data set. Note that the biplot may be a bit small to easily see in the “plot” pane. If you are following along in R, click the “zoom” button above the plot pane to see a larger version.

Video - STAT 484 Lesson: 10.4

10.5 Heirarchical Clustering and Dendrograms

Hierarchical clustering groups observations by finding those that are “nearest” each other and then defining clusters. While there are different ways to define “nearest” and different ways to define clusters, the idea is the same. Here we work with the root anatomy data, and it seems like the sample locations (L1 vs L2) are a bit more clustered than the genotypes.

Note! The current version of EssentialR uses a modified form of the data, so the genotypes in this data file are now named A:L and the sample locations are L1 and L2 vs 5-8 and 20-28.

Video - STAT 484 Lesson: 10.5

10.6 K-means Clustering

k-means clustering is a clustering method that looks for k clusters in the data, meaning we must tell it how many groups to look for. Nonetheless it can still be very useful. Here we ask how well the three species of iris in the iris dataset can be separated based on their morphology (as captured by the four quantitative variables in the dataset).

Video - STAT 484 Lesson: 10.6

STAT 484: Topics in R Statistical Language

This course will continue into STAT 485: Topics in R Statistical Language.