Skip to content
AITroveRead. Build. Understand.
Make this comfortable

Regression diagnostics: residual pattern, scale and influential routes

Last updated: 7 Oct 20265 min read
tutorial
AdvancedBy AITrove Editorial

Residual checks ask whether a fitted mean, error spread and individual observations support the intended inference.

Check the shape of error

A residual is observed delivery time minus the fitted time. Plot it against fitted time, distance, depot and calendar order. Curvature suggests that one straight slope misses structure; widening spread means a constant-error-scale model is questionable. Time ordering can reveal a shared disruption. A normal-looking histogram cannot repair an omitted depot effect or route dependence. The slope interpretation is limited by these design and model conditions.

Separate unusual outcomes from influence

A route can have a large residual but ordinary distance, or extreme distance with enough influence to move the line substantially. Refit after removing an identified route as a sensitivity check, then report both fits and investigate the record; do not delete it because it is inconvenient. Compare input provenance, sensor failure and legitimate long-distance service. The outlier policy should exist before inspecting its effect on a favorable coefficient.

Choose the response to a failure

If residual spread increases with distance, a transformation, weighted model or heteroskedasticity-aware uncertainty may be appropriate, depending on the question. If depots share shocks, use a depot-aware design or clustered uncertainty. If the relationship bends, fit an approved richer mean model and compare out-of-period error. These changes solve different problems; one fix does not automatically solve the others. Cluster resampling addresses dependence, and interval design depends on the error question.

Publish the diagnostic boundary

Save residual summaries by distance band and depot, a sensitivity refit for influential routes, the sample size and every exclusion rule. A small residual average is expected after fitting an intercept and is not a quality certificate. Report an error measure that cannot cancel positive and negative mistakes. The route review project rejects a candidate whose pooled fit hides rising errors on long trips.

Implementation

python
def route_error_bands(observed, fitted, distance, cut_off):
    if not (len(observed) == len(fitted) == len(distance)):
        raise ValueError("route columns differ in length")
    bands = {"near": [], "far": []}
    for actual, predicted, km in zip(observed, fitted, distance):
        bands["near" if km <= cut_off else "far"].append(abs(actual - predicted))
    return {name: (sum(errors) / len(errors) if errors else None)
            for name, errors in bands.items()}

report = route_error_bands([5, 9, 10, 15, 17],
                           [5.2, 8.2, 11.2, 14.2, 17.2],
                           [2, 4, 6, 8, 10], 6)
assert round(report["near"], 6) == round(2.2 / 3, 6)
assert round(report["far"], 6) == 0.5

Performance and operating cost

The band summary is O(n) time and O(n) stored absolute errors; streaming totals would reduce extra storage to O(1) for two bands. Refit-based influence checks cost at least one additional model fit per tested deletion. Diagnostic work is justified when a seemingly small aggregate error might conceal an expensive route segment.

Common Mistakes

  • Using mean signed residual as evidence of accurate predictions.
  • Deleting the point that changes the slope without investigating its provenance.
  • Treating a normal residual histogram as proof of independence.
  • Applying a variance fix to a curved mean relationship and claiming both issues are solved.

Read next

Continue the workflow: Poisson count models: use exposure offsets and test dispersion.

Continue the workflow: Regression uncertainty: inspect changing residual spread and high influence.

ai-data
applied-statistics
Storage details