Advertisement
Advertisement
STATISTICS

Residual Calculator — per-point residuals, leverage and standardised residuals

Enter your data and get every residual individually, with its leverage, its standardised value and a residual plot, so you can see which points the model fits badly rather than only how well it fits overall.

Separate with commas, spaces or line breaks. Between 3 and 200 values.
Must have exactly as many values as X, in the same order.
Use your own line when the model was fitted elsewhere, on a training set, or by a method other than least squares. Residuals against a supplied line will not sum to zero, and that is informative.
Two is the usual convention and roughly corresponds to the outer 5% of a normal distribution. Three is a stricter threshold.
Residual standard error
 
Sum of squared residuals
Largest residual by magnitude
Points flagged
Sum of residuals
Line used:
Point by point:
Working:
Tip: the bar plot is a residual plot laid on its side. What you are looking for is the absence of a pattern. A run of bars all pointing the same way, or bars that fan out as x increases, means the model is wrong in a specific and fixable way.
Advertisement

The residual calculator above takes a set of paired observations, measures every point against a straight line, and returns the individual residuals rather than a single summary of fit. For each point it gives the fitted value, the raw residual, the leverage, the standardised residual and a flag when that standardised value crosses your chosen threshold.

Arb Digital publishes it because the summary statistics of a regression hide exactly the information that matters most. Our linear regression calculator returns the fitted line, and the R-squared calculator returns how much variance it explains, but neither tells you which observation is fighting the model or whether the errors have a pattern. Both of those questions are answered only by looking at the residuals one at a time, and that is what this page is for.

What This Residual Calculator Does

It works in two modes. In the default mode it fits the least-squares line to your data and measures residuals against that. In the second mode you supply a slope and intercept of your own, which is what you need when the model was fitted on different data, produced by another method, or handed to you by someone else. That distinction matters: residuals against a least-squares line always sum to exactly zero by construction, while residuals against a supplied line do not, and their sum is then a direct measure of bias.

For each point it reports the fitted value, the residual, the leverage and the standardised residual. Leverage measures how far that point's x value sits from the centre of the x range, and it controls how much the point can pull the line towards itself. The standardised residual divides the raw residual by an estimate of its own standard deviation, which accounts for the fact that high-leverage points have systematically smaller residuals even when they fit badly.

The headline number is the residual standard error, the typical size of a residual in the units of y. The grid adds the sum of squared residuals, the largest residual by magnitude, the count of flagged points and the sum of residuals. That last figure is a check in fitted mode, where it must be zero, and a finding in supplied-line mode, where it need not be.

How to Use It

  1. Paste your X and Y values. They must be the same length and in matching order. Commas, spaces and line breaks all work as separators.
  2. Choose the line. Leave the default to fit a fresh least-squares line, or switch to supplying your own slope and intercept if the model came from elsewhere.
  3. Look at the bar plot before the numbers. Residuals should scatter without pattern. Any structure in the bars is the finding.
  4. Set the flag threshold to two for the usual convention or three for a stricter one, and read the point-by-point table for anything flagged.
  5. Check the leverage column on any flagged point. A large residual at low leverage is an unusual observation; a large residual at high leverage is a point that may be distorting the whole line.

The Formula and How It Is Calculated

A residual is simply the observed value minus the fitted value: e = y − ŷ. For simple linear regression the fitted value is the intercept plus the slope times x, so each residual is the vertical distance from the point to the line. The sum of squared residuals is what least squares minimises, and the residual standard error is the square root of that sum divided by n minus 2, where the 2 accounts for the two parameters the line consumed.

Leverage in simple regression has a compact form: h = 1/n + (x − x̄)² / Sₓₓ, where Sₓₓ is the sum of squared deviations of x from its mean. It ranges between 1/n and 1, and it sums across all points to exactly 2, the number of parameters. The standardised residual, sometimes called the internally studentised residual, is e divided by s times the square root of 1 minus h. The NIST/SEMATECH e-Handbook section on whether model residuals are well behaved sets out the standard checks these numbers support.

Worked example, using the data loaded by default: x values 1 through 5 and y values 2, 4, 5, 4, 5. The sum of x is 15 and the sum of y is 20, so both means are 3 and 4. Sₓₓ is 55 minus 45, which is 10, and Sₓₙ is 66 minus 60, which is 6, so the slope is 0.6 and the intercept is 4 minus 0.6 times 3, which is 2.2. The fitted values are 2.8, 3.4, 4.0, 4.6 and 5.2, giving residuals of −0.8, 0.6, 1.0, −0.6 and −0.2. Those sum to exactly zero, as they must. The sum of squares is 2.4, so the residual standard error is the square root of 2.4 divided by 3, which is the square root of 0.8, or 0.894427. The leverages are 0.6, 0.3, 0.2, 0.3 and 0.6, summing to 2. The standardised residuals are −1.414214, 0.801784, 1.25, −0.801784 and −0.353553.

Advertisement

Why Raw Residuals Mislead and Standardised Ones Do Not

Raw residuals do not all have the same variance, even when the underlying errors do. A point at the far end of the x range pulls the line towards itself, so the line passes closer to it than it would if the point were near the middle. Its residual is therefore systematically smaller, not because the model fits it better but because the model was bent to accommodate it.

The variance of the ith residual is the error variance times one minus the leverage. At the centre of the data leverage is close to 1/n and the residual has nearly the full error variance. At an extreme x value leverage can approach one and the residual variance approaches zero: the line is dragged through the point. Dividing by the square root of one minus the leverage undoes this, so standardised residuals are comparable across the whole range.

The practical consequence is important. If you scan raw residuals for the largest one, you will systematically overlook badly fitting points at the edges of your x range, which are exactly the points most capable of distorting the model. This is why the leverage column is displayed alongside every residual here rather than hidden. The outlier calculator handles the different question of unusual values in a single variable, where leverage does not arise.

Reading a Residual Plot

A residual plot is a scatter of residuals against fitted values or against x, and its whole purpose is to be boring. Random scatter around zero with no visible structure means the linear model has extracted everything systematic from the data. Anything else is a message.

A curved band, with residuals negative at both ends and positive in the middle or the reverse, means the relationship is not linear. The fix is a transformation or an extra term, not a better line. A fan shape, with residuals small at one end and large at the other, means the error variance is not constant, which does not bias the slope but makes every standard error and confidence interval wrong. A run of consecutive residuals with the same sign, in data collected in order, means autocorrelation, and the usual formulas assume independence.

An isolated large residual with the rest well behaved is a single unusual observation, and the correct response is to investigate that observation rather than to delete it. Removing points because they fit badly, without a reason external to the fit, is how a model is made to look good rather than made correct. The NIST/SEMATECH e-Handbook section on telling whether a model fits your data works through these patterns in detail.

Leverage, Influence and the Difference Between Them

High leverage means a point has an unusual x value and therefore has the potential to move the line. It says nothing about whether it actually does. A point far to the right of the data that happens to lie exactly on the line the rest of the points define has enormous leverage and no influence at all: remove it and nothing changes.

Influence is leverage combined with a poor fit. A point that has both an extreme x value and a large residual will drag the line towards itself, and removing it changes the slope materially. The standard summary measure is Cook's distance, which combines the standardised residual and the leverage into a single figure and answers the question of how much the fitted values would move if the point were dropped.

The reason to keep the two ideas apart is that the remedies differ. A high-leverage point that fits well is usually a valuable observation extending the range of the data, and should be kept. A high-leverage point that fits badly needs to be understood before anything else is done, because a single such point can reverse the sign of a slope in a small dataset.

What Residuals Cannot Tell You

Residuals are computed from the model you fitted, so they can only reveal the ways in which that model fails on the data you gave it. They cannot tell you that an important predictor is missing, unless its effect happens to correlate with x. They cannot tell you that the relationship reverses outside the observed range. And a set of perfectly behaved residuals is not evidence of causation, only that a straight line describes the association adequately.

They also become less informative as the sample shrinks. With five or six points, patterns appear in random residuals purely by chance, and a formal test of normality on the residuals has almost no power to detect anything. Treat small-sample residual plots as a check against gross errors rather than as a diagnostic. Our standard error calculator and correlation coefficient calculator cover the related precision questions.

Need reporting that shows where the model breaks?

Arb Digital builds measurement and attribution systems that surface the cases a model gets wrong instead of averaging them away.

Browse All Free Tools Talk To Our Team

Common Mistakes to Avoid

  • Comparing raw residuals across the x range — high-leverage points have systematically smaller residuals, so the largest raw residual is not the worst-fitting point.
  • Deleting points because they have large residuals — that fits the model to the data twice and produces an optimistic picture with no external justification.
  • Treating residuals summing to zero as evidence the model is right — it is arithmetic. Least squares forces it, and it holds for a badly wrong line as long as that line was fitted by least squares.
  • Ignoring a curved residual pattern because R-squared is high — a high R-squared with curved residuals means a good but systematically wrong model, and the errors are worst at the extremes.
  • Confusing leverage with influence — a high-leverage point that lies on the line changes nothing if removed. Only a high-leverage point that fits badly is influential.

Related Free Tools From Arb Digital

Fit the line itself with the linear regression calculator, measure explained variance with the R-squared calculator, get the squared error summary with the mean squared error calculator, screen a single variable with the outlier calculator, or measure association strength with the correlation coefficient calculator. The full free online tools hub lists every statistics tool we publish.

Frequently Asked Questions

What exactly is a residual?

The observed value minus the value the model predicts for the same point. In simple regression it is the vertical distance from the data point to the fitted line, carrying a sign for which side of the line the point falls on.

Why do residuals from a least-squares fit always sum to zero?

Because minimising the sum of squares with an intercept term forces it algebraically. It is a property of the fitting method, not evidence that the model is correct, and it holds for badly wrong lines too.

What is a standardised residual?

The raw residual divided by an estimate of its own standard deviation, which is the residual standard error times the square root of one minus the leverage. It makes residuals comparable across the whole range of x.

What does leverage measure?

How far a point's x value sits from the centre of the x range, and therefore how much power it has to pull the fitted line towards itself. It ranges from one over the sample size up to one.

Is a large residual the same as an outlier?

Not necessarily. A large standardised residual marks a point the model fits poorly, which may be a data error, a genuine unusual case, or a sign the model itself is wrong for all the points.

Can I use residuals from a line I fitted elsewhere?

Yes. Switch the mode and supply your own slope and intercept. Those residuals will not sum to zero, and the sum then measures the bias of the supplied line on this data.

What pattern in a residual plot should worry me most?

Curvature, because it means the linear model is systematically wrong rather than merely imprecise, and the errors are largest exactly where predictions are usually most wanted, at the extremes of the range.

How many points do I need for residuals to be informative?

Enough that apparent patterns are not chance. With fewer than about fifteen points a residual plot mainly catches gross errors, and formal tests of the residual distribution have very little power.

This page explains a statistical diagnostic for educational purposes. Residuals can only reveal the ways a model fails on the data supplied to it, and a well-behaved residual plot is not evidence of a causal relationship.

Advertisement
Advertisement

Take it further