Correlation & Linear Regression Calculator
Paste paired x, y data to instantly calculate the Pearson correlation coefficient (r), the least-squares regression line (y = mx + c), and R² — with a scatter plot and full step-by-step working.
One (x, y) pair per line, separated by a comma, space, or tab. Needs at least 2 pairs.
5 pairs detected
Pearson Correlation Coefficient (r)
0.7746
Positive — a strong positive linear relationship
Regression Equation
y = 0.6x + 2.2
R² (Coefficient of Determination)
0.6
Slope (m)
0.6
Intercept (c)
2.2
Mean of x
3
Mean of y
4
Data Points (n)
5
R² as Percentage
60%
Scatter Plot with Regression Line
The red line is the best-fit regression line y = 0.6x + 2.2, found using the least-squares method. It minimizes the total squared vertical distance between the line and every data point.
Step-by-Step Solution
Here's exactly how this answer was calculated, one step at a time.
- 1
List the paired data points
(1, 2), (2, 4), (3, 5), (4, 4), (5, 5)
There are n = 5 (x, y) pairs in this data set.
- 2
Calculate x·y, x², and y² for each pair
xy: 1×2=2, 2×4=8, 3×5=15, 4×4=16, 5×5=25. x²: 1²=1, 2²=4, 3²=9, 4²=16, 5²=25. y²: 2²=4, 4²=16, 5²=25, 4²=16, 5²=25.
- 3
Add up the five sums needed for the formulas
Σx = 15, Σy = 20, Σxy = 66, Σx² = 55, Σy² = 86
These five running totals are all that's needed to compute both the correlation coefficient and the regression line — no need to work with the raw pairs again after this.
- 4
Calculate the Pearson correlation coefficient (r)
r = (nΣxy − ΣxΣy) / √[(nΣx² − (Σx)²)(nΣy² − (Σy)²)] = (330 − 300) / √[50 × 30] = 30 / 38.73 = 0.7746
This measures the strength and direction of the linear relationship between x and y, on a scale from −1 to +1.
- 5
Interpret the correlation coefficient
r = 0.7746
A value this close to +1 indicates a strong positive linear relationship between x and y.
- 6
Calculate the regression slope (m)
m = (nΣxy − ΣxΣy) / (nΣx² − (Σx)²) = 30 / 50 = 0.6
The slope tells you how much y changes, on average, for every one-unit increase in x.
- 7
Calculate the regression intercept (c)
c = ȳ − m·x̄ = 4 − 0.6 × 3 = 2.2
The intercept is the predicted value of y when x = 0 — the point where the regression line crosses the y-axis.
- 8
Write the regression line equation
y = 0.6x + 2.2
This equation lets you predict y for any new value of x, using the slope and intercept just calculated.
- 9
Calculate R² (coefficient of determination)
R² = r² = (0.7746)² = 0.6
R² = 60% means that about 60% of the variation in y is explained by its linear relationship with x — the rest is due to other factors or randomness.
✓ Final Answer: r = 0.7746, y = 0.6x + 2.2, R² = 0.6
Correlation & Linear Regression Calculator
This free correlation and linear regression calculator is built for business, economics, and data analytics use cases where you need to understand the relationship between two numeric variables. Paste in your paired x, y data — such as advertising spend and sales, price and demand, years of experience and salary, or study hours and exam scores — and instantly get the Pearson correlation coefficient (r), the least-squares regression line equation (y = mx + c), and the R² value, all calculated together with a live scatter plot and full step-by-step working shown below.
Correlation and regression are two of the most widely used statistical tools in business analytics, econometrics, marketing research, finance, and the social sciences. Correlation tells you whether and how strongly two variables move together, while regression goes a step further and gives you an actual equation you can use to predict one variable from the other. This calculator handles both at once, since they're built from the exact same underlying sums.
Pearson Correlation Coefficient (r) Formula
The Pearson correlation coefficient measures the strength and direction of the linear relationship between two variables, x and y. It always falls between −1 and +1. This calculator uses the raw-score (computational) formula, which avoids having to calculate deviations from the mean for every point:
r = (nΣxy − ΣxΣy) / √[(nΣx² − (Σx)²)(nΣy² − (Σy)²)]
Here, n is the number of paired observations, Σxy is the sum of each x multiplied by its paired y, Σx and Σy are the simple sums of each variable, and Σx² and Σy² are the sums of each variable squared. A result of r = +1 means a perfect positive linear relationship (as x increases, y increases proportionally), r = −1 means a perfect negative linear relationship (as x increases, y decreases proportionally), and r = 0 means no linear relationship at all. Values in between are interpreted by their magnitude: generally, |r| below 0.3 is considered weak, 0.3–0.7 moderate to moderately strong, and above 0.7 a strong linear relationship — though the right threshold can vary by field.
Linear Regression Formula (y = mx + c)
Simple linear regression fits a straight line through the data using the ordinary least squares (OLS) method — the method that minimizes the sum of the squared vertical distances between each observed y value and the line's predicted value. The resulting line has the equation y = mx + c, where m is the slope and c is the y-intercept:
Slope: m = (nΣxy − ΣxΣy) / (nΣx² − (Σx)²)
Intercept: c = ȳ − m·x̄, where x̄ and ȳ are the means of x and y
Once you have m and c, you can plug in any x value to predict the corresponding y value — this is the core idea behind using regression for forecasting in business and economics, such as predicting sales from ad spend, or costs from production volume.
What is R² (Coefficient of Determination)?
R², the coefficient of determination, is simply the square of the correlation coefficient: R² = r². It represents the proportion of the variation in y that can be explained by its linear relationship with x, expressed as a value between 0 and 1 (or 0% to 100%). An R² of 0.80, for example, means 80% of the variability in y is explained by x through the fitted line, while the remaining 20% is due to other factors, noise, or a relationship that isn't purely linear. In business and economics contexts, R² is often used to judge how reliable a regression model is before using it for forecasting or decision-making — a low R² suggests the linear model may not be capturing the real relationship well, even if the slope looks meaningful.
How to Use This Calculator
Enter your paired data with one (x, y) observation per line, separating the two numbers with a comma, space, or tab — for example, '3, 12' on one line and '5, 18' on the next. The calculator needs at least two pairs, though results are more meaningful with several. It instantly returns the Pearson correlation coefficient, the regression equation, R², the slope, the intercept, and the means of both variables, along with a scatter plot showing your data points and the fitted regression line.
- Use the Pearson correlation coefficient (r) when you only want to know how strongly two variables are related, and in which direction.
- Use the linear regression equation (y = mx + c) when you want to predict or forecast one variable based on the other.
- Use R² when you want to know how much of the variation in y is actually explained by the linear model, before trusting its predictions.
- Remember that correlation and regression only capture linear relationships — a strong non-linear pattern can produce a low r even when x and y are clearly related.
Worked Example
Consider five paired observations: (1, 2), (2, 4), (3, 5), (4, 4), (5, 5). Here, n = 5, Σx = 15, Σy = 20, Σxy = 66, Σx² = 55, and Σy² = 86.
Correlation: r = (5×66 − 15×20) / √[(5×55 − 15²)(5×86 − 20²)] = (330 − 300) / √[(275 − 225)(430 − 400)] = 30 / √(50 × 30) = 30 / √1500 ≈ 0.7746, indicating a moderately strong positive linear relationship.
Regression: slope m = (5×66 − 15×20) / (5×55 − 15²) = 30 / 50 = 0.6. Intercept c = ȳ − m·x̄ = 4 − 0.6×3 = 2.2. So the regression line is y = 0.6x + 2.2.
R² = r² = 0.7746² ≈ 0.6, meaning about 60% of the variation in y is explained by its linear relationship with x. Enter this same data set into the calculator above to see every one of these steps computed automatically.
Correlation vs Regression vs Causation
It's important to remember that correlation and regression describe association, not causation. A strong positive r or a high R² only tells you that two variables tend to move together in a predictable linear way — it doesn't prove that changes in x directly cause changes in y. In business and economics, this distinction matters: advertising spend and sales might correlate strongly, but a third factor (like seasonality or overall market growth) could be driving both. This calculator, like any correlation and regression tool, gives you the statistical relationship — interpreting whether that relationship is causal is a separate analytical step that depends on domain knowledge, experimental design, or more advanced techniques like controlled experiments or multiple regression.
Frequently Asked Questions
What is the difference between correlation and regression?
Correlation (r) measures how strongly two variables are linearly related and in which direction, without implying that one causes the other. Regression goes further and produces an actual equation (y = mx + c) that lets you predict one variable from the other, along with R², which tells you how much of the variation in y that equation actually explains.
What does a Pearson correlation coefficient of 0 mean?
An r of 0 means there is no linear relationship between the two variables — as one increases, the other doesn't consistently increase or decrease in a straight-line pattern. It's still possible for the variables to have a strong non-linear relationship even when r is close to 0.
Can R² be negative?
For simple linear regression fitted with least squares, R² (which equals r²) is always between 0 and 1, since it's a squared value. Negative R² values only appear in more advanced modeling contexts, such as when a model performs worse than simply predicting the mean.
How many data points do I need for a reliable correlation or regression?
Mathematically, you need at least two points to fit a line, but two or three points will always look like a perfect fit and aren't meaningful. In practice, most statisticians recommend at least 10–20 paired observations before treating a correlation coefficient or regression equation as a reliable summary of the relationship.
Why do we square r to get R²?
Squaring r removes its sign and converts it into a proportion of explained variance, which is easier to interpret directly as a percentage. An r of 0.8 and an r of −0.8 represent equally strong relationships (just in opposite directions), and both produce the same R² of 0.64, meaning 64% of the variance in y is explained either way.
Does a strong correlation mean x causes y?
No. Correlation and regression only capture statistical association, not causation. Two variables can be strongly correlated because one genuinely influences the other, because both are influenced by a third factor, or purely by coincidence in a limited data set — establishing causation requires additional evidence beyond the correlation coefficient itself.