Regression Plots

Regression EDA assumes the model y = f(x) + e with a continuous predictor x. These plots diagnose the fit quality and stability of a linear regression as a function of position in x.

Pass x as a continuous numeric array to EDAData.

Reference: NIST Handbook Chapter 4

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from drippy import EDAData
from drippy import (
    scatter_plot,
    six_plot,
    linear_correlation_plot,
    linear_intercept_plot,
    linear_slope_plot,
    linear_residual_sd_plot,
)

rng = np.random.default_rng(42)

# 50-point calibration curve
x = np.linspace(0, 10, 50)
y = 2.5 * x + 3.0 + rng.normal(scale=1.5, size=50)
data = EDAData(y=y, x=x)

Scatter Plot (NIST 1.3.3.26)

The starting point for any regression EDA: raw y vs x to confirm linearity and spot outliers before fitting.

fig, ax = scatter_plot(data)
plt.show()
../_images/a9d4a581a773169f04956b3b489c5f9904047ead0583aaf6bcd288e1417faa33.png

6-Plot (NIST 1.3.3.33)

Comprehensive regression diagnostic in a 2×3 grid:

  1. Scatter with fitted line

  2. Residuals vs x

  3. Lag plot of residuals

  4. Histogram of residuals

  5. Normal probability plot of residuals

  6. Run sequence of residuals

If residuals in panels 2–6 look like white noise, the linear model is adequate.

fig, axes = six_plot(data)
plt.show()
../_images/d110206533142e01e17f91b474d451cb458806d4f3a8309eeb4ccb504037fa48.png

Linear Correlation Plot (NIST 1.3.3.16)

Plots the Pearson correlation coefficient from a rolling window of observations. Stable, high correlation confirms that the linear model holds throughout the data range; dips indicate local non-linearity.

fig, ax = linear_correlation_plot(data)
plt.show()
../_images/8ce2d2ab1b7d0b38667005ffb3d369f155f2daeb70c9fc1099ec7e1e9139ac6c.png
fig, ax = linear_correlation_plot(data, window=20)
plt.show()
../_images/71f94522af7a1daa9dfa3c28598375d0796c4b7dcb389a0c418e8e588eb419d6.png

Linear Intercept Plot (NIST 1.3.3.19)

Rolling OLS intercept. Drift in the intercept over the data sequence may indicate calibration shift or a non-stationary baseline.

fig, ax = linear_intercept_plot(data)
plt.show()
../_images/0d9432ac06c1b5c3260a9565356ce19a56fdebb2433fad564c25a024722e778d.png

Linear Slope Plot (NIST 1.3.3.20)

Rolling OLS slope (sensitivity). A flat line confirms constant sensitivity; trends reveal systematic changes in the response.

fig, ax = linear_slope_plot(data)
plt.show()
../_images/d4a65ec85a773713dba38bb2cc78d36639fe0fc2e81a45c2f4f8f9ae48e56f0a.png

Linear Residual SD Plot (NIST 1.3.3.22)

Rolling residual standard deviation. Increasing SD indicates heteroscedasticity — variance that grows with x.

fig, ax = linear_residual_sd_plot(data)
plt.show()
../_images/f2a925e9d8a17f0c9661ca38761cbd9ef580d128df6f276478e023bfd386c957.png