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.
—
—
—
—
—
—
—
—
—
—
—
—
—
—
Data and Line
—
Residual Plot
Residuals against fitted values. A healthy plot is a shapeless band around zero.
How it was calculated
Residual measures
Notes on this data
Residual Table
How to Use This Calculator
- 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.
- 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.
- For the other two modes, enter the intercept a and slope b of y = a + bx.
- 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.
| Pattern | What it looks like | What it suggests | What to try |
|---|---|---|---|
| Random band | Points scatter evenly above and below zero | A straight line fits and the spread is steady | Keep the model |
| Curve | U-shape or arch | The relationship is not linear | Add a squared term, transform a variable, or use a curve |
| Funnel | Spread widens or narrows from left to right | Unequal variance | Transform y (for example, take logs) or use weighted least squares |
| Lone outlier | One point far from the others | A data error or an unusual case | Check the record, then refit with and without it |
| Long runs | Many positive residuals, then many negative, in time order | Residuals depend on one another | Use 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.
| Type | Formula | Units | Use |
|---|---|---|---|
| Raw residual | y − ŷ | Same as y | Size of the miss for one point |
| Standardized (simple) | e ÷ s | None | Rough scale: how many standard errors |
| Standardized (this calculator) | e ÷ (s√(1 − h)) | None | Flagging 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
Correlation Coefficient Calculator
Pearson, Spearman, and Kendall with a regression line.
Constant of Proportionality Calculator
Find k = y/x and check proportional tables.
Mean Absolute Deviation Calculator
Average distance of each value from the mean.
Empirical Rule Calculator
The 68-95-99.7 rule for normal data.
Process Capability Index Calculator
Cp, Cpk, and PPM against tolerance limits.
Poisson Distribution Calculator
Probability of a number of events in an interval.