CALCULATOR

Linear Regression Calculator

Paste paired x and y data to get the least-squares line, slope, intercept, correlation r, R-squared and a p-value, with a scatter plot.

About this linear regression calculator

Simple linear regression finds the straight line that best describes how a variable y changes with a variable x. Paste your paired data and this calculator returns the least-squares line y = a + bx, the slope and intercept, the correlation coefficient r, the coefficient of determination R², the standard error, and a p-value for the slope that tests whether the relationship is statistically different from zero. It also draws a scatter plot with the fitted line and predicts y for any x you enter.

The formulas

QuantityFormula
Slope (b)b = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)²
Intercept (a)a = ȳ − b x̄
Correlation (r)r = Sxy / √(Sxx Syy)
R²r², the share of the variation in y explained by x
Standard error of estimates = √(SSE / (n − 2))
t statistic for the slopet = b / SE(b), with n − 2 degrees of freedom

How to read the output

Worked example

For the sample data (1, 2.1), (2, 3.9), (3, 6.2), (4, 7.8), (5, 10.1), the slope is about 1.99 and the intercept about 0.05, giving y = 0.05 + 1.99x with r very close to 1. Predicting x = 6 gives y ≈ 12.

Cautions

Related tools: summarize each column with the Standard Deviation Calculator, check significance with the P-Value Calculator, or work with percent differences in the Percent Change Calculator.

Frequently asked questions

How do you find the line of best fit?

Use least squares: the slope is the sum of the products of x and y deviations from their means divided by the sum of squared x deviations, and the intercept is the mean of y minus the slope times the mean of x. This calculator does all of that when you paste your data.

What does the correlation coefficient r tell me?

It measures how closely the points follow a straight line, from -1 for a perfect downward line to +1 for a perfect upward line. A value near 0 means little linear relationship, although a curved relationship could still exist.

What is R-squared?

R-squared is r squared. It is the proportion of the variation in y that the straight-line model explains. An R-squared of 0.72 means the line accounts for about 72% of the variation.

How many data points do I need?

You need at least 2 points to draw a line and at least 3 to get a standard error and a p-value. More points make the estimate more reliable, and the x values must not all be identical.

Can I use this to predict a value?

Yes. Enter an x value in the prediction box to read the predicted y from the fitted line. Predictions are most reliable inside the range of your data and less reliable far outside it.

What is the difference between regression and correlation?

Correlation gives a single number for the strength and direction of a linear relationship. Regression goes further by giving the equation of the line so you can predict one variable from the other.