Skip to content
svgadded-variable

Added-variable plot

What does one predictor add once the others are accounted for, and which rows drive it?

Demo data · seed 20261101 · 180 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read one panel per term: what that predictor adds after the others have explained what they can.
  2. The line's slope is the term's coefficient in the full model.
  3. Look for labelled rows far along the x axis: they have the most pull on that slope.
  1. Callout 1: The line's slope equals this term's coefficient.
  2. Callout 2: A labelled row: a strong pull on the slope.
  3. Callout 3: One panel per term; a flat line means it adds little.

Watch out

  • A strong slope isn't causal, and one row can create or hide it: refit without the labelled rows to check.

Defaults

Label influential rows
On
Name the rows with the largest pull on each slope.

Pinned in the code

  • Each panel plots the residuals of y on the other predictors against the residuals of this predictor on the other predictors.
  • The fitted line has an intercept; by the Frisch–Waugh–Lovell theorem its slope equals the term's coefficient in the full model.
  • Influential rows are those with the largest |x·y| after centring.
# Added-variable plot — Codesplash Chart Lab (recipe "added-variable")
# controls: labels=true
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from statsmodels.nonparametric.smoothers_lowess import lowess

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("added-variable-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV

_tokens = cs.palette(dark=False) if cs else {}
SEQ = _tokens.get("sequential", ["#eff6fd", "#1a469d"])  # sequential ramp (low → high)
DIV = _tokens.get("diverging", ["#c13e2e", "#f3f5f8", "#0859ac"])  # negative, midpoint, positive
REF = _tokens.get("reference", "#4e5661")
GREY = _tokens.get("dim", "#ced1d6")
X = "predictor residual"
Y = "sales residual"
T = "term"
d = df.dropna(subset=[X, Y])
terms = list(dict.fromkeys(d[T].astype(str))) if T else ["all rows"]
fig, axes = plt.subplots(1, len(terms), figsize=(4.5 * len(terms), 4), squeeze=False)
for ax, t in zip(axes[0], terms):
    g = d[d[T].astype(str) == t] if T else d
    x, y = g[X].to_numpy(float), g[Y].to_numpy(float)
    b, a = np.polyfit(x, y, 1)  # the least-squares line
    ax.scatter(x, y, s=10, color=PALETTE[0], alpha=0.6)
    grid = np.array([x.min(), x.max()])
    ax.plot(grid, a + b * grid, color=REF, linewidth=1.6)

    ax.set_title(f"{t}  (slope {b:.3g})", fontsize=10)
    ax.set_xlabel("predictor | others")
    ax.set_ylabel("outcome | others")
plt.tight_layout()
plt.show()

Needs pandas, numpy, matplotlib, statsmodels · reads added-variable-demo.csv · app theme from the optional codesplash helper