Pearson Correlation Coefficient Calculator
Calculate Pearson's r between two data sets with the coefficient, strength interpretation, and a plain-language summary.
Pearson Correlation Coefficient Calculator
Calculator
Adjust values & calculateEnter your values below. Every result is computed in your browser โ no data is sent to any server.
Formula: r = [n(Sum XY) - (Sum X)(Sum Y)] / sqrt{[n(Sum X^2) - (Sum X)^2][n(Sum Y^2) - (Sum Y)^2]}
Worked example โ r = 0.972 (Very Strong Positive), R-squared = 0.945 (94.5% variance explained)
Formula
r = [n(Sum XY) - (Sum X)(Sum Y)] / sqrt{[n(Sum X^2) - (Sum X)^2][n(Sum Y^2) - (Sum Y)^2]}Where r is the Pearson correlation coefficient, n is the number of data pairs, Sum XY is the sum of products of paired values, Sum X and Sum Y are the sums of X and Y values respectively, and Sum X^2 and Sum Y^2 are sums of squared values. The t-statistic for significance testing is t = r * sqrt((n-2)/(1-r^2)) with n-2 degrees of freedom.
Worked Examples
Example 1: Gene Expression Correlation
Problem:A researcher measures expression levels of Gene A (X: 2.1, 3.5, 4.2, 5.8, 6.1) and Gene B (Y: 1.8, 3.2, 4.5, 5.1, 6.3) in 5 tissue samples. Calculate the Pearson correlation.
Solution:n=5, Mean X=4.34, Mean Y=4.18 Sum of (Xi-MeanX)(Yi-MeanY) = 11.184 Sum of (Xi-MeanX)^2 = 10.972 Sum of (Yi-MeanY)^2 = 12.068 r = 11.184 / sqrt(10.972 * 12.068) = 11.184 / 11.507 = 0.9719 R-squared = 0.945, t = 0.9719 x sqrt(3 / (1 - 0.945)) = 7.16, df = 3, p = 0.006
Result:r = 0.972 (Very Strong Positive), R-squared = 0.945 (94.5% variance explained)
Example 2: Drug Dosage vs Response Time
Problem:Test whether drug dosage (mg: 10, 20, 30, 40, 50, 60) correlates with response time (min: 45, 38, 32, 25, 20, 15) in 6 patients.
Solution:n=6, Mean X=35, Mean Y=29.17 Sum of (Xi-MeanX)(Yi-MeanY) = -1055 Sum of (Xi-MeanX)^2 = 1750 Sum of (Yi-MeanY)^2 = 638.83 r = -1055 / sqrt(1750 * 638.83) = -1055 / 1057.3 = -0.9978 R-squared = 0.996, t = -30.0, df = 4, p < 0.001
Result:r = -0.998 (Very Strong Negative), higher dosage strongly associated with lower response time
Frequently Asked Questions
What is Pearson correlation and when should I use it?
Pearson correlation coefficient (r) measures the linear relationship between two continuous variables. It ranges from -1 to +1, where +1 indicates a perfect positive linear relationship, -1 indicates a perfect negative linear relationship, and 0 means no linear relationship. You should use Pearson correlation when both variables are continuous, approximately normally distributed, and you expect a linear (not curved) relationship. It is the most commonly used correlation measure in biological and biostatistical research for measuring associations between variables like height and weight, dosage and response, or gene expression levels.
What is the difference between r and R-squared?
The correlation coefficient (r) measures the strength and direction of a linear relationship, while R-squared (r squared, or the coefficient of determination) tells you the proportion of variance in one variable explained by the other. For example, if r = 0.8, then R-squared = 0.64, meaning 64% of the variability in Y is explained by its linear relationship with X. R-squared is always between 0 and 1 and is always positive, so it does not indicate direction. In biostatistics, R-squared is especially useful for understanding how well a predictor variable accounts for variation in an outcome variable.
How do I interpret the p-value for Pearson correlation?
The p-value tests the null hypothesis that the true population correlation is zero (no linear relationship). If p < 0.05 (the conventional significance threshold), you reject the null hypothesis and conclude the correlation is statistically significant. However, statistical significance does not imply practical importance. With very large sample sizes, even tiny correlations (r = 0.05) can be significant. Always consider the magnitude of r alongside the p-value. In biological research, it is common to report both r and p together, and to use scatterplots to visually confirm the relationship.
What sample size do I need for meaningful Pearson correlation?
A minimum of 3 data pairs is required mathematically, but meaningful results typically require at least 20-30 pairs. For detecting moderate correlations (r around 0.5) with 80% power at alpha = 0.05, you need approximately 30 pairs. For weaker correlations (r around 0.3), you need roughly 85 pairs. In biological studies, sample sizes under 10 should be interpreted very cautiously as the correlation estimate can be highly unstable. Power analysis can help determine the exact sample size needed for your expected effect size.
What are the assumptions of Pearson correlation?
Pearson correlation requires several assumptions: (1) Both variables must be continuous and measured on interval or ratio scales. (2) The relationship between the variables should be approximately linear. (3) Both variables should be roughly normally distributed, especially for small samples. (4) Observations should be independent of each other. (5) There should be no significant outliers, as Pearson r is sensitive to extreme values. If these assumptions are violated, consider using Spearman rank correlation instead, which is more robust to non-normality and outliers.
What is the difference between Pearson and Spearman correlation?
Pearson measures the strength of a straight-line relationship between two quantitative variables and uses the raw values, so it is sensitive to outliers and to curvature. Spearman replaces each value with its rank and then applies the same formula, which measures monotonic association instead: whether Y consistently increases as X increases, regardless of the shape of the curve. Spearman is the better choice for ordinal data, for skewed distributions, and when a single extreme point would otherwise dominate the coefficient.
How does the t-statistic test whether r is significantly different from zero?
Under the null hypothesis of no linear association, the sampling distribution of r converts to a t-statistic using t = r x sqrt((n - 2) / (1 - r^2)) with n - 2 degrees of freedom. With r = 0.6 and n = 20, that gives t = 0.6 x sqrt(18 / 0.64) = 0.6 x 5.303 = 3.18 on 18 degrees of freedom. Larger samples make the same r more significant, which is why a p-value alone says nothing about the strength of the relationship, only about the evidence against zero.
Why can two datasets share the same r and still look completely different?
The correlation coefficient compresses a whole scatterplot into one number and cannot distinguish the patterns behind it. Anscombe's quartet is the classic demonstration: four small datasets with essentially identical means, variances, regression lines and correlation, yet one is a clean linear trend, one is a curve, one is a perfect line with a single displaced point, and one is a vertical cluster plus one distant point. The lesson is to plot the data before quoting r, because a curve or a leverage point can manufacture or destroy an apparent correlation.
How do outliers and a restricted range distort the coefficient?
Because r is built from products of deviations from the mean, a single point far from the cloud contributes an enormous product and can drag the coefficient toward or away from zero out of all proportion to the rest of the sample. The opposite problem is range restriction: if you sample only a narrow slice of X, the between-subject variation that r divides by shrinks while the scatter around the line does not, so r is attenuated even though the underlying relationship is unchanged. Both are reasons to inspect the scatterplot and report the sampled range.
Why does a strong correlation not establish that one variable causes the other?
Correlation quantifies co-variation, and co-variation has several possible sources: X may drive Y, Y may drive X, both may respond to a third confounding variable, or the pattern may arise from selection in how the sample was assembled. In observational biological data, confounding by body size, age or population structure is extremely common. Establishing causation needs an intervention, a randomised design, or a study that measures and adjusts for the plausible confounders; the coefficient itself cannot distinguish between these explanations.
References
Background & Theory
History
Reviewed for accuracy by Daniel Agrici, Founder & Lead Developer ยท Editorial policy
Related Calculators
๐งฎRegression Coefficient Calculator
Calculate regression coefficient with inputs, formulas, and instant results.
๐งฎSpearman Correlation Calculator
Calculate spearman correlation with inputs, formulas, and instant results.
๐งฎAlpaca Gestation Calculator
Calculate alpaca gestation with inputs, formulas, and instant results.
๐งฎCat Pregnancy Calculator โ Due Date & Gestation
Calculate cat pregnancy with inputs, formulas, and instant results.
๐งฎCow Gestation Calculator
Calculate cow gestation with inputs, formulas, and instant results.
๐งฎDog Pregnancy Calculator: Due Date by Breed
Calculate dog pregnancy with inputs, formulas, and instant results.
๐งฎGoat Gestation Calculator
Calculate goat gestation with inputs, formulas, and instant results.
๐งฎGuinea Pig Pregnancy Calculator โ Due Date
Calculate guinea pig pregnancy with inputs, formulas, and instant results.