Correlation & Covariance Calculator
Enter paired data to get the Pearson correlation coefficient r, r², the sample and population covariance, the least-squares regression line and Spearman's rank correlation, with a scatter plot and a working table that shows every step.
Your data
Separate the values with spaces, commas, semicolons or new lines. The first X belongs to the first Y, the second X to the second Y, and so on.
Hours studied, Exam score,
labels the chart and the table.
Use a decimal point (12.5). A comma always separates two values and
is never read as a decimal comma: 1,5 means the two numbers 1 and 5.
Results
Scatter plot
Working table
Formulas with the totals substituted
Ranks for Spearman's ρ
Calculations run locally in your browser — nothing you enter is uploaded.
Runs on your device. Nothing you type or record is uploaded. Keeps working without a connection while the page is open. Works with touch. Saves your data, variable names and decimal places on this device.
Added · Updated : optional 95% confidence interval and p-value for r
How to use the correlation and covariance calculator
- Choose the input format. “Two lists” has one box for X and one for Y. “Two columns” takes one X, Y pair per line, so two neighbouring spreadsheet columns can be pasted straight in.
- Enter the data. Type whole numbers or decimals with a decimal point, such as 3.75 or −0.2. A comma always separates two values; it is never read as a decimal comma.
- Name the variables if you like. In list mode use the two name boxes; in column mode put the two names on the first line. The names label the chart and the table.
- Choose the decimal places (2 to 8). The results update as you type.
- Tick “Show the 95% confidence interval and p-value” under the results if you want to know how precisely the data pin down r and whether it could have arisen by chance. It needs at least 4 pairs.
- Read the results. Check the scatter plot for outliers or a curved pattern, then copy the results or the tab-separated working table.
How it works
The calculator finds the two means, x̄ and ȳ, and subtracts them
from every value. These deviations give three totals, which are the last row of the working
table:
Sxx = Σ(x − x̄)²measures how much X varies;Syy = Σ(y − ȳ)²measures how much Y varies;Sxy = Σ(x − x̄)(y − ȳ)measures how much they vary together.
With n pairs, every result follows from these three totals:
- sample covariance
Sxy / (n − 1)and population covarianceSxy / n; - Pearson correlation
r = Sxy / √(Sxx · Syy), always between −1 and +1; - regression slope
b = Sxy / Sxxand intercepta = ȳ − b · x̄, which give the least-squares liney = a + b · x; - sample standard deviations
√(Sxx / (n − 1))and√(Syy / (n − 1)).
r², the coefficient of determination, is the share of the variation in Y that
the regression line accounts for. Spearman's rank correlation ρ replaces every
value by its rank (1 for the smallest, with tied values sharing the average of their ranks)
and applies the Pearson formula to the ranks.
Working with deviations from the means, rather than the shortcut built on
Σx² and Σxy, keeps the result accurate when the values are large
and close together. Numbers are rounded only for display; halves round away from zero.
Confidence interval and p-value
Both results assume that the pairs are independent and come from a population in which X and Y follow a bivariate normal distribution. They are shown from 4 pairs on, and not when |r| = 1.
- The 95% confidence interval uses Fisher's z transformation:
z = artanh(r)is roughly normal with standard error1 / √(n − 3), so the interval istanh(z ± 1.959964 / √(n − 3)). It is not centred on r and always stays between −1 and +1. The approximation improves as n grows. - The p-value tests whether the true correlation is 0:
t = r · √(n − 2) / √(1 − r²)follows Student's t distribution with n − 2 degrees of freedom, and p is the two-sided probability of a |t| at least this large.
Examples
Example 1: study time and exam score (the preloaded data). X = 2, 4, 6,
8, 10, 12 hours and Y = 65, 70, 74, 81, 85, 95 points give x̄ = 7, ȳ = 78.3333,
Sxx = 70, Syy = 595.3333 and Sxy = 202.
r = 202 / √(70 × 595.3333) = 0.9895, so r² = 0.9791. The sample covariance is
202 / 5 = 40.4, the population covariance is 202 / 6 = 33.6667, and the regression line is
y = 58.1333 + 2.8857·x: each extra hour goes with about 2.9 more points.
Spearman's ρ is 1, because the score rises with every extra hour. With the confidence
interval option ticked, the 95% interval for r is 0.9036 to 0.9989 and t = 13.7021 with 4
degrees of freedom, so p = 0.0002.
Example 2: tied values. X = 1, 2, 3, 4, 5 and Y = 2, 4, 5, 4, 5. Here
Sxx = 10, Syy = 6 and Sxy = 6, so r = 6 / √(10 × 6) = 0.7746 and r² = 0.6. The
sample covariance is 1.5, the population covariance is 1.2 and the line is
y = 2.2 + 0.6·x. The two 4s share ranks 2 and 3 and the two 5s share ranks 4
and 5, so the ranks of Y are 1, 2.5, 4.5, 2.5, 4.5 and Spearman's ρ is 0.7379. The 95%
interval for r runs from −0.3401 to 0.9842 and p = 0.124 (t = 2.1213, 3 degrees of freedom):
about one sample in eight would give an r this large if there were no correlation at
all.
Example 3: a perfect negative relationship. X = 1, 2, 3 and Y = 6, 4, 2
lie exactly on a falling line: r = −1, r² = 1, sample covariance −2, population covariance
−1.3333 and line y = 8 − 2·x.
Example 4: no variation. X = 1, 2, 3, 4 and Y = 5, 5, 5, 5. Y never changes, so Syy = 0 and Sxy = 0. Both covariances are 0, but r would be 0 ÷ 0, so it is reported as undefined, and so are r² and Spearman's ρ. The fitted line is the horizontal line y = 5 with slope 0.
Correlation or covariance: which one do you need?
Both describe whether two variables move together, and they always have the same sign. Covariance keeps the units of the data (hours times points in Example 1), so its size depends on the scale: measure study time in minutes instead of hours and the covariance becomes 60 times larger, while r stays 0.9895. Use r to compare the strength of relationships, and covariance where a formula asks for it, such as the variance of a sum or the risk of a portfolio.
Use the sample covariance (divide by n − 1) when your data are a sample from a larger group, which is the usual case, and the population covariance (divide by n) when they cover the whole group you want to describe. The choice does not affect r, because the divisor cancels.
Common mistakes when reading a correlation
- Correlation is not causation. Ice-cream sales and sunburn cases rise together because both follow hot weather, not because one causes the other.
- r measures only straight-line association: points on a symmetric U-shaped curve can give r = 0. Always look at the scatter plot.
- One extreme point can create a strong r or hide one. Spearman's ρ uses ranks, so it reacts less; a large gap between r and ρ is a reason to inspect the data.
- With a handful of pairs, a large r easily arises by chance. In Example 2, r = 0.7746 from 5 pairs has p = 0.124 and a 95% interval that includes 0, so tick the interval option before you rely on a small sample.
- The strength labels in the result, from very weak below 0.2 to very strong from 0.8, follow one common rule of thumb, not a fixed rule. Other fields draw the lines elsewhere.
Frequently asked questions
What is a good correlation coefficient?
There is no universal threshold. In a controlled physics experiment an r of 0.9 may be disappointing, while in the social sciences 0.3 can be a meaningful result. Judge r against what is typical for your subject.
Why does the calculator say r is undefined?
All X values, or all Y values, are identical. A variable that does not vary has a standard deviation of 0, and the formula for r would divide by it. The covariance is still shown, and it is 0.
What is the difference between Pearson and Spearman correlation?
Pearson's r measures how closely the points follow a straight line. Spearman's ρ works on ranks, so it measures whether Y consistently rises or falls as X rises, whatever the shape of the curve. For ordinal data, such as rankings or survey scales, Spearman is usually the better choice.
Does r² tell me the percentage explained?
For a straight-line fit with one predictor, yes: an r² of 0.9791 means the line accounts for about 98% of the variation in Y. It does not mean that 98% of the points lie on the line, or that X causes that share of Y.
Sources
- Wikipedia contributors (accessed 25 October 2026). Pearson correlation coefficient. Wikipedia. The formula for r, the t-test with n − 2 degrees of freedom and its bivariate normal assumption.
- Wikipedia contributors (accessed 25 October 2026). Fisher transformation. Wikipedia. z = artanh(r), its standard error 1 / √(N − 3) and its origin in R. A. Fisher's 1915 paper in Biometrika.
- Wikipedia contributors (accessed 25 October 2026). Spearman's rank correlation coefficient. Wikipedia. Pearson's r of the ranks, average ranks for ties, and why the 6·Σd² shortcut is wrong when there are ties.