Residual Calculator Formula
Understand the math behind the residual calculator. Each variable explained with a worked example.
Formulas Used
Residual
residual = observed - predictedPredicted Value (y-hat)
predicted_val = predicted|Residual|
abs_residual = abs(observed - predicted)Squared Residual
sq_residual = pow(observed - predicted, 2)Variables
| Variable | Description | Default |
|---|---|---|
observed | Observed Value (y) | 45 |
b0 | Intercept (b0) | 5 |
b1 | Slope (b1) | 2 |
x | x Value | 18 |
predicted | Derived value= b0 + b1 * x | calculated |
How It Works
How to Calculate a Residual
Formula
Residual = Observed - Predicted = y - y_hat
where y_hat = b0 + b1*x
A residual is the vertical distance between an observed data point and the regression line. Positive residuals mean the point is above the line; negative means below. In least-squares regression, the sum of all residuals is zero. Examining residuals helps detect model violations.
Worked Example
Regression: y = 5 + 2x. At x = 18, the observed y = 45.
observed = 45b0 = 5b1 = 2x = 18
- 01Predicted y_hat = 5 + 2*18 = 5 + 36 = 41
- 02Residual = 45 - 41 = 4
- 03The observed value is 4 units above the regression line
- 04Squared residual = 4^2 = 16
Ready to run the numbers?
Open Residual Calculator