Community Blog

Keep up-to-date on postgraduate related issues with our quick reads written by students, postdocs, professors and industry leaders.

Pearson correlation: formula, example and when to use it

Picture of DiscoverPhDs
A worn metal straightedge follows a rising scatter of graphite dots on textured paper.

Pearson correlation measures how closely two numerical variables follow a straight line. The Pearson correlation coefficient, Pearson’s r, runs from −1 to +1. A value of −1 is a perfect negative straight line, 0 means no linear (straight-line) relationship and +1 is a perfect positive straight line. It’s worked out by dividing how much the two variables vary together by how much each varies on its own.

Because r only measures straight-line relationships, you should plot your data before you calculate it. A curved pattern can give a misleading r, and so can a single outlier. A significant Pearson correlation isn’t necessarily a strong one either: with a big enough sample, even a weak r passes a significance test.

If your data are ranks or ordered categories, are badly skewed or have outliers, Spearman’s rank correlation is usually the better choice. For 14 blood donors’ haemoglobin and packed cell volume, the hand calculation below gives r = 0.877, with a 95% confidence interval of 0.65 to 0.96.

What does the Pearson correlation coefficient tell you?

Pearson’s r tells you two things about a linear relationship: its direction and its strength. A positive r means that as one variable goes up, the other tends to go up too. A negative r means that as one goes up, the other tends to go down. The closer r is to +1 or −1, the more tightly the points cluster around a straight line.

Two things r doesn’t tell you catch many students out.

  • It isn’t the slope. The coefficient shares only its sign with the gradient of the line. Multiply every y value by 10 and the line becomes ten times steeper, but r doesn’t change. If you want to know how much y changes per unit of x, you need regression instead.
  • r = 0 doesn’t mean ‘no relationship’. It means no straight-line relationship. A perfect U-shaped (quadratic) pattern can give an r of 0, even though y is completely determined by x.

That’s why a scatterplot comes first. It shows you whether a straight line is a fair summary before you reduce the pattern to a single number.

The Pearson correlation formula

The Pearson correlation formula compares how the two variables move together with how much each one varies:

r = Sxy ÷ √(Sxx × Syy)

where:

  • Sxx is the sum of squared deviations of x from its mean: Σ(x − x̄)²
  • Syy is the same for y: Σ(y − ȳ)²
  • Sxy is the sum of cross-products: Σ(x − x̄)(y − ȳ)

If you’re calculating by hand, these shortcut versions save you working out every deviation:

  • Sxx = Σx² − (Σx)² ÷ n
  • Syy = Σy² − (Σy)² ÷ n
  • Sxy = Σxy − (Σx)(Σy) ÷ n

The same formula can be written as the covariance of x and y divided by the product of their standard deviations. Covariance on its own depends on the units you measure in, so its size is hard to interpret. Dividing by the two standard deviations removes the units and scales the result, so r always falls between −1 and +1.

The formula is also symmetrical: the correlation between A and B equals the correlation between B and A. So it doesn’t matter which variable you call x.

Worked example: calculating Pearson’s r by hand

This example uses a small real dataset: blood haemoglobin (Hb) and packed cell volume (PCV) for 14 female blood bank donors. It comes from the statstutor guide to Pearson’s correlation, which reports an SPSS result of r = 0.877. Working it by hand shows where that number comes from.

Donor Hb (x) PCV (y)
1 15.5 0.450
2 13.6 0.420
3 13.5 0.440
4 13.0 0.395
5 13.3 0.395
6 12.4 0.370
7 11.1 0.390
8 13.1 0.400
9 16.1 0.445
10 16.4 0.470
11 13.4 0.390
12 13.2 0.400
13 14.3 0.420
14 16.1 0.450

Source: statstutor, Pearson’s correlation (data table, page 2).

Before calculating anything, the guide checks the assumptions. The scatterplot looks linear, and both variables’ skewness is small enough to treat them as normally distributed. After that, the arithmetic takes five steps.

Step Calculation Result
1. Totals Σx = 195.0; Σy = 5.835 (n = 14) Means: x̄ = 13.93, ȳ = 0.4168
2. Sums of squares and products Σx² = 2,747.60; Σy² = 2.443475; Σxy = 81.802
3. Sxx 2,747.60 − 195.0² ÷ 14 31.529
4. Syy and Sxy Syy = 2.443475 − 5.835² ÷ 14; Sxy = 81.802 − (195.0 × 5.835) ÷ 14 Syy = 0.011530; Sxy = 0.52879
5. r 0.52879 ÷ √(31.529 × 0.011530) = 0.52879 ÷ 0.60294 r = 0.877

Source: DiscoverPhDs’ own calculation from the statstutor data; it matches the r = 0.877 the guide reports.

So donors with higher haemoglobin tend to have higher packed cell volume, and the points sit close to a straight line. The next questions are whether this could be chance, and how precisely 14 donors pin r down.

Is the correlation significant? The t test and a confidence interval

To test whether a Pearson correlation could have arisen by chance, convert r into a t statistic:

t = r × √(n − 2) ÷ √(1 − r²), with n − 2 degrees of freedom. For a correlation, that’s the number of pairs minus two.

You then compare t with the t distribution, just as in a t-test.

The null hypothesis is that there is no linear correlation in the population. For the donor data:

  • t = 0.877 × √12 ÷ √(1 − 0.769) = 6.32, with 12 degrees of freedom.
  • In NIST’s table of t critical values, the two-sided 5% critical value for 12 degrees of freedom is 2.179. The value in the 0.999 column is 3.930, which marks a two-sided P of 0.002.
  • Our t of 6.32 is well beyond both, so P < 0.002. SPSS displays the P value as .000, which the guide reports as p < .001.

A P value says nothing about how strong a relationship is, though. With a very weak correlation of 0.1, a sample of over 1,000 would still give a significant result. That’s why it’s good practice to report a confidence interval for r.

Calculating a 95% confidence interval for r

The sampling distribution of r is skewed, more so the closer the true correlation is to ±1. So you build the interval on a transformed scale (Fisher’s z′) and then convert it back:

  1. Convert r to z′ = 0.5 × ln[(1 + r) ÷ (1 − r)]. For r = 0.877, z′ = 1.363.
  2. The standard error of z′ is 1 ÷ √(n − 3) = 1 ÷ √11 = 0.302.
  3. Add and subtract 1.96 standard errors: 1.363 ± 0.591 gives 0.772 to 1.954.
  4. Convert both limits back to r: 0.65 to 0.96.

The result: the population correlation (ρ, rho) is plausibly anywhere from about 0.65 to 0.96. Fourteen donors are enough to show a clearly positive relationship (the whole interval is above 0.6). They aren’t enough to say whether it’s ‘strong’ or ‘very strong’ on the scale in the next section.

R’s cor.test function reports this interval automatically, so you rarely need to do it by hand. Knowing the steps helps you explain it in a viva or methods section.

How strong is a Pearson correlation? Reading r and r squared

There’s no universal scale for how strong a Pearson correlation is, and published labels disagree. One common set, used in the BMJ’s Statistics at Square One and in the statstutor guide (which credits Evans, 1996), is:

Absolute value of r Label
0.00 to 0.19 Very weak
0.20 to 0.39 Weak
0.40 to 0.59 Moderate
0.60 to 0.79 Strong
0.80 to 1.00 Very strong

Source: BMJ, Statistics at Square One, chapter 11; statstutor, Pearson’s correlation.

On this scale, an r of 0.7 counts as strong and an r of 0.9 as very strong. But treat these as rough guides. The BMJ chapter itself calls them ‘rather arbitrary limits’ and says the context of the results should be considered.

A 2018 tutorial on correlation coefficients in Anesthesia & Analgesia goes further. Most researchers, it says, would probably agree that below 0.1 is negligible and above 0.9 very strong. Values in between are disputable: 0.65 could be ‘good’ or ‘moderate’, depending on the rule of thumb. And calling 0.39 ‘weak’ but 0.40 ‘moderate’ is hard to defend.

The range of values in your sample matters too. Correlations tend to be higher across a wide range of values than across a narrow one. In one simulated dataset, r is 0.6 across the whole range but only 0.34 within a narrow slice. If your sample covers only part of the possible range, r will tend to be lower than it would be across the full range.

What this means for you: describe r with a label if your department expects one, but say which scheme you used. Then let the confidence interval and your research question do the real interpreting.

What r squared adds

Squaring r gives the coefficient of determination, r². It is read as the proportion of variance in one variable that is accounted for by the other. For the donor data, 0.877² = 0.769: about 77% of the variation in PCV goes with its linear relationship to Hb. The other 23% isn’t accounted for by that linear relationship.

Two cautions apply. r² is always positive, so it loses the direction of the relationship. And ‘accounted for’ is statistical language, not a claim that one variable causes the other.

When can you use Pearson correlation? The assumptions

You can calculate r for any set of paired numbers. But a P value or confidence interval for the population needs these assumptions to hold:

  1. A random or representative sample. If your sample doesn’t represent the population, no correlation from it can tell you about that population.
  2. Both variables continuous and jointly normal (a bivariate normal distribution). In practice, check that each variable is roughly normal and that the scatterplot looks like a straight-line band, not a curve.
  3. No relevant outliers. One extreme point can pull r a long way. Don’t simply delete outliers: run the analysis with and without them and compare.
  4. Independent pairs. Each x–y pair must be measured independently of the others, typically one pair per person. Several measurements on the same people break this rule and need a different method.

If normality or linearity fails, or there are outliers, you still have options. Transforming a skewed variable (taking logs, for example) can make it closer to normal and the relationship closer to a straight line. Otherwise, use Spearman’s rank correlation.

Common mistake: using Pearson correlation when you have set one variable’s values yourself. If you assigned participants to fixed doses, for example, x is no longer a random variable. Regression is the usual tool there, because it treats the x values as fixed and estimates y from them.

Pearson vs Spearman correlation: which should you use?

Use Pearson correlation for a straight-line relationship between two continuous, roughly normal variables. Use Spearman’s rank correlation when the relationship is monotonic but curved, or when the data are ordinal, skewed or have outliers. (Monotonic means one variable consistently rises, or consistently falls, as the other rises.)

Spearman is simply Pearson’s r calculated on the ranks of the data instead of the raw values. Ranking turns any strictly monotonic curve into a straight line of ranks, and it limits how far one extreme value can pull the result.

Pearson correlation Spearman’s rank correlation
Measures Linear (straight-line) relationship Monotonic relationship (straight or curved)
Data Continuous: interval or ratio Continuous or ordinal (ranked)
Needs normal data? Yes, for valid P values and CIs No
Outliers Can distort r badly Much less affected
Range −1 to +1 −1 to +1
Calculated from Raw values Ranks of the values

Source: Schober, Boer and Schwarte (2018), Anesthesia & Analgesia; statstutor, Spearman’s correlation; BMJ, Statistics at Square One, chapter 11.

The difference shows up clearly on curved data. Take points that rise along a perfect curve: in one worked example, Pearson’s r is 0.699 but Spearman’s coefficient is 1. The ranks line up exactly, even though the raw values don’t. On data that are close to linear, the two can be very close.

Which route fits you?

  • Two measurements, roughly normal, straight-line scatter, no extreme points: Pearson.
  • Ordered categories, such as a pain score or a single agree–disagree item: Spearman.
  • Counts such as a number of moles, or a clear outlier: Spearman.
  • Skewed data: Spearman, or transform the data (taking logs, for example) and use Pearson.
  • A curved pattern that keeps rising or keeps falling: Spearman.
  • A pattern that rises then falls: neither. Plot it and look for a different model.

Our guide to monotonic relationships explains what Spearman’s coefficient measures in more detail.

What correlation can’t tell you

Even a strong, significant r has limits.

  • It doesn’t show causation. Monthly deaths from heart disease and ice cream sales are negatively associated, but both depend on a third factor: temperature. Reading ability and foot length in children can correlate strongly: r = .88 in a sample of 54. Within each age group, there appears to be no correlation at all, so once age is taken into account the link may be spurious.
  • It doesn’t measure agreement. If you’re comparing two ways of measuring the same thing, a high r doesn’t show the methods agree. One method could read consistently higher than the other and still correlate perfectly. Method-comparison studies use agreement methods, such as the Bland–Altman approach, instead.
  • It can hide very different patterns. Quite different relationships, including a curve and a line distorted by one outlier, can produce the same r. Only a plot shows which you have.

How to report a Pearson correlation in your dissertation

A results sentence should give the direction, the strength, r, the sample size and the P value. The statstutor guide reports the donor example like this:

‘A Pearson’s correlation was run to determine the relationship between 14 females’ Hb and PCV values. There was a very strong, positive correlation between Hb and PCV (r = .88, N=14, p < .001).’

You can strengthen that by adding a confidence interval (95% is the usual choice). The 2018 tutorial says one should accompany every reported correlation. A template:

‘There was a [strength], [positive/negative] correlation between [variable 1] and [variable 2] (r = [value], 95% CI [lower] to [upper], N = [n], p = [value]).’

Include the scatterplot as a figure with a clear figure legend, and say in your methods how you checked the assumptions. If the result isn’t significant, say there wasn’t enough evidence of a linear correlation. That isn’t the same as showing there’s no relationship, especially in a small sample.

Correlation is only one of the analyses you might need. If you’re comparing the means of two groups rather than relating two measurements, use a t-test; for two categorical variables, use a chi-square test. Our guide to the statistical treatment of data explains descriptive and inferential statistics. It also covers the Type I and Type II errors a significance test can make.

Running it in SPSS, R and Excel

  • SPSS: Analyze > Correlate > Bivariate, then tick Pearson. The same dialog offers Spearman’s rho and Kendall’s tau-b. IBM’s own guidance is to screen your data for outliers and check for a linear relationship first.
  • R: cor.test(x, y) uses Pearson by default. It reports t with n − 2 degrees of freedom, the P value and, with at least four complete pairs, a confidence interval based on Fisher’s z. Add method = "spearman" for Spearman.
  • Excel: =PEARSON(A2:A15, B2:B15) returns r. It gives an #N/A error if the two ranges are empty or hold different numbers of values. Excel’s function returns r only, so use the t formula above for the P value.

Next steps with your own data

Start with a scatterplot of your two variables. If the points form a rough straight-line band with no extreme values, calculate Pearson’s r, test it and report it with its confidence interval. If the pattern curves, your data are ranks or a few points sit far from the rest, switch to Spearman.

Then write it up in plain terms. Say what the Pearson correlation shows, how precise it is and what it can’t show. A good methods section explains why you chose a test, not just which button you pressed.

If you’re considering a research degree that uses analyses like this, browse current PhD opportunities, or read our guide to doing a PhD in statistics.

Sources

Facebook
Twitter
LinkedIn
Pinterest

Join

Thousands

Join thousands of other students and stay up to date with the latest PhD programmes, funding opportunities and advice.

Browse PhDs Now

Other Posts
Interviews
Ellie Hurer Profile
Ellie Hurer

Ellie is a final year PhD student at the University of Hertfordshire, investigating a protein which is implicated in pancreatic cancer; this work can improve the efficacy of cancer drug treatments.

Read More »
Emma Strand

Emma is a third year PhD student at the University of Rhode Island. Her research focuses on the physiological and genomic response to climate change stressors.

Read More »

Browse PhDs Now

Join Thousands of Students

Join thousands of other students and stay up to date with the latest PhD programmes, funding opportunities and advice.