Residual Calculator (Observed − Predicted)

Compute the residual of a regression: e = observed − predicted.

Science Single+batch RMSE
Rate this calculator · 3.5 (2)

Residual

e = y − ŷ · SSR · MAE · RMSE · R²

Instructions — Residual Calculator (Observed − Predicted)

  1. Pick Single point for a one-shot residual, or Batch mode to analyze multiple data points.
  2. For single mode, enter the observed value y and the predicted value ŷ.
  3. For batch mode, paste observed-predicted pairs one per line, separated by comma or space.
  4. Read the residual, absolute error, squared error and percent error (single mode) or SSR, MAE, RMSE and R² (batch mode).

Formulas

Single residual:

$$e_i = y_i - \hat{y}_i$$

Sum of squared residuals (SSR or RSS):

$$SSR = \sum_{i=1}^{n} (y_i - \hat{y}_i)^2$$

Mean absolute error:

$$MAE = \frac{1}{n}\sum_{i=1}^{n} |y_i - \hat{y}_i|$$

Root mean square error:

$$RMSE = \sqrt{\frac{1}{n}\sum_{i=1}^{n}(y_i - \hat{y}_i)^2}$$

Coefficient of determination:

$$R^2 = 1 - \frac{SSR}{SST}, \quad SST = \sum_{i=1}^{n}(y_i - \bar{y})^2$$

Reference

  • e > 0: observed exceeds predicted — model under-predicted
  • e < 0: observed below predicted — model over-predicted
  • e = 0: perfect fit at this point
  • Σe ≈ 0: required for unbiased OLS regression with intercept
  • RMSE in same units as y: easier to interpret than SSR
  • MAE robust to outliers — less sensitive than RMSE
  • R² > 0.7: typical "good fit" threshold (varies by field)
  • R² < 0: model worse than predicting the mean of y

Article — Residual Calculator (Observed − Predicted)

Residual calculator

A residual is the difference between an observed value and the corresponding value predicted by a model, written e = y − ŷ. If the observed value is 125 and the model predicted 120, the residual is +5. Positive residuals mean the model under-predicted; negative residuals mean it over-predicted. The smaller the residuals, the closer the fit.

Residuals are the workhorse of regression diagnostics. They tell you whether your model captures the structure of the data or systematically misses certain regions. They feed into goodness-of-fit metrics — sum of squared residuals (SSR), mean absolute error (MAE), root mean square error (RMSE), and R². Every line of statistical inference about a linear model runs through the residual matrix.

What is a residual?

A residual is a single number per data point: how far the actual observation deviates from the regression prediction at that point. If you have 100 data points and fit a line, you get 100 residuals — one per observation. They live in the same units as the dependent variable. A residual of 5 in a house-price regression means the model missed by $5 (or $5,000, depending on scale).

By construction, ordinary least squares regression chooses the line that minimizes the sum of squared residuals. Other algorithms minimize different residual functions: least absolute deviation minimizes Σ|e_i|, quantile regression minimizes asymmetric weighted residuals, and so on. Whatever you minimize defines what residual you care about.

Did you know

The term "residual" in regression comes from Carl Friedrich Gauss's 1809 derivation of the least-squares method for astronomical orbit fitting. He was tracking the dwarf planet Ceres and needed to estimate its orbital parameters from imperfect telescope observations. The residuals — observation minus orbital prediction — were what he minimized to recover the orbit, a procedure that recovered Ceres in 1801 after it had been lost behind the sun.

The residual formula

The basic formula is simple subtraction. The aggregate metrics derive from it.

Residual formulas
eᵢ = yᵢ − ŷᵢ individual residual
SSR = Σ eᵢ² sum of squared residuals
MAE = (1/n) × Σ|eᵢ| mean absolute error
RMSE = √(SSR / n) root mean square error
R² = 1 − SSR/SST coefficient of determination
eᵢ_std = eᵢ / s standardized residual

The squared formulation in SSR and RMSE was chosen for mathematical convenience — squares are differentiable, absolute values are not — but it has a side effect: large residuals dominate the metric. A single outlier can pull RMSE up substantially while leaving MAE roughly unchanged.

Residual vs error

The two words are often conflated but the distinction matters in formal statistics. Error refers to the deviation between an observation and the true unobservable population mean — a theoretical quantity. Residual refers to the deviation between an observation and the model's fitted prediction — an observed quantity. Residuals are sample estimates of errors.

Because you never see the true population, you never see true errors. You only see residuals, which approximate the errors with some sampling noise. This distinction underlies inference: standard errors of coefficients, confidence intervals and hypothesis tests all rely on assumptions about the true errors being modelled, and residuals are the only window into them.

Using residuals to judge model fit

Three numbers summarize how well a model fits across an entire dataset: SSR, RMSE and R². All three are derived from residuals.

  • SSR (sum of squared residuals): always non-negative. Smaller is better. Scale-dependent — comparing across datasets requires normalization.
  • RMSE: RMSE is in the units of y. RMSE of 5 on a house price model means typical prediction error is $5,000.
  • MAE: also in units of y. Less sensitive to outliers than RMSE.
  • R²: proportion of variance in y explained by the model. R² = 0.8 means 80% of variation in y is captured.
  • Adjusted R²: R² penalized for the number of predictors. Standard for comparing nested models.
  • F-statistic: ratio of explained to unexplained variance. Tests whether the model is better than the mean.

Residual plots and diagnostics

A scatter plot of residuals against fitted values is the single most useful diagnostic tool in linear regression. A good model produces a featureless cloud centered at zero. Patterns reveal trouble.

Good fit
Random scatter
no pattern around zero
Bad fit
Curved or funneled
model missed structure
Funnel-shaped residuals indicate heteroscedasticity

If residual variance grows with the fitted value (creating a fan or funnel shape on the residual plot), the OLS assumption of constant variance is violated. Standard errors of coefficients become biased — usually too small — leading to overconfident confidence intervals and inflated t-statistics. Common remedies include weighted least squares, log-transformation of y, or robust standard errors (Huber-White sandwich estimator).

Residual aggregates — SSR, MAE, RMSE

The three classical aggregates serve different purposes. SSR is the metric you minimized to fit the model; it is the obvious goodness-of-fit number, but its scale depends on n and on the units of y. RMSE corrects for n and keeps the units of y, making it the most interpretable single number. MAE is more robust to outliers but does not have the nice statistical properties of RMSE (it is not differentiable).

The relationship RMSE ≥ MAE always holds, with equality only when all residuals have the same magnitude. The ratio RMSE/MAE between roughly 1.0 and 1.5 typically indicates well-behaved residuals; ratios above 2 suggest heavy tails or outliers driving the squared metric.

Common residual mistakes

Tip

Always inspect a residual plot before trusting any regression output. R² of 0.95 can hide a clear curved pattern that signals a missing quadratic or interaction term. Numbers like RMSE summarize, but plots reveal.

The most common error is confusing residual with error in writing or speech. The two terms are interchangeable in casual use, but in formal statistical inference the distinction matters. Standard error of the regression, for example, refers to the estimated standard deviation of the true errors, computed from the residuals.

A second trap is computing residuals on training data and treating those as a measure of predictive accuracy. In-sample residuals are biased downward because the model has already been fit to those points. Out-of-sample residuals from held-out data, cross-validation or a test set are the honest measure of prediction error.

A third trap is reporting R² without considering whether the model has an intercept. Without an intercept, the formula R² = 1 − SSR/SST does not behave as expected and can be negative even when the model is reasonable. Always include an intercept unless you have a strong theoretical reason to force the line through the origin.

A fourth trap is using RMSE alone to compare models with different output scales. RMSE inherits the units of y. A model predicting log(price) has RMSE in log-dollars; a model predicting price has RMSE in dollars. Comparing the two requires careful unit conversion or a normalized metric like MAPE (mean absolute percentage error).

FAQ

A residual is the difference between an observed value and the corresponding value predicted by a model: e = y − ŷ. Residuals measure how far each data point deviates from the regression line. They are the building blocks for goodness-of-fit metrics like SSR, RMSE and R².
In statistics, error refers to the deviation between an observed value and the true unobservable population mean. Residual refers to the deviation between an observed value and the model's fitted prediction. Residuals are observable estimates of the errors.
In ordinary least squares (OLS) regression with an intercept, the sum of residuals is exactly zero by construction. This is a consequence of the normal equations that define the OLS solution. If Σe ≠ 0 in your output, either the model has no intercept term or there is a calculation error.
RMSE (root mean square error) is the square root of the average squared residual. MAE (mean absolute error) is the average of the absolute residuals. RMSE penalizes large errors more than small ones because squaring inflates large deviations. MAE is more robust to outliers.
Plot residuals on the y-axis against predicted values (or against a predictor) on the x-axis. Random scatter around zero indicates a well-fitting linear model. Patterns — a curve, funnel shape, or trend — signal that the model misses structure. Funnels indicate heteroscedasticity (non-constant variance).
A standardized residual is the raw residual divided by its estimated standard deviation: z_i = e_i / s, where s = √(SSR / (n − p)) and p is the number of model parameters. Values outside ±2 are often flagged as potential outliers; outside ±3 strongly suggest investigation.
R² = 1 − SSR / SST, where SST = Σ(y − ȳ)² is the total sum of squares. R² near 1 means residuals are small relative to natural variability of y. R² near 0 means the model explains little; R² < 0 means the model is worse than just predicting the mean.
Yes. Linear regression assumes residuals are normally distributed, have constant variance (homoscedasticity), are independent, and have zero mean. A Q-Q plot of residuals checks normality. A residuals-vs-fitted scatter checks variance. A Durbin-Watson statistic on time-series residuals checks autocorrelation.