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 sent to a server.
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.
- 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.
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.
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.
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
- Treating correlation as causation. Ice-cream sales and sunburn cases rise together because both follow hot weather, not because one causes the other.
- Forgetting that r only measures straight-line association. Points on a symmetric U-shaped curve can give r = 0. Always look at the scatter plot.
- Ignoring outliers. 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.
- Trusting a tiny sample. With a handful of pairs, a large r easily arises by chance. This page does not calculate a p-value or a confidence interval for r.
- Reading strength labels as fixed rules. The labels in the result, from very weak below 0.2 to very strong from 0.8, follow one common rule of thumb. 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.
Is my data uploaded anywhere?
No. All calculations run in your browser. Your entries are kept only in this browser's local storage, so they are still there when you come back, and nothing is sent to a server.
Related tools
- Histogram Maker — see how the values of a single variable are distributed.
- Confidence Interval Calculator — put a margin of error around an estimate.
- Sample Size Calculator — work out how many observations a study needs.
- CSV to JSON Converter — turn spreadsheet exports into JSON.
- Galton Board — watch a bell-shaped distribution build up from random bounces.