Linear Regression Calculator

Enter x,y pairs to calculate the least-squares regression line, slope, intercept, R-squared, correlation, residuals, prediction, and a readable scatterplot with the fitted line.

Slope + Intercept R-squared Residuals Prediction Server-rendered Chart
Share this tool

Use one x,y pair per line. Commas and spaces are supported, for example 3, 7 or 3 7.

The fitted line will estimate y at this x-value.

Quick load

Fitting line...

Your regression result appears here

Submit paired data to get the fitted line, R-squared, correlation strength, residuals, prediction, and scatterplot.

Example scatterplot and fitted lineAn example visual showing data points around an upward regression line. x y

How the Linear Regression Calculator Works

This least-squares linear regression calculator fits a straight line to paired x,y data. The line has the form y = mx + b, where m is the slope and b is the intercept. The calculator accepts one data pair per line, computes the fitted equation, and shows how well the line explains the variation in your y-values.

Linear regression is useful when the relationship between two numeric variables is approximately straight. Common examples include study time and test score, advertising spend and sales, temperature and energy use, or age and measured performance. A high R-squared value can be helpful, but it does not prove causation, and it does not guarantee that a straight line is the right model outside your observed data range.

Regression Diagram

The points are the observations. The fitted line is chosen so the squared vertical residuals are as small as possible.

Least-squares regression residual diagramData points, regression line, and vertical residual distances. fitted line residuals x values y values

Least-Squares Formula

For n paired observations, first calculate the means:

x-bar = sum(x) / n
y-bar = sum(y) / n

Then calculate the centered sums:

Sxx = sum((x - x-bar)^2)
Sxy = sum((x - x-bar)(y - y-bar))

The regression coefficients are:

slope = Sxy / Sxx
intercept = y-bar - slope * x-bar

The calculator also computes residuals, sum of squared error, RMSE, correlation r, and R-squared. These values help you judge whether the line is a useful summary of the data.

Worked Example

xyPredicted yResidual
122.2-0.2
233.1-0.1
354.01.0
444.9-0.9
565.80.2

For points (1,2), (2,3), (3,5), (4,4), and (5,6), the means are x-bar = 3 and y-bar = 4.

The centered sums are Sxx = 10 and Sxy = 9, so the slope is 9 / 10 = 0.9.

The intercept is 4 - 0.9 * 3 = 1.3, giving the fitted equation y = 0.9x + 1.3.

If x = 6, the predicted y-value is 0.9 * 6 + 1.3 = 6.7.

How to Interpret R-Squared and r

R-squared is the fraction of observed y variation explained by the fitted line. An R-squared of 0.82 means about 82% of the variation in y is explained by the linear model for the submitted dataset.

Correlation r describes direction and strength. Positive r means y tends to increase as x increases. Negative r means y tends to decrease as x increases. Values near -1 or +1 indicate a stronger linear association.

Both values can be misleading when the data are curved, contain influential outliers, combine unrelated groups, or use a prediction x-value far outside the observed range.

When Not to Use a Straight Line

  • Use caution when a scatterplot visibly curves instead of following a roughly straight trend.
  • Do not rely on regression for causal claims without study design, domain evidence, and confounder control.
  • Avoid extrapolating far beyond the observed x-values unless you have outside evidence that the trend remains linear.
  • Inspect residuals. Large patterns in residuals often mean the straight-line model is missing structure.

Related Calculators and References

Linear Regression FAQ

What input format does the calculator accept?

Enter one point per line. Both comma-separated pairs such as 2, 5 and space-separated pairs such as 2 5 are accepted.

What does the slope mean?

The slope is the fitted change in y for a one-unit increase in x. A slope of 3 means the line increases by 3 y-units for every 1 x-unit.

Is R-squared always better when it is high?

Not always. A high R-squared can still come from outliers, grouped data, or a relationship that is not useful for prediction. Always inspect the scatterplot and residuals.

Can this calculator prove causation?

No. Linear regression measures association in the submitted data. Causation requires study design and domain evidence beyond the fitted equation.