Pearson Correlation Calculator
Pearson r, r squared, the regression line and a two sided p value from two lists of paired numbers.
What it does
Correlation is the workhorse of statistics. Give it two lists of paired numbers and it tells you how tightly the second one moves with the first, on a scale from -1 through 0 to 1. Pearson r is the version that looks for straight line relationships, and it is the one that comes with the familiar r squared.
The number itself is easy to misread, so it is worth being precise. r of 1 means the points fall exactly on a straight line that slopes upwards. r of -1 means they fall exactly on a straight line that slopes downwards. r of 0 means there is no straight line relationship at all, which does not rule out a curve. The sign gives the direction and the size gives the strength.
Squaring r turns it into something you can read as a share. r squared is the fraction of the variation in y that the straight line relationship explains, so r of 0.95 gives an r squared of about 0.90. The same thing shows up in regression analysis, where the coefficient of determination is the square of the correlation.
A correlation on its own says nothing about cause. Two series can move together for all sorts of reasons, including a third variable pushing both, or the first one causing the second. That is why the tool also returns the slope and intercept of the least squares line, which tells you the size of the movement, and the p value, which tells you whether the pattern is more than chance given the sample size.
The tool takes plain lists of numbers, so it works for anything you can paste in: test scores against hours of study, sales against advertising spend, rainfall against crop yield. It reads the data exactly as typed, so clean numbers and matching row counts matter more than any setting on the page.
How to use
- Put the first variable in the top box, with numbers separated by commas.
- Put the matching second variable in the box below, in the same order, one value for each value above.
- Check that the pair count reported below matches the number of rows you expected.
- Read r first: the sign gives the direction and the size gives the strength of the straight line relationship.
- Use the slope and intercept to write the fitted line, then multiply any x by the slope to predict y.
- Check the p value last, and only then decide whether the pattern is more than chance at the sample size you have.
Formula
- x
- Values of the first list
- y
- Values of the second list, paired with x in the same order
- n
- Number of paired values
- Sxy
- Sum of the products of the deviations of x and y from their means
- Sxx, Syy
- Sums of the squared deviations of x and of y from their means
- t
- Test statistic compared with a t distribution on n - 2 degrees of freedom
The same r can also be written as the covariance divided by the product of the two standard deviations, which is why r has no units and does not change when you rescale either list. The p value assumes the pairs are independent and roughly follow a straight line with normal spread, and it needs at least three pairs to leave any degrees of freedom. If one list has no spread at all, the correlation is not defined and the tool will say so.
Worked example
Example: hours studied against a test score
Eight students study 2, 3, 4, 5, 6, 7, 8 and 9 hours. Their scores are 61, 66, 68, 73, 71, 78, 76 and 84.
- Means: the hours average 5.5 and the scores average 72.125.
- Sxy = 3293 - 8 x 5.5 x 72.125 = 119.5, Sxx = 284 - 8 x 5.5 squared = 42, and Syy = 41987 - 8 x 72.125 squared = 370.9.
- r = 119.5 / sqrt(42 x 370.9) = 119.5 / 124.8 = 0.9575.
- r squared = 0.9575 squared = 0.9168, so the straight line accounts for about 92 percent of the spread in the scores.
- Slope = 119.5 / 42 = 2.8452 and intercept = 72.125 - 2.8452 x 5.5 = 56.4762, so the fitted line is y = 2.8452 x + 56.4762.
- Test statistic: t = 0.9575 x sqrt(6) / sqrt(1 - 0.9168) = 8.129 on 6 degrees of freedom.
- The two sided p value is 0.0002, so with eight pairs the pattern is not explained by chance alone.
Reference table
| Value of r | Strength | Reading |
|---|---|---|
| 0.90 to 1.00 | Very strong | Points sit close to a straight line |
| 0.70 to 0.89 | Strong | A clear straight line relationship |
| 0.30 to 0.69 | Moderate | A real but loose relationship |
| 0.00 to 0.29 | Weak | Only a slight straight line relationship |
Limits
- It measures straight line association only, so a strong curve can come out as a weak correlation.
- The p value assumes independent pairs and a roughly normal spread, and neither is checked here.
- Outliers move r a lot, so one strange value can change the answer.
- Correlation never establishes cause, and two lists can share a common cause without one driving the other.
Common mistakes
- Pairing the values in the wrong order, which keeps the numbers valid but changes the answer.
- Reading r squared as the share of the cause and forgetting it only describes the spread.
- Using a small number of pairs and treating a large r as proof, when the p value shows how little the sample can carry.
- Leaving one list with a different number of values and assuming the tool will sort it out.
- Using correlation to make a causal claim, such as that raising advertising spend caused the sales rise.
Try it yourself
Quick checks. Answers sit tucked under each question.
With x = 1, 2, 3, 4, 5 and y = 2, 4, 6, 8, 10, what is the correlation?
r = 1.0000, a perfect positive straight line. Every y value is exactly twice the matching x value, and the fitted line is y = 2.0000 x + 0.0000.
With x = 5, 4, 3, 2, 1 and y = 1, 3, 4, 6, 9, what is the correlation and the p value?
r = -0.9851 with a p value of 0.0022. The relationship is very strong and negative, and with 5 pairs the two sided p value is 0.0022.
What happens if the two lists hold a different number of values?
The tool stops with an error and asks for the same number of values in both lists, because a correlation needs one y value for every x value.
Questions
What does r squared mean?
It is the square of the correlation and it reads as the share of the variation in y that the straight line relationship accounts for. An r of 0.95 gives an r squared of about 0.90, so about 90 percent of the spread is explained.
How many pairs do I need?
At least three for the math to run, and more for a result you can lean on. The p value widens fast with small samples, so five pairs is a demonstration rather than evidence.
Can I paste data with decimals and negative numbers?
Yes. Decimals, negative numbers and numbers written in scientific notation all work, and you can separate values with commas, spaces or semicolons.
Why is my p value 0?
With a perfect straight line fit the test statistic is infinite, so the p value is reported as 0. That only happens when the points sit exactly on a line, so read the r value and the pair count alongside it.
Does a strong correlation prove one thing causes the other?
No. Correlation only says the two move together. A third variable, a common cause, or pure coincidence can all produce a high r, so look for a mechanism before you claim cause.
What is the difference between this and a regression?
Regression estimates a line and its uncertainty from the same data. The correlation is one number taken from that line, so this tool gives you the slope and intercept as well as r.
Sources
- Penn State STAT 462: Pearson correlation coefficient r
- NIST/SEMATECH e-Handbook of Statistical Methods, glossary entry for correlation
- NIST Dataplot reference: Pearson dissimilarity, shows the correlation formula