Skip to content
ZeroServer.tools

Linear Regression Calculator

Find the line of best fit and R² from your data points.

Format: x,y — one pair per line. Blank lines and invalid rows are ignored.

Regression Equation
y = 2.034286x + (-0.053333)
R² (coefficient of determination)
0.9979
Strong fit
Correlation (r)
0.998947
n (data points)
6
Summary Statistics
Slope (m)Intercept (b)nMean XMean Y
2.034286-0.0533330.997963.50007.0667
Predict Y for a given X
Predicted Y = 14.186667
Scatter Plot with Regression Line
Data Table
xypredictedresidual
1.00002.10001.98100.1190
2.00003.90004.0152-0.1152
3.00006.20006.04950.1505
4.00007.80008.0838-0.2838
5.000010.100010.1181-0.0181
6.000012.300012.15240.1476

About Linear Regression

Linear regression finds the straight line that best fits a set of data points by minimizing the sum of squared residuals (ordinary least-squares). The formula produces slope m and intercept b so you can express any trend as y = mx + band predict new values. R² (coefficient of determination) measures fit quality: >0.9 is a strong relationship, 0.7–0.9 moderate, and below 0.7 weak. The correlation coefficient r adds direction — positive for upward trends, negative for downward. All calculations run locally in your browser; no data is sent to any server.

Built and maintained by Meet Shah · Last updated

What this tool is used for

  • Fitting a line to a small set of paired values.
  • Getting an R-squared figure to see how much variance the line explains.
  • Predicting a value from the fitted line.
  • Checking a slope you estimated by eye from a scatter plot.
  • Producing a fit for a lab report or an exercise.

Frequently Asked Questions

What does least squares actually minimise?
The sum of the SQUARED vertical distances from each point to the line. Squaring is what makes the solution unique and computable in closed form, and it is also why a single distant outlier moves the line so much — its error is squared along with everything else.
What does R² tell me?
The proportion of the variance in y explained by the line, from 0 to 1. An R² of 0.95 means 95% of the variation is accounted for — and it says nothing about whether a straight line is the right model, which is the thing people read into it.
Can a high R² still be the wrong model?
Easily. Anscombe's quartet is the classic demonstration: four datasets with identical means, variances, regression lines and R², one of which is a clean parabola and another a single outlier driving everything. Plotting the residuals is what catches it.
Does the slope mean x causes y?
No, and this is the most consequential misreading of a regression. It measures association; causation requires an argument the arithmetic cannot supply. A confounder affecting both variables produces a strong, significant, entirely non-causal slope.
Is it safe to predict outside the data range?
No — extrapolation assumes the relationship continues, which the data cannot show. A linear fit over a narrow range routinely projects to absurd values well outside it, and biological and economic relationships in particular flatten or reverse at their extremes.

Common errors and gotchas

  • Reading correlation as causation, which the arithmetic cannot distinguish.
  • Extrapolating beyond the data range, where the fit has no support.
  • Trusting R-squared alone, when a high value can still come with a badly shaped residual pattern.
  • Fitting a line to data that is plainly curved.
  • Letting a single outlier determine the slope without noticing.

Related Calculators tools

Private & free — this tool runs entirely in your browser.