Residual Calculator — Residuals, Sum of Squares & Residual Plot

Residual Calculator

Find the residual for every data point: observed y minus predicted y. Fit the best straight line or test your own equation, then see the sum of squared residuals, R², and a residual plot.

Residual = observed y − predicted ŷ

Enter your x and y pairs. The calculator fits the least-squares line ŷ = a + bx and reports the residual of every point.

What do you want to do?

Data (up to 1,000 pairs)

0 pairs

How to Use This Calculator

  1. Pick a mode. Fit a line to my data finds the least-squares line for you. Use my own equation measures how far your data sits from a line you already have. Single point gives one residual.
  2. Paste your data as two columns (x, then y), or switch to Two lists. Fitting a line needs at least 2 points with different x values; 5 or more makes the residual plot useful.
  3. For the other two modes, enter the intercept a and slope b of y = a + bx.
  4. Press Calculate Residuals. Read the sum of squared residuals, then check the residual table and the plot for points that stand out or patterns that curve.

What Is a Residual?

A residual calculator calculates the difference between an observed value and its predicted value in regression analysis. The residual formula is e = y − ŷ, where y represents the observed value and ŷ represents the predicted value. Positive residuals indicate underprediction, while negative residuals indicate overprediction. Residuals help evaluate model accuracy and identify prediction errors.

On a scatter plot, a residual is the vertical distance from a data point to the regression line. There is one residual per data point.

e > 0

The point is above the line. The model predicted too low.

e = 0

The line passes exactly through the point.

e < 0

The point is below the line. The model predicted too high.

Residuals are often called errors, but the word means “unexplained difference”, not a mistake in your analysis. Small residuals mean the line describes the data closely. For a least-squares line, the residuals always add up to zero, so their average is zero too. That is why fit is judged by the squared residuals, not by their plain sum.

Definition reference: Statistics How To — Residual.

Residual Formulas

Predicted value

ŷ = a + bx

a is the intercept and b is the slope of the line.

Residual

e = y − ŷ

Observed minus predicted, in the units of y.

Sum of squared residuals

SSE = Σe² = e₁² + e₂² + … + eₙ²

Also written RSS. The least-squares line makes this as small as possible.

Least-squares line

b = Sxy ÷ Sxx, a = ȳ − b·x̄

Sxy = Σ(x − x̄)(y − ȳ), Sxx = Σ(x − x̄)².

Standard error and R²

s = √(SSE ÷ (n − 2)), R² = 1 − SSE ÷ SST

SST = Σ(y − ȳ)², the total variation in y.

Standardized residual

rᵢ = eᵢ ÷ (s·√(1 − hᵢ))

Leverage hᵢ = 1/n + (xᵢ − x̄)² ÷ Sxx.

Model assumptions: Penn State STAT 462 — Residuals vs. Fits Plot.

Worked Example 1: Residuals for Your Own Line

Check the line y = 2x + 2 against the points (1, 4), (2, 7), and (3, 5).

  • Predicted values: ŷ = 2(1) + 2 = 4, ŷ = 2(2) + 2 = 6, ŷ = 2(3) + 2 = 8.
  • Residuals (y − ŷ): 4 − 4 = 0, 7 − 6 = 1, 5 − 8 = −3.
  • Sum of squared residuals: 0² + 1² + (−3)² = 10.
  • The residuals do not add to zero (the sum is −2), so this is not the least-squares line. Use Fit a line to my data on the same points and the SSE falls to about 4.17.

Worked Example 2: Fitting the Line First

Eight observations: x = 1 to 8, y = 3.1, 4.8, 6.2, 8.9, 9.8, 12.4, 13.1, 17.6.

  • Sums: x̄ = 4.5, ȳ = 9.4875, Sxx = 42, Sxy = 81.25.
  • Line: b = 81.25 ÷ 42 = 1.9345 and a = 9.4875 − 1.9345 × 4.5 = 0.7821, so ŷ = 0.7821 + 1.9345x.
  • Residuals: 0.383, 0.149, −0.386, 0.380, −0.655, 0.011, −1.224, 1.342. They add to 0.
  • SSE = 4.1887, s = √(4.1887 ÷ 6) = 0.8355, and R² = 0.974.
  • The last point has a standardized residual of 2.10, just past the usual cut-off of 2, so it is worth a second look.

How to Read a Residual Plot

Plot residuals on the vertical axis and fitted values on the horizontal axis. The shape tells you whether a straight line was the right model.

PatternWhat it looks likeWhat it suggestsWhat to try
Random bandPoints scatter evenly above and below zeroA straight line fits and the spread is steadyKeep the model
CurveU-shape or archThe relationship is not linearAdd a squared term, transform a variable, or use a curve
FunnelSpread widens or narrows from left to rightUnequal varianceTransform y (for example, take logs) or use weighted least squares
Lone outlierOne point far from the othersA data error or an unusual caseCheck the record, then refit with and without it
Long runsMany positive residuals, then many negative, in time orderResiduals depend on one anotherUse a time-series method

Reading these plots is partly a judgement call, and with fewer than about ten points almost any pattern can appear by chance. A high R² does not replace the plot: a curved relationship can still give an R² above 0.9.

Residual analysis guidance: NIST/SEMATECH e-Handbook of Statistical Methods — Model Validation.

Types of Residuals

The raw residual is the most common, but scaled versions make it easier to judge which points are unusual.

TypeFormulaUnitsUse
Raw residualy − ŷSame as ySize of the miss for one point
Standardized (simple)e ÷ sNoneRough scale: how many standard errors
Standardized (this calculator)e ÷ (s√(1 − h))NoneFlagging outliers; adjusts for leverage
Percent residual(y − ŷ) ÷ y × 100%Comparing errors across large and small values

As a rule of thumb, a standardized residual beyond ±2 is unusual (about 1 point in 20 under normal errors), and beyond ±3 deserves a close look.

Frequently Asked Questions

What is a residual in statistics?

A residual is the difference between the observed value and the predicted value from a regression model: e = y − ŷ. In other words, it is the error left over after the line has done its work. Every data point in your dataset has one residual value, which is the part of the y-value (the dependent variable) that the equation does not explain.

How do I calculate a residual?

Put the x value (the independent variable) into the line to get ŷ, then subtract it from the actual value of y. For y = 2x + 2 and the observation (2, 7), ŷ = 6 and the residual is 7 − 6 = 1. A residual calculator repeats this for every row at once, which saves time when you have more than a handful of points.

What do positive and negative residuals mean?

A positive residual means the point lies above the regression line, so the model underestimated it. A negative residual means the point lies below the line and the model overestimated it. The sign shows the direction; the size is the prediction error, or how far the line missed.

Why do the residuals add up to zero?

For a least squares line with an intercept, the line of best fit always passes through the point (x̄, ȳ). The method chooses the slope and intercept coefficients so that this holds, which balances the positive and negative residuals and makes the sum of residuals exactly zero. If the sum is not zero, the line is not the least squares line, or it was fitted without an intercept.

Why use the sum of squared residuals instead of the plain sum?

Positive and negative residuals cancel each other, so the plain sum can be zero even for a poor fit. Squaring makes every term positive and penalizes large misses more heavily. The least squares method picks the line with the smallest sum of squared residuals. Divide that sum by n and you get the mean squared error; divide by n − 2 and you get an estimate of the error variance.

What is a residual plot and what should it look like?

A residual plot graphs the residuals against the fitted values (or against x). If a straight line is a good model, the points form a shapeless, roughly horizontal band around zero. A curve, a funnel, or a lone far-off point points to a problem with the model. The plot shows these problems more clearly than a scatter plot of y against x, and it tells you about the accuracy of the fit in a way R² alone cannot.

What is a standardized residual, and when is a point an outlier?

A standardized residual divides the residual by its estimated standard deviation, so it has no units. This calculator flags values beyond ±2. That is only a guide: in 100 well-behaved observations you would still expect about five of them to cross it.

Can linear regression explain every relationship?

No. Linear regression only describes straight-line trends. Growth that doubles over time, saturating effects, and cycles need other models. Large, patterned residuals are the signal that the straight line is the wrong shape, however high R² looks.

Other Useful Calculators

Disclaimer: This calculator is for educational, informational, and preliminary analytical use. It fits a straight line by ordinary least squares or measures residuals against the line you enter. Residuals describe how well a model matches the data you entered; they do not show that the model is correct or that one variable causes another. Standardized residuals and the pattern notes are rules of thumb and assume independent observations. For research, medical, financial, or other consequential decisions, review the data and assumptions and consult a qualified statistician.

Last updated: October 8, 2026