Correlation Calculator
Find the Pearson correlation coefficient (r) between two paired data sets. Enter your values below, and see the formula, a worked example, and ready-to-use Python code underneath.
Enter your data
Comma, space, or newline separated.
Must have the same number of values as X, in matching order.
Please enter two equal-length lists of at least 3 paired values.
What correlation tells you
The Pearson correlation coefficient (r) measures the strength and direction of the linear relationship between two paired variables. It always falls between -1 and 1: values near 1 mean the variables tend to increase together, values near -1 mean one tends to increase as the other decreases, and values near 0 mean there's little to no linear relationship.
Correlation is closely related to covariance — in fact, it's just covariance rescaled to always sit between -1 and 1, which is what makes it comparable across variables measured in completely different units.
Correlation formula
Python code
You can compute correlation manually, or with Python's statistics, NumPy, or SciPy:
# Method 1 — manual calculation X = [2, 4, 6, 8, 10] Y = [65, 70, 75, 85, 95] n = len(X) mean_x, mean_y = sum(X) / n, sum(Y) / n numerator = sum((x - mean_x) * (y - mean_y) for x, y in zip(X, Y)) denom_x = sum((x - mean_x) ** 2 for x in X) denom_y = sum((y - mean_y) ** 2 for y in Y) r = numerator / (denom_x * denom_y) ** 0.5 print(r) # 0.9848 # Method 2 — statistics module (Python 3.10+) import statistics statistics.correlation(X, Y) # Method 3 — SciPy (also returns a p-value) from scipy.stats import pearsonr r, p_value = pearsonr(X, Y)
Worked example
Five students' hours studied (X) and exam scores (Y):
| Hours studied (X) | 2 | 4 | 6 | 8 | 10 |
|---|---|---|---|---|---|
| Exam score (Y) | 65 | 70 | 75 | 85 | 95 |
- 1Find the means.
x̄ = 6, ȳ = 78 - 2Compute the sums needed for the formula.
Σ(xᵢ−x̄)(yᵢ−ȳ) = 150, Σ(xᵢ−x̄)² = 40, Σ(yᵢ−ȳ)² = 580 - 3Divide by the square root of the product.
r = 150 / √(40 × 580) = 150 / 152.32 = 0.9848
r = 0.9848, an r² of 0.9698, and a two-tailed p-value of 0.0022 — a very strong, statistically significant positive correlation between hours studied and exam score in this small sample.
Frequently asked questions
What does a correlation coefficient of 0 mean?
A Pearson correlation of 0 means there's no linear relationship between the two variables. It doesn't rule out a strong non-linear relationship, since Pearson's r only measures linear association.
Does correlation imply causation?
No. A strong correlation only shows that two variables tend to move together; it doesn't show that one causes the other. The relationship could be causal, reversed, driven by a third variable, or simply coincidental.
What's the difference between correlation and covariance?
Covariance measures the direction of a linear relationship but is expressed in the product of the two variables' units, which makes its size hard to interpret. Correlation is covariance rescaled to always fall between -1 and 1, which makes it comparable across different variables and units.
What does the p-value in a correlation test tell you?
It tests the null hypothesis that the true population correlation is zero. A small p-value suggests the observed correlation is unlikely to have arisen purely by chance if there were really no linear relationship — though with a small sample, even a fairly large r can fail to reach significance.
How is correlation strength usually described?
There's no single agreed standard, but a common rough guideline treats |r| below 0.3 as weak, 0.3 to 0.7 as moderate, and above 0.7 as strong. These bands vary by field, so they should be treated as a general guide rather than a fixed rule.