Pearson Correlation Coefficient Calculator
The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.
This calculator computes the Pearson correlation coefficient (r) from paired data you enter. You provide two lists of numbers (X and Y), and it returns r, the p-value for a two-tailed test, and the sample size. The result tells you the strength and direction of the linear relationship between the two variables.
Formula
The Pearson correlation coefficient is defined as:
r = Σ((xi – xÌ„)(yi – ȳ)) / √(Σ(xi – xÌ„)² · Σ(yi – ȳ)²)
where:
- xi and yi are the individual sample points
- x̄ is the mean of the X values
- ȳ is the mean of the Y values
- Σ denotes summation over all observations
The numerator is the covariance of X and Y, and the denominator is the product of their standard deviations. This normalizes the result to a range from -1 to +1.
For the p-value, the calculator uses the t-distribution with n-2 degrees of freedom. The test statistic is t = r·√((n-2)/(1-r²)). The p-value is the probability of observing a correlation as extreme as the one computed, assuming the true correlation is zero.
Worked Example
Using the default data: X = [1, 2, 3, 4, 5] and Y = [2, 4, 5, 4, 5].
- Compute the sums: Σx = 15, Σy = 20, Σxy = 2+8+15+16+25 = 66, Σx² = 1+4+9+16+25 = 55, Σy² = 4+16+25+16+25 = 86.
- Plug into the formula: numerator = 5·66 – 15·20 = 330 – 300 = 30.
- Denominator: √(5·55 – 15²) · √(5·86 – 20²) = √(275-225) · √(430-400) = √50 · √30 ≈ 7.0711 · 5.4772 ≈ 38.7298.
- r = 30 / 38.7298 ≈ 0.7746.
- For the p-value: t = 0.7746·√(3/(1-0.5999)) ≈ 0.7746·√(7.501) ≈ 0.7746·2.7388 ≈ 2.121. Using the t-distribution with 3 degrees of freedom, the two-tailed p-value is approximately 0.124.
So r ≈ 0.7746, p ≈ 0.124, n = 5.
When to Use Pearson’s r
Use Pearson’s correlation when you want to measure the strength of a linear relationship between two continuous variables that are roughly normally distributed. It is widely used in psychology, education, medicine, and economics. For example, you might examine the relationship between study hours and exam scores, or between height and weight.
The coefficient is meaningful only when the relationship is approximately linear. If the data shows a clear curve (e.g., a U-shape), Pearson’s r will be close to zero even though a strong nonlinear relationship exists. Always plot your data first.
How to Read the Result
- r = +1: perfect positive linear relationship
- r = -1: perfect negative linear relationship
- r = 0: no linear relationship
- |r| > 0.8: strong correlation
- |r| between 0.5 and 0.8: moderate correlation
- |r| between 0.2 and 0.5: weak correlation
- |r| < 0.2: very weak correlation
The sign indicates direction: positive means as one variable increases, the other tends to increase; negative means the opposite. The p-value tells you whether the observed correlation is statistically significant. A common threshold is p < 0.05, but that is an arbitrary convention.
Common Mistakes and Pitfalls
- Not checking for outliers: A single outlier can drastically inflate or deflate r. For example, if most points cluster near (0,0) and one point is at (100,100), r will be high even if the rest show no relationship.
- Assuming causation: Correlation does not imply causation. Two variables can be correlated because of a third factor or pure chance.
- Using non-linear data: If the relationship is quadratic, Pearson’s r will underestimate the association.
- Mixing units: The coefficient is unitless, but if you enter values with different scales (e.g., one in meters, one in feet), the result is still correct mathematically, but the interpretation may be misleading if you forget the actual units.
- Ignoring the p-value: A high r with a large p-value (e.g., r=0.9 with n=3) is not reliable.
Limitations and Assumptions
Pearson’s r assumes:
- Both variables are continuous and approximately normally distributed.
- The relationship is linear.
- There are no significant outliers.
- The data is homoscedastic (the spread of Y is roughly constant across values of X).
If these assumptions are violated, consider Spearman’s rank correlation, which is based on ranks and is more robust to outliers and non-linear monotonic relationships.
Alternatives to Pearson’s r
- Spearman’s rho: Uses ranks, works for monotonic relationships, robust to outliers.
- Kendall’s tau: Another rank-based measure, often used with small samples or many ties.
- Point-biserial correlation: When one variable is dichotomous (e.g., pass/fail) and the other is continuous.
- Phi coefficient: For two binary variables.
- Partial correlation: Measures the relationship between two variables while controlling for a third.
Frequently Asked Questions
What is the difference between Pearson and Spearman correlation?
Pearson measures linear relationships on raw data; Spearman measures monotonic relationships on ranked data. Spearman is less sensitive to outliers and does not require normality.
Can Pearson’s r be greater than 1 or less than -1?
No. The formula normalizes the covariance by the product of standard deviations, so the result is always between -1 and 1. If you get a value outside this range, you likely made an arithmetic error.
What does a correlation of 0 mean?
It means there is no linear relationship between the variables. There could still be a nonlinear relationship, so always visualize the data.
How do I know if my correlation is significant?
Check the p-value. If it is below your chosen significance level (commonly 0.05), you can reject the null hypothesis that the true correlation is zero. The p-value depends on the sample size.
Can I use Pearson’s r for ordinal data?
It is not ideal. Ordinal data (e.g., Likert scales) is better analyzed with Spearman’s rho, which uses ranks and does not assume equal intervals.
What is the effect of sample size on p-value?
Larger samples make the p-value smaller for the same r value. With n=100, r=0.2 might be significant, but with n=10, r=0.5 might not be. Always report both r and p.
Related
Formula used
in x | X values | - | 1, 2, 3, 4, 5 | 0 in y | Y values | - | 2, 4, 5, 4, 5 | 0 out r | Pearson r | - | (count(x)*sum(x*y) - sum(x)*sum(y)) / (sqrt(count(x)*sum(x^2) - sum(x)^2) * sqrt(count(x)*sum(y^2) - sum(y)^2)) | 4 out p | p-value (two-tailed) | - | 0 | 4 out n | Sample size | - | count(x) | 0
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.