Skip to content
svgrecursive-coef

Recursive coefficient estimates

Does a regression coefficient settle down as data accumulate, or drift — a sign the relationship is changing?

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

How to read it

  1. Read the line as the coefficient re-estimated as more rows arrive.
  2. The band shows how uncertain it is at each size: wide early, narrower later.
  3. A steady drift away from the dashed line suggests the relationship is changing.
  1. Callout 1: Early estimates: unstable and uncertain.
  2. Callout 2: The final estimate on all rows.
  3. Callout 3: Dashed line: the full-sample value.

Watch out

  • Row order matters: this only speaks to time-related change when rows are in time order.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Each point is the OLS estimate from rows 1…r in time order; SE = √(σ̂²_r [(X'X)⁻¹_r]_jj) with σ̂²_r = RSS_r / (r − k).
  • Early estimates are noisy by construction; read the shape after the band narrows.
# Recursive coefficient estimates — Codesplash Chart Lab (recipe "recursive-coef")
# controls: defaults
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

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("recursive-coef-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")
def ordered(d, x, cols):
    """Rows with the needed values, sorted by the time column (stable); row order when there is none."""
    d = d.dropna(subset=[c for c in cols if c] + ([x] if x else []))
    return d.sort_values(x, kind="stable") if x else d

def time_of(d, x):
    return d[x] if x else pd.Series(np.arange(1, len(d) + 1), index=d.index)
X = "row"
Y = "slope"
LO = "lower"
HI = "upper"
d = ordered(df, X, [Y])
t = time_of(d, X)
fig, ax = plt.subplots(figsize=(8, 4))
if LO and HI:
    ok = d[LO].notna() & d[HI].notna()
    ax.fill_between(t[ok], d.loc[ok, LO], d.loc[ok, HI], color=PALETTE[0], alpha=0.16, lw=0, label="± 1.96 SE")
ax.axhline(d[Y].iloc[-1], color=REF, linestyle="--", linewidth=1, label="full-sample estimate")
ax.plot(t, d[Y], color=PALETTE[0], linewidth=1.8, label="estimate on the first r rows")
ax.set_xlabel("row")
ax.set_ylabel(Y)
ax.legend(frameon=False)
plt.show()

Needs pandas, numpy, matplotlib · reads recursive-coef-demo.csv · app theme from the optional codesplash helper