How to use the correlation coefficient calculator
- Paste your x values in the first box and the matching y values in the second, in the same order.
- Choose Pearson for a straight-line relationship between measured values, or Spearman for ranks, ratings or data with outliers.
- Pick the alternative hypothesis and significance level for the test (two-tailed at α = 0.05 is the usual choice).
- Optionally name the variables so the chart and explanation use them, then click Calculate correlation.
- Read r, r², the p-value and the plain-English summary, and check the scatter plot for curves or outliers.
Correlation coefficient formula
Pearson's correlation coefficient compares how x and y vary together with how much each varies on its own:
r = Σ(x − x)(y − y)Σ(x − x)2 · Σ(y − y)2 = SxySxx Syy
To test whether the correlation differs from zero, convert r to a t statistic with n − 2 degrees of freedom:
t = r n − 21 − r2
- r
- The sample correlation coefficient, between −1 and 1
- x, y
- The means of x and y
- Sxy
- The sum of the products of the deviations, which is positive when x and y tend to be above (or below) their means together
- Sxx, Syy
- The sums of squared deviations of x and of y
- n
- The number of (x, y) pairs
- ρ
- The population correlation, which the test compares with 0. Spearman's rho is Pearson's r computed on the ranks of x and y
Worked example
Five students report hours of sleep (x) and a quiz score out of 5 (y): (1, 2), (2, 4), (3, 5), (4, 4), (5, 5). How strongly are they correlated?
-
Find the means
x = 155 = 3, y = 205 = 4
-
Sum the products and squares of the deviations
Sxy = (−2)(−2) + (−1)(0) + 0(1) + 1(0) + 2(1) = 6Sxx = 4 + 1 + 0 + 1 + 4 = 10, Syy = 4 + 0 + 1 + 0 + 1 = 6
-
Divide
r = 610 × 6 = 0.7746
-
Test it: t with 5 − 2 = 3 degrees of freedom
t = 0.7746 31 − 0.6 = 2.1213, p = 0.1240
What it means: r = 0.77 is a strong positive correlation, and r² = 0.60, so a straight line on sleep explains 60% of the variation in scores. But with only five students, the p-value of 0.124 is above 0.05, so the sample is too small to rule out that the pattern happened by chance.
How to interpret a correlation coefficient
- The sign gives the direction. Positive r means y tends to rise as x rises; negative r means y tends to fall.
- The size gives the strength of the linear relationship: 0 means no linear relationship, ±1 means the points lie exactly on a line.
- r² is the share of the variation in y explained by a straight line on x.
- The p-value tells you whether the correlation could plausibly be zero in the population. With large samples, even weak correlations become significant, so judge the size too.
- Look at the plot. A curved relationship can have r near 0, and one outlier can create or hide a strong correlation.
To fit and draw the trend line itself, use the scatter plot maker, which gives the least-squares equation alongside the chart.