1. Tutorials
  2. Correlation / PCA tutorial

Correlation & Principal Component Analysis in Excel: Worked ExampleLearn how to visualize the relationships between the variables and the similarities between observations.

To illustrate the concepts, we will use data from a New York magazine article that examines the most livable neighborhoods in New York. In the original article, written by Nate Silver, neighborhoods were scored using 12 factors. Then, the scores for each factor were combined into an overall score and ranking for each neighborhood. For more information, see NY magazine story “ The Most Livable Neighborhoods in New York”and Junk Charts story “ The scatter plot matrix: a great tool”.

If you prefer you can watch a video of this tutorial.

In this tutorial you will perform the following tasks:

Understanding the relationship between variables

When analyzing many variables, scatter plots and correlation coefficients can quickly uncover patterns and reduce a large amount of data to a subset of interesting relationships.

Correlation describes the strength of relationship between two variables. A correlation coefficient ranges from -1 to +1. +1 indicates a perfect positive linear relationship, and -1 indicates a perfect negative linear relationship. Zero indicates the variables are uncorrelated and there is no linear relationship. Normally the correlation coefficient lies somewhere between these values.

  1. Open the file tutorials\New York Neighborhoods.xlsx.
  2. Click a cell in the dataset.
  3. On the Analyse-it ribbon tab, in the Statistical Analyses group, click Multivariate, and then click Correlation Matrix.
    The analysis task pane opens.
  4. In the Model drop-down list, select Multivariate.
  5. In the Y variables list box, select Affordability, Transit, Shopping & Services, Crime, Food, Schools, Diversity, Creative, Housing Quality, Green Space, Wellness, Nightlife.
  6. Select Correlation and Color maps.
  7. On the Analyse-it ribbon tab, in the Correlation group, click Scatter matrix, and then click Scatter Plot with Density Ellipses and Histograms.
  8. In the Density ellipse edit box, enter 75%.
  9. Click Calculate.
    The results are calculated and the analysis report opens.

The scatter plot matrix shows plots for all of the pairs of variables, and each plot shows the relationship between a pair of variables. The red ellipse contains the middle 75% of the neighborhoods and indicates whether the two variables are positively, negatively, or not correlated.

Scatter plot matrix

The correlation matrix shows the correlation coefficient for each pair of variables. Positively correlated variables are blue and negatively correlated variables are red, with the intensity dependent on the magnitude of the correlation.

Correlation matrix
Based on the scatter plot matrix and the correlation matrix, a few relationships are obvious:
  • Neighborhoods with affordable housing don’t offer good transit.
  • Better shopping also means a greater number of restaurants.
  • There is less creative capital in neighborhoods with high diversity.
  • Wellness seems almost completely unrelated to other factors.

Reducing the dimensionality of the data

Due to the large number of variables in the dataset, it is hard to comprehend all of the relationships between the variables using a scatter plot or correlation matrix. Using a data reduction technique such as principal components analysis (PCA) reduces the dimensionality of the dataset whilst retaining as much of the variability in the data as possible. The first few principal components retain most of the variation in the original variables, and, to make interpretation simpler, they can be used to describe the relationships between the original variables and similarities between observations.

PCA is a mathematical technique that reduces dimensionality by creating a new set of variables called principal components. The first principal component is a linear combination of the original variables and explains as much variation as possible in the original data. Each subsequent component explains as much of the remaining variation as possible under the condition that it is uncorrelated with the previous components.

  1. On the Analyse-it ribbon tab, in the PCA group, click Principal Components.
    The Principal Components task is added to the analysis task pane.
  2. Select Scale.
  3. Select Variances, Coefficients, and Color maps.
  4. Click Recalculate.
    The results are calculated and the analysis report opens.

The variances table shows the amount of variance in the original data explained by each principal component (also called the eigenvalues). Because the data was standardized, a principal component with a variance of 1 indicates that the component accounts for variation equivalent to one of the original variables. Also, the sum of all the variances equals the number of original variables.

PCA variances table

There are many ad-hoc rules regarding the number of components to retain to adequately describe the data. According to the table, the first two principal components account for nearly 70% of the variance in the original 12 variables, whilst the first three components account for nearly 80%.

The coefficients table shows the linear combinations that make each principal component, and the color map shows the structure of the components. Absolute values near zero indicate that a variable contributes little to the component, whereas larger absolute values indicate variables that contribute more to the component. The sign of the coefficients is irrelevant and may even differ when the analysis is performed on different computers.

PCA coefficients table

There is not necessarily a simple interpretable structure to the principal components because they are created to maximize the amount of variance whilst remaining uncorrelated with the other components. By trying to interpret the coefficients in the table, we can see that the first component is an average of many different variables; the second component represents mainly crime, wellness, and, to a lesser extent, schools and housing quality; and the third component – although it still has some reasonable sized contribution from other variables – represents mainly green space.

Understanding the relationship between variables (revisited)

Rather than using a scatter plot or correlation matrix, a two-dimensional correlation monoplot of the coefficients of the first two principal components can visualize the relationships between the variables.

The correlation monoplot shows vectors pointing away from the origin to represent the original variables.

The angle between the vectors is an approximation of the correlation between the variables. A small angle indicates the variables are positively correlated, an angle of 90 degrees indicates the variables are not correlated, and an angle close to 180 degrees indicates the variables are negatively correlated.

The length of the line and its closeness to the circle indicate how well the variable is represented in the plot. It is therefore unwise to make inferences about relationships involving variables that are poorly represented.

  1. On the Analyse-it ribbon tab, in the PCA group, click Biplot / Monoplot, and then click Correlation Monoplot.
    The Biplot / Monoplot task is added to the analysis task pane.
  2. Click Recalculate.
    The results are calculated and the analysis report opens.

Although the first two principal components only account for 70% of the variance in the original dataset, they still provide a useful approximation of the relationships between the variables.

Correlation monoplot

The relationships between the variables described earlier using the scatter plots are easier to visualize in the monoplot. The negative correlation between affordability and transit is represented by the lines being almost 180 degrees to each other.

Green space is not very well represented as indicated by the short length of its vector. This variable was mostly associated with the third principal component, which is not represented in the two-dimensional plot.

Understanding the similarities between observations

Until now, we have been interested in understanding the relationships between the variables, but often the interest is on the similarity between neighborhoods or groups of neighborhoods. Whilst it is possible to label and color the points on the scatter plots relating to neighborhoods, it is not easy to interpret them when each neighborhood is represented on 60 or more plots. It is easier to first reduce the dimensionality of the data using principal components, and then use a biplot that simultaneously plots information on the observations and the variables.

The classical biplot popularized by Gabriel represents the variables using vectors and observations as points whereas a more recent innovation developed by Gower & Hand represents the variables using calibrated axes allowing the observations represented as points to be projected onto the axes and an approximation made. A full monograph titled Understanding Biplots by Gower, Gardener-Lubbe and LeRoux is an excellent book to learn more about biplots.

  1. Open the file tutorials\New York Neighborhoods.xlsx.
  2. Click a cell in the dataset.
  3. On the Analyse-it ribbon tab, in the Statistical Analyses group, click Multivariate, click Biplot, and then click PCA Biplot.
    The analysis task pane opens.
  4. In the Y variables list box, select Affordability, Transit, Shopping & Services, Crime, Food, Schools, Diversity, Creative, Housing Quality, Green Space, Wellness, Nightlife.
  5. Select Label points.
  6. Click Calculate.
    The results are calculated and the analysis report opens.

The biplot shows the two-dimensional approximation to the original multidimensional space. It represents 70% of the original variation in the data. Each point on the biplot represents a neighborhood and each axis represents a variable.

PCA biplot

The distance between points represents the similarity between them, points close to each other are neighborhoods with similar profiles, and points far away have dissimilar profiles.

Any point on the plot can be projected orthogonally onto the axes to show the approximate value of that variable. For example, Bedford Park (center right of the plot) scores around 90 on affordability, 65 on housing quality, and 70 on food. The true values were 89, 60, and 62 respectively, so the approximation is fairly accurate for these variables and this neighborhood.

Grouping the observations

Rather than focusing on individual neighborhoods, we may group the neighborhoods by the borough they are located in and plot the points using different symbols and colors.

  1. On the Biplot task pane, click Vary point color / symbol.
  2. In the Group / Color / Symbol drop-down list, select Borough.
  3. Click Recalculate.
    The results are calculated and the analysis report opens.
PCA biplot

It is easy to see that the neighborhoods in The Bronx are more affordable than those in Manhattan and that they have lower scores for shopping & services, transit, food and creative. The axes are labelled on the edge with higher values for convenience.

Adding additional variables

Sometimes there are additional variables that were not included in the PCA because they are a combination of the other variables. It can still be useful to add these variables to the plot as additional axes to help interpretation.

  1. On the Biplot task pane, click Add new variables.
  2. In the Additional variables list, select Rank.
  3. Click Recalculate.
    The results are calculated and the analysis report opens.
PCA biplot

The plot shows the additional axis named rank (colored green in the plot). Due to its poor representation, only 25% of variation in the original variable is explained by the first two principal components, we will not pursue interpreting it any further. This is not surprising, given it is a weighted average of the other scores that have varying degrees of correlation between them.

Adding additional observations

If we have our own priorities regarding what constitutes our ideal neighborhood, this can be plotted to determine a list of neighborhoods closely matching those criteria.

  1. On the Biplot task pane, click Add new observations.
  2. In the Label edit box, enter My Ideal.
  3. In the edit boxes, enter Affordability = 70,Transit = 75, Shopping & Services = 75, Crime = 80, Food = 80, Schools = 80, Diversity = 75, Creative = 80, Housing Quality = 80, Green Space = 85, Wellness = 80, Nightlife = 85
  4. Click Recalculate.
    The results are calculated and the analysis report opens.
PCA biplot

Our ideal neighborhood is interpolated onto the plot and labelled “My Ideal” (left and above the center of the plot). Neighborhoods that closely match those priorities will surround that point. Namely, these neighborhoods are Park Slope, Upper West Side, and the Flatiron District & Gramercy.

Publishing the plot

Once the plot is constructed, there are many additional options that can be used to tweak its appearance.

The quality of the representation of the axis (known as the predictivity and shown in brackets at the end of each axis label) indicates how much of the variance in the original variable is explained in the plot. Some of the variables – such as green space, schools and diversity – are poorly represented in a two-dimensional PCA biplot, which means projections of points onto those axes aren’t very accurate. Likewise, some neighborhoods may not be well represented by the two-dimensional approximation.

Another issue is that the axes cross over the data points, which makes them difficult to see.

  1. In the Rotate edit box, enter -.

    The plot will be rotated so the axis that is best represented will be horizontal.

  2. Select Transparency.

    Points that are poorly approximated will be more transparent.

  3. Select Visibility and in the Predictivity threshold edit box, enter 0.6.

    Axes which are poorly represented will be hidden.

  4. Select Adjust axes.
  5. In the Offset X edit boxes, enter Crime = 4, Wellness = -4.5, Nightlife = 4.1
  6. In the Offset Y edit boxes, enter Transit = 4, Shopping & Services = 4, Food = -3.3, Creative = -3.6, Housing Quality = -4.3, Rank = -4.
  7. Click Recalculate.
    The results are calculated and the analysis report opens.
PCA biplot

The plot is rotated so that the axis that is best represented (affordability) is horizontal. Other axes are offset to the edge of the plot, which makes the points easier to see.

Points are filled with a lighter transparency the poorer the representation. Axes that represent less than 60% of the variation in the variable are hidden, which eliminates the risk of interpreting the projections onto them.

Tutorials v6.20.0