Regression Calculator
Fit a straight line that predicts Y from X, then try a value of X to see its predicted outcome. You get the slope, intercept, R squared and residual standard error. A short table lets you compare the fitted line with the observations it came from.
Loading the calculator. It runs in your browser, so JavaScript needs to be on.
How to use the Regression Calculator
- Paste paired measurements into X values and Y values, separating numbers with commas, spaces or new lines.
- Keep each pair in the same position in both lists. Enter 2 to 10,000 pairs, with at least two distinct X values.
- Enter Predict Y at X using the same X units as the source data.
- Read the equation and Predicted Y. Check R squared, residual standard error and the observed-versus-fitted table before relying on the line.
The formula
Slope b = sum of (x - mean X)(y - mean Y) / sum of (x - mean X) squared. Intercept a = mean Y - b times mean X. The fitted value is y-hat = a + bx. Residual = observed Y - fitted Y. R squared = 1 - SSE/Syy, where SSE is the sum of squared residuals and Syy is the total centered sum of squares for Y. Residual standard error = square root of [SSE/(n - 2)].
Worked example
With X = 1, 2, 3 and Y = 3, 5, 7, each increase of one X unit adds two Y units. The fitted equation is y = 2x + 1. At X = 4, predicted Y is 9. All three points lie exactly on the line, so R squared is 1 and every residual is zero.
The slope keeps the units
If X is hours and Y is dollars, a slope of 20 means an additional hour is associated with $20 higher predicted Y. The intercept is the predicted value at X = 0. It may have little practical meaning if zero is far outside the observed range. Reversing X and Y generally produces a different fitted relationship, not the algebraic inverse of this one.
Residuals reveal what R squared misses
Residuals are vertical errors from the fitted line. A curved pattern in those errors suggests a straight line is missing structure. Increasing error spread suggests predictions become less precise as X rises. The table shows the first 12 pairs, while all valid pairs enter the calculation. R squared describes in-sample fit; it does not guarantee accurate future predictions or establish causation.
Prediction outside the data is extrapolation
The result warns when your prediction X falls outside the observed range. A trend fitted between X = 1 and 5 can fail badly at X = 100. The prediction is a point estimate, with no prediction interval. Residual standard error needs at least three pairs because fitting slope and intercept uses two degrees of freedom. With constant Y, the line is horizontal and R squared is undefined.
Regression Calculator questions
What is the difference between correlation and regression?
Correlation summarizes linear association symmetrically. Regression fits an equation to predict a chosen response Y from X.
Can the slope be negative?
Yes. A negative slope means predicted Y falls when X increases.
Why does my line fit perfectly with two points?
Two points with distinct X values define one straight line. That exact fit provides no residual degrees of freedom to estimate typical prediction error.
Related calculators
- Correlation CalculatorPaste paired X and Y values to calculate Pearson correlation, R squared, means and sample...
- Standard Deviation CalculatorPaste numbers to calculate population or sample standard deviation, variance and mean....
- Mean, Median, Mode CalculatorPaste a list of numbers to find the mean, median, modes, sum and range. Repeated values...
- Confidence Interval CalculatorEnter a mean, standard deviation and sample size, or a success count, to calculate a t, z...
- Sample Size CalculatorEnter confidence, margin of error and an expected proportion or standard deviation to...