Four numbers per city, and nobody can see the pattern
The Larkspur Regional Planning Office, a fictional agency, compares ten cities on four indicators: average rent per square metre, median household income, average commute time and the share of green space. Four columns sound manageable, but try to answer a simple question from them: which cities are alike? Aldermoor has high rent, high income and a long commute. Juniper Bay has low rent, a short commute and lots of parks. Every pair of columns tells a slightly different story, and with more indicators it quickly becomes impossible to keep in your head.
Principal Component Analysis (PCA) solves this. It replaces many correlated columns with a few new ones, the principal components, that keep as much of the original variation as possible. Instead of four numbers per city you look at two, and you can plot every city on one chart. Analysts use it for city and regional comparisons, customer segmentation, survey scales, finance and quality data.
This free first lesson is for analysts, students in statistics, economics or geography, controllers and data-curious Excel users who want to understand PCA instead of pressing a button in a statistics package. The whole course builds PCA from formulas only. Lesson 1 covers the step that is easy to skip and expensive to forget: standardising the variables. The city data are fictional and used only for teaching.
What PCA does, in plain words
Picture the ten cities as points in a four-dimensional space, one axis per indicator. PCA looks for the direction through that cloud along which the cities differ most. That direction is the first principal component, PC1. Then it looks for the next direction, at a right angle to the first, that captures most of the remaining variation, and so on. Each component is a weighted sum of the original variables, and the weights tell you what it means, for example "expensive and wealthy" versus "green and quick to commute".
The key word is variation. PCA measures how much the data spread along a direction with the variance. And variance depends on the unit. Income in thousands of dollars varies by tens, from 45 to 83. Rent in dollars per square metre varies by single digits, from 9.6 to 27.9. Measure income in dollars instead of thousands and its variance grows by a factor of a million. If you feed raw data into PCA, the variable with the biggest numbers grabs the first component, not because it matters most, but because of its unit.
The fix: z-scores
Standardising puts every variable on the same scale. For each value you subtract the column mean and divide by the column standard deviation: z = (x − mean) ÷ sd. After this step every column has a mean of exactly 0 and a standard deviation of exactly 1, whatever its original unit. A z-score of +1.5 means "1.5 standard deviations above the average city", which you can compare directly between rent, income, commute and green space.
Because every standardised column has variance 1, each indicator enters the analysis with the same weight. PCA on z-scores is the same as PCA on the correlation matrix, and that is the standard choice when variables are measured in different units. Use the sample standard deviation, STDEV.S, which divides by n − 1. Excel uses the same convention in CORREL and COVARIANCE.S, so your later matrices will line up.
Worked example: ten cities, four indicators
Here are the raw data from the lab, columns B to E, with the mean in row 13 and the sample standard deviation in row 14. These two rows are the first thing you calculate.
| City | Rent ($/m²) | Income ($k) | Commute (min) | Green (%) |
|---|---|---|---|---|
| Aldermoor | 24.5 | 71 | 41 | 14 |
| Brackenford | 13.2 | 58 | 24 | 31 |
| Calderwick | 19.8 | 57 | 29 | 29 |
| Duskmere | 9.6 | 49 | 33 | 22 |
| Embervale | 27.9 | 83 | 32 | 19 |
| Fernhollow | 15.4 | 66 | 22 | 27 |
| Glenmarrow | 11.1 | 45 | 37 | 24 |
| Hollowmere | 21.7 | 64 | 26 | 21 |
| Ivyreach | 17.3 | 62 | 44 | 15 |
| Juniper Bay | 12.8 | 52 | 21 | 36 |
| Mean (row 13) | 17.33 | 60.70 | 30.90 | 23.80 |
| Std dev, sample (row 14) | 6.04 | 11.18 | 7.95 | 7.04 |
Look at the standard deviations: 6.04 for rent, 11.18 for income, 7.95 for commute and 7.04 for green space. They depend entirely on the units. Squared, they give the variances, and those decide how much weight each variable would get in a PCA on raw data. Income has a variance of 124.9, rent only 36.5. Income would count 3.43 times as much as rent, which is what the lab asks you to calculate in B29 with =VAR.S(C2:C11)/VAR.S(B2:B11).
Now the z-scores. One formula in B17, =(B2-B$13)/B$14, copied across to E17 and down to row 26, fills the whole table. The dollar sign before the row number is what makes this work: when you copy across, the column letter moves from B to E, so each column uses its own mean and standard deviation. When you copy down, the row stays at 13 and 14.
| City | z Rent | z Income | z Commute | z Green |
|---|---|---|---|---|
| Aldermoor | +1.19 | +0.92 | +1.27 | -1.39 |
| Brackenford | -0.68 | -0.24 | -0.87 | +1.02 |
| Calderwick | +0.41 | -0.33 | -0.24 | +0.74 |
| Duskmere | -1.28 | -1.05 | +0.26 | -0.26 |
| Embervale | +1.75 | +2.00 | +0.14 | -0.68 |
| Fernhollow | -0.32 | +0.47 | -1.12 | +0.45 |
| Glenmarrow | -1.03 | -1.40 | +0.77 | +0.03 |
| Hollowmere | +0.72 | +0.30 | -0.62 | -0.40 |
| Ivyreach | 0.00 | +0.12 | +1.65 | -1.25 |
| Juniper Bay | -0.75 | -0.78 | -1.25 | +1.73 |
Read a few cells. Embervale's income has a z-score of +2.00: two standard deviations above the average city, the most extreme value in the table. Juniper Bay's green space is +1.73. Ivyreach's commute is +1.65, the longest. Glenmarrow's income is −1.40. In each column the z-scores add up to zero, and their standard deviation is exactly 1, a quick check you can do with =SUM(C17:C26) and =STDEV.S(C17:C26).
The table already hints at what PCA will find. Cities with high rent tend to have high income too: Aldermoor and Embervale are positive in both, Duskmere and Glenmarrow negative in both. Long commutes tend to go with little green space: Ivyreach and Aldermoor show exactly that pattern. Those two pairs of related indicators are what the first components will pick up later in the course.

How to do it in Excel, step by step
- Arrange the data as a table: one row per observation (city), one column per variable, a header row, no blank rows, no text in number columns. In the lab that is A1:E11.
- Mean: click B13 and enter
=AVERAGE(B2:B11). Standard deviation: click B14 and enter=STDEV.S(B2:B11). - Select B13:E14 and press Ctrl+R to fill both formulas to the right. E14 should show about 7.04.
- Click B17 and type
=(B2-B, click B13 and press F4 (Mac: Cmd+T) twice until it readsB$13. Continue with)/B$14and press Enter. B17 shows 1.19. - Copy B17, select B17:E26 and paste with Ctrl+V. Or select B17:E26 first, type the formula once and press Ctrl+Enter to fill the whole block. D21 (Embervale, commute) should show 0.14.
- Alternative:
=STANDARDIZE(B2,B$13,B$14)gives the same numbers. In Excel 365 you can even type=(B2:E11-B13:E13)/B14:E14in B17 and let it spill over the whole table. - Format the z-table with two decimals (Ctrl+1 > Number > Decimal places: 2). For a quick visual, add Home > Conditional Formatting > Color Scales with a three-colour scale centred on 0.
- Count unusual values in B28:
=COUNTIF(C17:C26,">1")+COUNTIF(C17:C26,"<-1"). You can also use=SUMPRODUCT(--(ABS(C17:C26)>1)). The result is 3. - Check the weighting problem in B29:
=VAR.S(C2:C11)/VAR.S(B2:B11), about 3.43. - Verify: below the z-table,
=AVERAGE(B17:B26)must be 0 (or a tiny number like 1E-16) and=STDEV.S(B17:B26)must be 1 for every column.
When not to standardise
Standardising is the default when variables have different units, but not a law. If all variables share one unit and their spread is meaningful, for example monthly spending in dollars on four product groups, you may want the big categories to count more. Then you run PCA on the covariance matrix of the centred, unscaled data. The question to ask is: should a variable with a larger spread get more weight? If the spread only reflects the unit, standardise. If it reflects real importance in the same unit, consider not scaling. Whatever you choose, say so in your report, because the components can change a lot.
Common mistakes and how to spot them
- STDEV.P instead of STDEV.S. The population formula divides by n and gives slightly larger z-scores. Your later correlation matrix from
CORRELwould then not match the covariance of your z-scores. Check: the z-columns must have STDEV.S exactly 1. - Centring without scaling.
=B2-B$13gives mean 0 but keeps the units, so income still dominates. If a column of "z-scores" has values like −15.7, you forgot to divide. - Wrong anchoring.
=(B2-$B$13)/$B$14locks the column too, so every column uses rent's mean and sd. Spot it when the income z-scores all land between about 4.6 and 10.9. UseB$13: row fixed, column free. - Relative references.
=(B2-B13)/B14works in row 17 but slides down to empty rows when copied, causing#DIV/0!or nonsense. Lock the row with $. - Standardising across rows. Each variable is standardised over the observations in its column, not each city over its four indicators. A row-wise mean of rent, income and commute has no meaning.
- Counting only one side.
=COUNTIF(C17:C26,">1")returns 1 and misses the two cities below −1. "Beyond ±1" means both tails. - Ratio of standard deviations instead of variances. 11.18 ÷ 6.04 = 1.85 understates the weighting problem. PCA works with variances, so square it: 3.43.
Quick reference: functions and shortcuts used
| Cell(s) | Formula | Result |
|---|---|---|
| B13 (copy to E13) | =AVERAGE(B2:B11) | Rent mean 17.33 |
| B14 (copy to E14) | =STDEV.S(B2:B11) | Rent sd 6.04, Green sd 7.04 (E14) |
| B17 (copy to B17:E26) | =(B2-B$13)/B$14 or =STANDARDIZE(B2,B$13,B$14) | Aldermoor rent +1.19 |
| B28 | =COUNTIF(C17:C26,">1")+COUNTIF(C17:C26,"<-1") | 3 cities |
| B29 | =VAR.S(C2:C11)/VAR.S(B2:B11) | 3.43 |
| Function or shortcut | What it does | Example |
|---|---|---|
AVERAGE(range) | Column mean | Income: 60.70 |
STDEV.S(range) | Sample standard deviation (n − 1) | Income: 11.18 |
VAR.S(range) | Sample variance = STDEV.S² | Income: 124.9 |
STANDARDIZE(x,mean,sd) | z-score of one value | Embervale income: +2.00 |
=(B2-B$13)/B$14 | Same z-score with mixed references, ready to copy across and down | Aldermoor rent: +1.19 |
COUNTIF(range,">1") | Counts values above +1 | Income: 1 |
ABS(x) | Absolute value, for "beyond ±1" tests | |−1.40| = 1.40 |
=(B2:E11-B13:E13)/B14:E14 | Whole z-table in one spilling formula (Excel 365) | 10 × 4 result |
| F4 (Mac: Cmd+T) | Cycles B13 → $B$13 → B$13 → $B13 | B$13 |
| Ctrl+Enter | Enters one formula into every selected cell at once | B17:E26 |
Real-world uses
- Regional and city comparisons. Planners combine housing, income, transport and environment indicators into a few composite dimensions, exactly as in this course.
- Customer segmentation. Spending, visit frequency, basket size and tenure are measured in different units; standardising before PCA or clustering stops the biggest number from dominating.
- Survey analysis. Twenty questions about satisfaction often boil down to two or three underlying themes. PCA on standardised answers shows which questions move together.
- Finance and risk. Returns of many assets or interest rates at many maturities are summarised by a few components that explain most of the joint movement.
- Benchmarking and KPIs. z-scores alone already let a controller compare branches on several KPIs with different units and flag the ones that sit unusually far from the average.
What you will build in the rest of this course
This first lab is free. The remaining 19 labs are part of the full course, a one-time purchase of $9.90, and they take the same ten cities all the way to a finished PCA, built with formulas you can see and check.
Covariance & Correlation Matrices with MMULT and TRANSPOSE. You turn the z-scores into a correlation matrix with one matrix formula and see which indicators move together, the raw material of every component.
Power Iteration: the First Eigenvector with Repeated MMULT. You find the first principal component without any add-in, by multiplying a vector with the matrix again and again until it stops changing, a method you can watch converge cell by cell.
Eigenvalue & Explained Variance: How Much Does PC1 Capture?. You compute how much of the total variation the first component explains, the number that tells you whether one summary score is enough.
The Second Component: Deflation and Another Power Iteration. You remove what PC1 already explains and repeat the iteration to find the second, independent direction in the data.
Scree Plot & Cumulative Variance: How Many Components? (with a Chart). You chart the eigenvalues and the cumulative share of variance and apply common rules for deciding how many components to keep.
Component Scores & Loadings: Placing and Naming the Cities (with a Chart). You place every city on a two-dimensional map of the components and give the axes names from their loadings, the chart that makes PCA results easy to present.
Reconstruction Error: What You Lose with k Components. You rebuild the original data from one, two or three components and measure what is lost, so you can show exactly how faithful the summary is.
Summary
PCA finds the directions of largest variance, and variance depends on units, so variables in different units must be standardised first. A z-score is (x − mean) ÷ sd with the sample standard deviation STDEV.S. One formula with mixed references, =(B2-B$13)/B$14, fills the whole table. Every standardised column has mean 0 and standard deviation 1, every indicator gets equal weight, and the cities become directly comparable.
Now scroll up and do it yourself in the lab: means and standard deviations, the z-score table, the count of unusual incomes and the variance ratio that shows why this step matters. It takes about fifteen minutes, and the Coach checks every step.
Frequently asked questions
Why do you standardise data before PCA?
PCA looks for directions of largest variance, and variance depends on the unit of each variable. Standardising gives every variable mean 0 and standard deviation 1, so a variable does not dominate just because it is measured in bigger numbers.
How do I calculate a z-score in Excel?
Use =(x-mean)/sd, for example =(B2-B$13)/B$14 with the mean and standard deviation in helper rows, or =STANDARDIZE(B2,B$13,B$14). Both give the same result.
Should I use STDEV.S or STDEV.P for z-scores?
For sample data use STDEV.S, which divides by n − 1. It matches CORREL and COVARIANCE.S in Excel, so your later correlation matrix will be consistent with the z-scores.
Is PCA on standardised data the same as PCA on the correlation matrix?
Yes. The covariance matrix of z-scores is the correlation matrix of the original data, so both give the same components. PCA on unscaled data uses the covariance matrix instead.
When should I not standardise before PCA?
When all variables share the same unit and their different spreads reflect real importance, for example spending in dollars on several categories. Then PCA on the covariance matrix of centred data can be the better choice.
Can Excel do PCA without add-ins?
Yes. With z-scores, MMULT and TRANSPOSE for the correlation matrix and repeated matrix multiplication (power iteration) for the eigenvectors, you can build a full PCA with ordinary formulas.
Keep going: Principal Component Analysis in Excel: Standardise, Covariance, Eigenvectors & Scores
This free lab is lesson 1 of 20. Unlock the other 19 hands-on labs, the final exam and your certificate for a one-time $9.90.
- Covariance & Correlation Matrices with MMULT and TRANSPOSE
- Power Iteration: the First Eigenvector with Repeated MMULT
- Eigenvalue & Explained Variance: How Much Does PC1 Capture?
- The Second Component: Deflation and Another Power Iteration
- Scree Plot & Cumulative Variance: How Many Components? (with a Chart)
- Component Scores & Loadings: Placing and Naming the Cities (with a Chart)
- Reconstruction Error: What You Lose with k Components
- Checking a PCA: Rebuilding R from Eigenvectors, Trace and Determinant
- Faster Eigenvectors: Repeated Squaring and Convergence Speed
- Covariance PCA: What Changes without Standardising
- Scoring New Cities: Projecting with the Reference Mean, SD and Directions
- Unusual Cities: Hotelling's T² and the Residual Q (with Conditional Formatting)
- Correlation Circle & Communalities: How Well Two Components Show Each Indicator (with a Chart)
- Broken Stick & Parallel Analysis: Stricter Rules for How Many Components (with a Chart)
- A Composite Index from PC1: 0–100 Scaling vs Equal Weights (with a Chart)
- Rotating Two Components: Varimax by Formula
- Sensitivity: How One Typo Moves the Correlations and PC1
- The Smallest Component: Inverse Iteration with MINVERSE to Spot Redundant Indicators
- Capstone Project: A PCA Dashboard for Twelve River-Valley Towns (with a Chart)