PCA: Hunting for patterns and structure in my data

Multivariate data arises when several different variates (1, …, p) are measured on a set of n samples. However, with so many variates, a major challenge with multivariate data is finding the patterns and relationships hidden within it. Principal Components Analysis (PCA), a popular multivariate method, aims to reduce the dimensionality of multivariate data. That is, its purpose is to find a smaller number of dimensions than p (usually 2 or 3) that captures most of the variation present in the data. By reducing the dimensionality, PCA helps uncover patterns and structure in the data, and reveals the relative importance of the individual variables.


PCA works by creating linear combinations of the data variates. (For a detailed explanation on the PCA methodology see, for example, Jolliffe and Cadima, 2016.) These linear combinations are known as principal components. For example, denoting the p variates by X1, X2, … , Xp, principal component i is given by:

ai,1 X1 + ai,2 X2 + … + ai,p Xp

where ai,1, ai,2, … , ai,p are the loadings for the ith component.

The first principal component is constructed so that it explains the maximum amount of variation in the original dataset of any possible linear combination of the p variates. Subsequent components are then formed to maximise the remaining variation explained, but importantly, with the additional requirement that they are orthogonal to (i.e., uncorrelated with) any other component. Let’s look at an example.

Example: exploring pollution data

Our historic 1 example dataset contains seven environmental variates recorded in 41 American towns (Town, TownID). These are:

SO2sulphur dioxide levels in the air in micrograms per cubic meter
Tempaverage annual temperature in degrees Fahrenheit
Manufnumber of factories with 20+ staff
Poppopulation size in thousands
Windaverage annual wind speed in miles per hour
Precipaverage annual rainfall in inches
Daysaverage rain days per year

The first few rows of data are shown below. You can find the full dataset at the end of this blog.

alt text

Let’s perform a PCA on this multivariate dataset.

The first step is to decide what matrix, formed from the variates, to use. PCA can be based on either the variance-covariance matrix, the sums of squares and products matrix or the correlation matrix. The first two essentially produce the same analysis: these matrices just differ by a scaling factor, whereas, if the correlation matrix is used, each variate is standardised by subtracting its mean and dividing by its standard deviation. This standardisation can be very useful if the variates aren’t measured on the same scale and/or show very different amounts of variation.

As the variates in our example dataset are on different scales, it is sensible to base the PCA on the correlation matrix.

The Genstat menu settings for performing the PCA are shown below:

alt text

And here’s the output:

alt text

The first principal component explains 38.97% of the variation in the (standardised) pollution data. The second, uncorrelated with the first, explains a further 21.60%. The third, uncorrelated with the first and second, explains an additional 19.93% – and so, and until the final principal component (here, the 7th as the trace is 7), which explains the final 0.36%. Combined, all seven principal components explain 100% of the variation in the (standardised) pollution data.

Interpreting principal components

It is often interesting to try to interpret the coefficients of each component, i.e., the loadings. Components with mainly positive or mainly negative loadings represent “averages” of the variates, whilst those with a mixture of loading signs represent “comparisons”. In addition, as here the variates have been standardised, the bigger the absolute value of the loading, the larger the contribution that particular variate makes to explaining the variation (i.e., the more important it is).

For the pollution dataset the first principal component (PC-1) is:

0.26 × Days* + 0.54 × Manuf* + 0.49 × Pop* + 0.00 × Precip* + 0.49 × SO2* − 0.32 × Temp* + 0.25 × Wind*

Note: the asterisk (*) denotes that the variables have been standardised.

Capturing variation: how many dimensions do we need?

Higher scores (i.e., values) for PC-1 will result in increased numbers of rain days, numbers of factories with 20+ staff, population size, levels of sulphur dioxide and wind speed, and decreased temperature. Thus, PC-1 seems to represent “quality of life”, suggesting that a town with a lower PC-1 score offers a better quality of life than a town with a higher PC-1 score.

The second principal component (PC-2) is:

0.68 × Days* − 0.23 × Manuf* − 0.28 × Pop* + 0.63 × Precip* + 0.08 × SO2* − 0.09 × Temp* + 0.06 × Wind*

This appears to be a contrast between numbers of rain days and amount of rain against number of factories with 20+ staff and population size; that is, a high score for PC-2 will correspond to towns with wet climates, small populations, and few large factories.

These first two principal components explain 60.57% (38.97% + 21.60%) of the variation in the (standardised) pollution data. Recall, that the aim of PCA is to reduce the dimensionality of the original dataset whilst capturing most of the variation present within. So, how many dimensions do we need to provide a good representation of the pollution dataset? This is somewhat subjective, but realistically for PCA to be useful we need a large percentage (e.g,. > 70%) of the variation to be explained by only a few (say, ≤ 3) principal components.

In our example, the cumulative percentage of variation explained is depicted below:

alt text

So perhaps three dimensions are needed? These three dimensions explain just over 80% of the variation in the data.

The third principal component (PC-3) is:

− 0.11 × Days* + 0.27 × Manuf* + 0.34 × Pop* + 0.49 × Precip* + 0.01 × SO2* + 0.68 × Temp* − 0.31 × Wind*

In this case high scores (i.e., values) appear to represent hot, populous towns with a climate of heavy downpours concentrated on few days per year and little wind.

Visualizing town differences: scatter plot matrix

To help study the differences and similarities between towns, let’s create a scatter plot matrix from the first three principal component scores. In Genstat, the menu settings below have been used to generate the plot.

alt text

alt text

In the resulting scatter plot matrix, Chicago (Ch) stands out in the direction of PC-1, suggesting that it offers a low “quality of life”. In the direction of PC-2, Phoenix (Px) stands out, indicating that it is a populous city with a dry climate. From the third component, we deduce that Miami (Mi) has a hotter climate with higher annual rainfall than Buffalo (Bf).

Insights from a biplots

Another very useful and commonly used tool for exploring the results of a PCA is the biplot 2. Biplots provide a means of assessing the relationships between the individual samples in the analysis (here the towns), and their characteristics with respect to the variates in the dataset.

In brief, the scores for the individual samples are plotted in the 2-D space defined by two dimensions of the PCA. Typically, the first two dimensions are plotted. Superimposed onto this plot are the axes for each variate (i.e., its biplot axis). These axes enable us to see how each sample’s projection into this 2-D space relates to its value for the variate concerned. In addition, the angles between the biplot axes represent the correlations between the variates. An acute angle indicates positive correlation, a right angle indicates no correlation, and an obtuse angle indicates negative correlation.

Understanding biplots: predictive vs. interpolative axes

There are two types of biplot axes: predictive and interpolative. Predictive axes show the values of the variates that are predicted by the projection of the samples into 2-D space. Essentially, this is the orthogonal projection of the sample onto each biplot axis (i.e., at right-angles to the axes). Interpolative axes show the values of the variates that would lead to a sample being placed at a particular position on the biplot graph. That is, for interpolative axes, the sample is being predicted by the variates, whereas for predictive axes the variates are being predicted by the samples.

Below is a biplot, with predictive axis, for the first two dimensions. Superimposed onto this plot are the orthogonal projections for Chicago (Ch) onto each biplot axis. The point at which the orthogonal projection intersects with a variate’s biplot axis corresponds to the predicted value for particular variate. For example, Pop (the population size in thousands) is predicted to be ~3,000 for Chicago.

alt text

As the first two dimensions only explain 60.58% of the variation in the (standardised) pollution data, with some caution due to this loss of information, by inspecting the biplot we can glean insights into the correlation between variables. For example:

  • Wind and SO2 appear to be strongly positively correlated (as the angle between their axes is small)
  • SO2 and Temp appear to be negatively strongly correlated (as their axes run in almost exactly the opposite direction)
  • Days and Pop appear to be uncorrelated (as their axes are approximately at a right angle)

Identifying town similarities: biplot clustering

We can also use the biplot to identify towns that are similar to one another and those that are dissimilar. Towns that are more alike will tend to cluster together, such as Seattle (Se) and Buffalo (Bf). Conversely, towns plotted further apart will tend to be rather different, such as Cleveland (Cv) and Phoenix (Px).

PCA is one of the commonly used methods for exploring multivariate data and is readily available in most statistical software packages. As I’ve attempted to demonstrate in this blog, PCA provides one way to overcome the “curse of dimensionality” afflicting multivariate data. It does this by reducing the number of dimensions, enabling us to create graphs to uncover patterns and structure in the data.

The pollution example dataset

alt text


    1 From Biometry. The Principles and Practices of Statistics in Biological Research, Sokal, R.R., and Rohlf, F.J. (1969). W.H. Freeman and Company. ↩

    2 For a much more detailed explanation of PCA biplots, see Chapter 2 of Gower, J.C. & Hand, D.J. (1996). Biplots. Chapman & Hall, London. ↩

    Picture of Dr. Vanessa Cave
    Dr. Vanessa Cave
    Dr. Vanessa Cave is an applied statistician interested in the application of statistics to the biosciences, in particular agriculture and ecology, and is a developer of the Genstat statistical software package. She has over 15 years of experience collaborating with scientists, using statistics to solve real-world problems. Vanessa provides expertise on experiment and survey design, data collection and management, statistical analysis, and the interpretation of statistical findings. Her interests include statistical consultancy, mixed models, multivariate methods, statistical ecology, statistical graphics and data visualisation, and the statistical challenges related to digital agriculture. Vanessa is a past President of both the Australasian Region of the International Biometric Society and the New Zealand Statistical Association, on the Editorial Board of The New Zealand Veterinary Journal and an honorary academic at the University of Auckland. She has a PhD in statistics from the University of St Andrew.

    Comments

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Related articles

    How much of the variation in your field trial comes from the treatments, and how much comes from...
    What should you do when count data are more variable than your model expects? Vanessa Cave and David...
    Precision breeding can deliver scientifically impressive traits, but practical value depends on more than technical success. Owen McIntosh...