Correlation Coefficient Calculator
For the example data (advertising spend against monthly sales, 10 pairs) Pearson’s r ≈ 0.96356: a very strong positive correlation, with r² ≈ 0.92844, p ≈ 7.3835 × 10⁻⁶ and a 95% confidence interval for r of ≈ 0.84901 to 0.99160. Spearman’s rank correlation is ρ ≈ 0.96341. Paste your own x, y pairs (one pair per line, or x and y as two lists, up to 1,000 pairs) to get r, r², how strong it is, the p-value from an n − 2 degrees of freedom t test, a Fisher z confidence interval, Spearman’s ρ with a rank table, and a scatter plot with the line.
Updated Runs in your browser: nothing you enter is uploadedHow this tool works
Pearson correlation coefficient
r ≈ 0.96356
A very strong positive linear correlation (a rule of thumb): r² ≈ 0.92844 means about 92.844% of the variation in y goes with x along a straight line, from 10 pairs. p ≈ 7.3835 × 10⁻⁶, below 0.05, so r is statistically significant at the 5% level. The 95% confidence interval for r is ≈ 0.84901 to 0.99160. Spearman rank correlation: ρ ≈ 0.96341.
Pearson correlation
- Pearson correlation coefficient (r)
- ≈ 0.96356
- Coefficient of determination (r²)
- ≈ 0.92844
- r² as a percentage
- ≈ 92.844%
- Strength (rule of thumb)
- Very strong, positive
- t statistic
- ≈ 10.188
- Degrees of freedom (n − 2)
- 8
- p-value (two-tailed)
- ≈ 7.3835 × 10⁻⁶
- 95% confidence interval for r
- ≈ 0.84901 to 0.99160
Spearman rank correlation
- Spearman rank correlation (ρ)
- ≈ 0.96341
- Strength (rule of thumb)
- Very strong, positive
- t statistic
- ≈ 10.167
- p-value (two-tailed)
- ≈ 7.4992 × 10⁻⁶
- Tied values
- x: 2 values in 1 tie group; y: 2 values in 1 tie group
The p-value uses the t distribution with n − 2 degrees of freedom, the usual approximation for ρ (SciPy’s spearmanr does the same); it is less reliable with fewer than about 10 pairs or many ties.
Working sums
- Number of pairs (n)
- 10
- Mean of x (x̄)
- 4.52
- Mean of y (ȳ)
- 24.1
- Sxx = Σ(x − x̄)²
- 25.096
- Sxy = Σ(x − x̄)(y − ȳ)
- 95.68
- Syy = Σ(y − ȳ)²
- 392.9
- Σx
- 45.2
- Σy
- 241
- Σx²
- 229.4
- Σy²
- 6,201
- Σxy
- 1,185
Scatter plot
How strong is the correlation?
| |r| (or |ρ|) | Label | r² (or ρ²) | Your data |
|---|---|---|---|
| 0.00 to below 0.20 | Very weak | 0 to below 0.04 | |
| 0.20 to below 0.40 | Weak | 0.04 to below 0.16 | |
| 0.40 to below 0.60 | Moderate | 0.16 to below 0.36 | |
| 0.60 to below 0.80 | Strong | 0.36 to below 0.64 | |
| 0.80 to 1.00 | Very strong | 0.64 to 1 | Pearson r and Spearman ρ |
These labels are a rough convention, not a law: what counts as strong depends on the field, and a small n can make even a large r a fluke. The p-value and the confidence interval above say how much to trust it.
Rank table for Spearman’s ρ
Equal values share the average of the ranks they occupy, so a tie for ranks 2 and 3 gives both 2.5. Spearman’s ρ is Pearson’s r computed on these ranks.
| # | x | y | Rank of x | Rank of y |
|---|---|---|---|---|
| 1 | 2.1 | 14 | 1 | 1 |
| 2 | 2.8 | 18 | 2 | 3 |
| 3 | 3.4 | 17 | 3.5 | 2 |
| 4 | 3.4 | 22 | 3.5 | 4 |
| 5 | 4 | 24 | 5 | 5.5 |
| 6 | 4.7 | 24 | 6 | 5.5 |
| 7 | 5.2 | 27 | 7 | 7 |
| 8 | 5.9 | 31 | 8 | 9 |
| 9 | 6.5 | 29 | 9 | 8 |
| 10 | 7.2 | 35 | 10 | 10 |
How big does r have to be? Critical values for the p-value test
| Pairs (n) | Degrees of freedom (n − 2) | 10% level | 5% level | 1% level |
|---|---|---|---|---|
| 3 | 1 | 0.9877 | 0.9969 | 0.9999 |
| 4 | 2 | 0.9000 | 0.9500 | 0.9900 |
| 5 | 3 | 0.8054 | 0.8783 | 0.9587 |
| 6 | 4 | 0.7293 | 0.8114 | 0.9172 |
| 7 | 5 | 0.6694 | 0.7545 | 0.8745 |
| 8 | 6 | 0.6215 | 0.7067 | 0.8343 |
| 10 | 8 | 0.5494 | 0.6319 | 0.7646 |
| 12 | 10 | 0.4973 | 0.5760 | 0.7079 |
| 17 | 15 | 0.4124 | 0.4821 | 0.6055 |
| 22 | 20 | 0.3598 | 0.4227 | 0.5368 |
| 32 | 30 | 0.2960 | 0.3494 | 0.4487 |
| 52 | 50 | 0.2306 | 0.2732 | 0.3542 |
| 102 | 100 | 0.1638 | 0.1946 | 0.2540 |
What an r of a given size means
| r (or −r) | r² | r² as a percentage | Rule-of-thumb label |
|---|---|---|---|
| 0.1 | 0.01 | 1% | Very weak |
| 0.3 | 0.09 | 9% | Weak |
| 0.5 | 0.25 | 25% | Moderate |
| 0.7 | 0.49 | 49% | Strong |
| 0.9 | 0.81 | 81% | Very strong |
| 0.99 | 0.9801 | 98.01% | Very strong |
Pearson r against Spearman ρ on six patterns
| Pattern | Data (x, y) | Pearson r | Spearman ρ | What it shows |
|---|---|---|---|---|
| A perfect straight line | 1, 2; 2, 4; 3, 6; 4, 8 | 1 | 1 | Both reach 1 when every point is on one rising line. |
| A steady rise with some scatter | 1, 2; 2, 4; 3, 5; 4, 4; 5, 6; 6, 7; 7, 8; 8, 9 | ≈ 0.96529 | ≈ 0.95810 | Close, because the trend is nearly straight. |
| The same data with one outlier | 1, 2; 2, 4; 3, 5; 4, 4; 5, 6; 6, 7; 7, 8; 8, 9; 9, 30 | ≈ 0.73800 | ≈ 0.97072 | One extreme point drags Pearson down; ranks barely notice it. |
| A curve that always rises, y = x³ | 1, 1; 2, 8; 3, 27; 4, 64; 5, 125; 6, 216; 7, 343; 8, 512 | ≈ 0.93183 | 1 | Spearman is exactly 1 for any steadily rising pattern; Pearson is lower because it is not a straight line. |
| A U-shaped curve, y = x² for x from −3 to 3 | -3, 9; -2, 4; -1, 1; 0, 0; 1, 1; 2, 4; 3, 9 | 0 | 0 | A strong relationship with zero correlation: neither coefficient sees a U. |
| A heating bill that falls as it warms | 30, 210; 35, 190; 42, 165; 50, 130; 55, 110; 63, 80; 70, 60 | ≈ −0.99879 | −1 | A perfect rank order (ρ is −1) on a nearly straight line. |
Worked examples
| Problem | Data | Pearson r | Spearman ρ | p-value for r | 95% confidence interval for r |
|---|---|---|---|---|---|
| Advertising spend and monthly sales, in $1,000s (the example above) | 2.1, 14; 2.8, 18; 3.4, 17; 3.4, 22; 4.0, 24; 4.7, 24; 5.2, 27; 5.9, 31; 6.5, 29; 7.2, 35 | ≈ 0.96356 | ≈ 0.96341 | ≈ 7.3835 × 10⁻⁶ | ≈ 0.84901 to 0.99160 |
| Outdoor temperature (°F) and a monthly heating bill ($): as one rises the other falls | 30, 210; 35, 190; 42, 165; 50, 130; 55, 110; 63, 80; 70, 60 | ≈ −0.99879 | −1 | ≈ 9.7232 × 10⁻⁸ | ≈ −0.99983 to −0.99146 |
| A noisy relationship in a small sample | 1, 5; 2, 3; 3, 6; 4, 4; 5, 7; 6, 3; 7, 8; 8, 5 | ≈ 0.30649 | ≈ 0.27713 | ≈ 0.46030 | ≈ −0.50787 to 0.83157 |
| A steady rise, 8 pairs | 1, 2; 2, 4; 3, 5; 4, 4; 5, 6; 6, 7; 7, 8; 8, 9 | ≈ 0.96529 | ≈ 0.95810 | ≈ 0.00010180 | ≈ 0.81499 to 0.99390 |
| The same data with one outlier added at (9, 30) | 1, 2; 2, 4; 3, 5; 4, 4; 5, 6; 6, 7; 7, 8; 8, 9; 9, 30 | ≈ 0.73800 | ≈ 0.97072 | ≈ 0.023199 | ≈ 0.14489 to 0.94094 |
| A curve that always rises, y = x³ for x from 1 to 8 | 1, 1; 2, 8; 3, 27; 4, 64; 5, 125; 6, 216; 7, 343; 8, 512 | ≈ 0.93183 | 1 | ≈ 0.00075199 | ≈ 0.66157 to 0.98785 |
| Scores with tied values (average ranks) | 1, 3; 2, 2; 2, 4; 3, 3; 4, 6; 4, 5; 5, 7; 6, 7 | ≈ 0.88745 | ≈ 0.87805 | ≈ 0.0032705 | ≈ 0.48786 to 0.97955 |
| Every x is the same | 4, 1; 4, 2; 4, 3 | Undefined (all x values are equal) | Undefined (all x values or all y values are equal) | Undefined (all x values are equal) | Undefined (all x values are equal) |
How to calculate a correlation coefficient by hand
- Find the means. Add up the x values and the y values and divide each sum by the number of pairs. For the example, Σx = 45.2 and Σy = 241, so x̄ = 4.52 and ȳ = 24.1 with n = 10.
- Add up the spreads. Sxx = Σx² − (Σx)² ÷ n, Syy = Σy² − (Σy)² ÷ n and Sxy = Σxy − Σx × Σy ÷ n. For the example Sxx = 25.096, Syy = 392.9 and Sxy = 95.68.
- Divide for r. r = Sxy ÷ √(Sxx × Syy) = 95.68 ÷ √(25.096 × 392.9) ≈ 0.96356. Square it for r² ≈ 0.92844.
- Test it against zero. Find t = r × √((n − 2) ÷ (1 − r²)) ≈ 10.188 with 8 degrees of freedom, then look up the two-tailed p-value: p ≈ 7.3835 × 10⁻⁶. A p-value below 0.05 means r is statistically significant at the 5% level.
- Add a confidence interval. Fisher’s z = atanh(r) ≈ 1.9934 has standard error 1 ÷ √(n − 3) ≈ 0.37796. For 95%, take z ± 1.9600 × 0.37796, then convert back with tanh to get ≈ 0.84901 to 0.99160.
Frequently asked questions
- What is a correlation coefficient?
- A single number between −1 and 1 that says how closely two variables move together. Pearson’s r measures the straight-line part of that: +1 is a perfect rising line, −1 a perfect falling line and 0 no straight-line relationship. For the example (advertising spend and sales) r ≈ 0.96356, so the points lie very close to a rising line. Spearman’s ρ does the same on ranks.
- How do you calculate Pearson’s r?
- r = Sxy ÷ √(Sxx × Syy), where Sxx and Syy are the sums of squared deviations of x and y from their means and Sxy is the sum of the products of the deviations. For the example Sxy = 95.68, Sxx = 25.096 and Syy = 392.9, giving r ≈ 0.96356. The calculator forms these sums as exact fractions, so only the final square root is approximate. The same number is what a spreadsheet’s CORREL function returns.
- How do I interpret r?
- Read the sign for the direction (positive: y tends to rise with x; negative: it falls) and the size of |r| for the strength. A common rule of thumb calls |r| from 0.00 to 0.20 very weak, 0.20 to 0.40 weak, 0.40 to 0.60 moderate, 0.60 to 0.80 strong and 0.80 to 1.00 very strong. The example is very strong, positive. The labels are a convention, not a law, and different fields use different cut-offs. r² tells you more: r² ≈ 0.92844 means that about 92.844% of the variation in sales goes with spend along a straight line.
- What is the difference between Pearson and Spearman correlation?
- Pearson’s r measures how well the pairs follow a straight line, using the values themselves, so outliers and curves affect it. Spearman’s ρ replaces each value by its rank and then computes Pearson’s r on the ranks, so it measures how consistently y rises (or falls) with x, whatever the shape. For y = x³ on x from 1 to 8 Spearman gives ρ = 1 while Pearson gives r ≈ 0.93183. Adding one outlier to a steady rise moves Pearson from 0.96529 to 0.73800, while Spearman goes from 0.95810 to 0.97072.
- How does Spearman’s correlation handle tied values?
- Tied values get the average of the ranks they would have occupied: two values tied for ranks 2 and 3 both get rank 2.5. The rank table shows this for the first 50 pairs. In the example the repeated x value 3.4 and the repeated y value 24 each take an average rank, and ρ ≈ 0.96341. Because ρ is computed as Pearson’s r of these ranks, it stays correct with ties; the tie counts are listed under the Spearman results (x: 2 values in 1 tie group; y: 2 values in 1 tie group).
- How is the p-value for r calculated?
- The test asks whether a correlation this large could easily arise from unrelated variables. It uses t = r × √((n − 2) ÷ (1 − r²)) with n − 2 degrees of freedom and reads the two-tailed probability from Student’s t distribution. For the example t ≈ 10.188 on 8 degrees of freedom gives p ≈ 7.3835 × 10⁻⁶. The p-value is not the probability that r is zero; it is how surprising a result at least this extreme would be if the true correlation were zero. The test assumes the pairs are independent and roughly bivariate normal.
- How is the confidence interval for r calculated?
- r’s sampling distribution is skewed, so the interval is built on Fisher’s z = atanh(r), which is close to normal with standard error 1 ÷ √(n − 3). The calculator takes z ± (the normal critical value) × that standard error and converts the ends back with tanh. For the example the 95% interval is ≈ 0.84901 to 0.99160; it is not symmetric around r, and it is the same method SciPy uses. It needs at least 4 pairs and is not defined when |r| is 1. The “Confidence level” menu offers 90%, 95% and 99%.
- How large must r be to be statistically significant?
- It depends on the number of pairs: more pairs, smaller r needed. With 12 pairs (10 degrees of freedom) |r| must exceed 0.5760 at the 5% level; the critical-value table above lists other sizes at the 10%, 5% and 1% levels. Significance is not importance: with a very large sample a tiny r is significant, and with a small sample even a large r may not be. For r = 0.5 the 95% interval is −0.189 to 0.859 with 10 pairs but only 0.337 to 0.634 with 100.
- Does a high correlation mean one thing causes the other?
- No. Two variables can move together because one causes the other, because a third factor drives both, or by coincidence. Correlation describes the data you have; it cannot tell you which way, if any, causation runs. It also says nothing about how much y would change if you changed x, which is a question for a fitted line or an experiment.
- Can r be 0 when there is a clear relationship?
- Yes. Pearson’s r only detects straight-line trends. For the U-shaped data y = x² on x from −3 to 3 (-3, 9; -2, 4; -1, 1; 0, 0; 1, 1; 2, 4; 3, 9) the calculator gives r = 0 and ρ = 0, although y is exactly determined by x. Always look at the scatter plot as well as the number.
- What happens with only two pairs, or when all values are equal?
- With two pairs the line through them is perfect, so r is always 1 or −1 (1, 3; 2, 8 gives r = 1) and there is no test: the p-value needs at least 3 pairs (the calculator says “Needs at least 3 pairs”) and the interval at least 4. If every x (or every y) is the same, r is undefined because it divides by the spread: for 4, 1; 4, 2; 4, 3 the calculator shows “Undefined (all x values are equal)” instead of a made-up number.
- How do I enter the data, and what are the limits?
- Put one pair per line, with x and y separated by a comma, a space, a tab or a semicolon, so a copied spreadsheet range works. A first line of column names is skipped. Or put the x values in the first box and the y values in the second. Up to 1,000 pairs are used; more are refused rather than cut, so the result always covers everything you pasted. A line that is not two numbers is reported with its line number.
- Is the result exact?
- For ordinary decimals (up to 30 digits each) the sums, means, Sxx, Sxy, Syy and r² are exact fractions, and only the square root for r is approximate, found to 30 decimals; Spearman’s ranks are exact too. If you type a value in exponent notation (1.5e3) or with more than 30 digits, the whole data set is computed in double precision and every figure carries ≈. The p-value and the interval use floating-point numerics, checked against SciPy to many digits. The “Significant digits” menu rounds what you see, half away from zero.
- How is this different from the linear regression calculator?
- This page is about how strong the relationship is: r, r², its significance and confidence interval, and rank correlation. A regression calculator is about the line itself: the slope, the intercept, predictions and residuals. The scatter plot here draws the least-squares line only so you can see the trend that r summarises.
How it works
Each x and y is read as an exact decimal (up to 30 digits) and the sums use exact fractions of whole numbers. With n pairs: Sxx = Σx² − (Σx)² ÷ n, Syy = Σy² − (Σy)² ÷ n and Sxy = Σxy − Σx × Σy ÷ n, which avoids the cancellation error of the textbook shortcut in floating point. Pearson’s r = Sxy ÷ √(Sxx × Syy) and r² = Sxy² ÷ (Sxx × Syy) is exact; the square root is found with integer arithmetic to 30 decimals and is exact for perfect squares. If a value uses exponent notation or has more than 30 digits, the sums are taken in double precision (means first, then squared deviations) and results are marked ≈. Spearman’s ρ is Pearson’s r of the ranks, where tied values receive the mean of the ranks they span; ranks are multiples of one half, so ρ is exact. The significance test is t = r √((n − 2) ÷ (1 − r²)) with n − 2 degrees of freedom and a two-tailed p-value from Student’s t distribution (the same test SciPy’s pearsonr uses, and the usual approximation for spearmanr). The confidence interval is tanh(atanh(r) ± z* ÷ √(n − 3)) with z* the standard normal critical value for the chosen level; it needs n ≥ 4. The critical values of r in the table are t* ÷ √(df + t*²). The strength labels (very weak below 0.20, weak, moderate, strong, very strong from 0.80) are a rule of thumb after Evans (1996), not a statistical standard. The scatter plot converts the numbers to floating point only to place them on the page and draws the least-squares line for orientation. The rank table lists the first 50 pairs in the order entered. Numerics for the t and normal distributions are in double precision and were checked against SciPy. This describes the data you enter; it does not show causation.
Sources
- NIST/SEMATECH e-Handbook of Statistical Methods
- Pearson correlation coefficient, Wikipedia
- Spearman’s rank correlation coefficient, Wikipedia
- Fisher transformation, Wikipedia
- scipy.stats.pearsonr, SciPy documentation
- scipy.stats.spearmanr, SciPy documentation
- J. D. Evans, Straightforward Statistics for the Behavioral Sciences, Brooks/Cole, 1996 (the strength labels)
More free tools
- Linear Regression CalculatorPaste x, y pairs and get the line of best fit y = a + bx, slope, intercept, r, r², standard error, predictions, a residual table and a scatter plot.
- Standard Deviation CalculatorPaste numbers and get the standard deviation (sample and population), variance, mean, quartiles and z-scores, with the step-by-step working and a dot plot.
- Average CalculatorFind the average (mean), median, mode and range of any list of numbers, plus standard deviation and a weighted average. Paste a column from a spreadsheet.
- Percentile and Quartile CalculatorPaste numbers to get Q1, median, Q3, the interquartile range, outliers, any percentile and a value’s percentile rank, by three methods, with a box plot.
- Chi-Square CalculatorChi-square test of independence or goodness of fit from your counts: statistic, p-value, expected counts, Cramér’s V and critical values at your alpha.
- GPA CalculatorWork out your GPA from credits and letter grades or percentages: unweighted, weighted (Honors, AP/IB), cumulative, and the GPA you need next.
More: Statistics, probability and gradesAll math & numbersAll toolsHome & DIY calculators