Percentages and Math

Linear Regression and Correlation Calculator

Paste your x and y pairs to fit a straight line and see how well it describes the data.

Your numbers

Separate x and y with a comma, space or tab. Up to 2,000 pairs.

Stay inside the range of your data. Predictions outside it are extrapolation.

Result

Best fit line

y = 2.02x - 0.02

r = 0.999105, R squared = 0.998211

Slope
2.02
Intercept
-0.02
Correlation (r)
0.999105
R squared
0.998211
Number of pairs
6
Standard error of the estimate
0.178885
Standard error of the slope
0.042762
p value for the slope
0.000001

Fitted values and residuals

xyFitted yResidual
12.120.1
23.94.02-0.12
36.26.040.16
47.88.06-0.26
510.110.080.02
612.212.10.1
How this was calculated
  1. Mean of x = 3.5, mean of y = 7.05.
  2. Slope = sum of (x - mean x)(y - mean y) / sum of (x - mean x) squared. Intercept = mean y - slope x mean x.
  3. r = sum of (x - mean x)(y - mean y) / square root of (Sxx x Syy). R squared is r squared.
  4. Standard error of the estimate = square root of (sum of squared residuals / (n - 2)) = 0.178885. The slope t statistic is slope / its standard error with n - 2 degrees of freedom.
  • Correlation does not show cause. The p value assumes the errors are roughly normal and independent, and a fitted line only describes the range of your data.
  • With so few points the slope and p value are very uncertain.

Calculated using SumPanda.com · https://sumpanda.com/linear-regression-calculator/

Results are estimates for general information. Verify important figures before relying on them.

Next step

How to use the linear regression and correlation calculator

  1. Paste your data into the box with one x, y pair per line. Separate the two numbers with a comma, space or tab.
  2. Optionally enter an x value to predict the matching y.
  3. Read the slope, intercept, correlation, R squared and the p value for the slope, along with the equation of the best fit line.
  4. Check the table of fitted values and residuals, and look for points that sit far from the line before you trust the result.

Formula

Slope = sum of (x - mean x)(y - mean y) / sum of (x - mean x)^2

Intercept = mean y - slope x mean x

r = sum of (x - mean x)(y - mean y) / square root of (Sxx x Syy)

R squared = r^2

Standard error of the estimate = square root of (sum of squared residuals / (n - 2))

t = slope / standard error of the slope, with n - 2 degrees of freedom

The p value is two sided and comes from the exact Student t distribution.

Worked example

Take the pairs (1, 2.1), (2, 3.9), (3, 6.2), (4, 7.8), (5, 10.1) and (6, 12.2). The best fit line is y = 2.02x - 0.02.

The correlation is 0.999105 and R squared is 0.998211, so the line explains almost all of the variation. The standard error of the slope is 0.042762, the t statistic is 47.24 and the p value is about 0.000001. A prediction at x = 7 is 14.12.

Reading slope and intercept

The slope is the average change in y for each one unit increase in x. The intercept is the fitted y when x is zero, which may not mean anything in practice if zero is outside your data. R squared is the share of the variation in y that the line accounts for, from 0 to 1.

Correlation is not causation

A strong correlation shows two things move together, not that one causes the other. Outliers can pull the line and inflate or hide a relationship, so inspect the residuals. A p value tests whether the slope differs from zero, assuming roughly normal, independent errors. For summary figures on a single column, use the descriptive statistics calculator.

Predicting beyond your data

A line fitted to x values between 1 and 6 says little about x = 60. The tool warns when you predict outside the range of your data. For planning the size of a study, see the sample size calculator, and for the spread of a single set of values see the standard deviation calculator.

Assumptions and limits

  • The relationship is roughly a straight line, and each pair is an independent observation.
  • For the p value, the errors around the line are roughly normal with similar spread.
  • At least three pairs are needed, up to 2,000. Every x cannot be the same.
  • If y never changes, the correlation and R squared are not defined and the page says so.

Formulas reviewed October 10, 2026. See the calculation methodology for how SumPanda rounds, tests and sources its formulas.

Frequently asked questions

How do I find the line of best fit?

Compute the slope as the covariance of x and y divided by the variance of x, then the intercept as mean y minus slope times mean x. This tool does that for you from pasted pairs.

What is a good R squared?

There is no universal cutoff. In tightly controlled physical measurements 0.99 is common, while in social data 0.3 can be meaningful. Judge it against what is normal for your field.

What does a negative correlation mean?

That y tends to fall as x rises. The slope is also negative. The size of r, from 0 to 1 in absolute value, shows how tight the relationship is.

Why does the tool need three points?

With two points a line fits perfectly and there is no information on how well it describes the data. Three or more points leave degrees of freedom to estimate the error.