Residual Calculator Formula

Understand the math behind the residual calculator. Each variable explained with a worked example.

Formulas Used

Residual

residual = observed - predicted

Predicted Value (y-hat)

predicted_val = predicted

|Residual|

abs_residual = abs(observed - predicted)

Squared Residual

sq_residual = pow(observed - predicted, 2)

Variables

VariableDescriptionDefault
observedObserved Value (y)45
b0Intercept (b0)5
b1Slope (b1)2
xx Value18
predictedDerived value= b0 + b1 * xcalculated

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
  1. 01Predicted y_hat = 5 + 2*18 = 5 + 36 = 41
  2. 02Residual = 45 - 41 = 4
  3. 03The observed value is 4 units above the regression line
  4. 04Squared residual = 4^2 = 16

Ready to run the numbers?

Open Residual Calculator