Skip to content
svgimpulse-response

Impulse responses

When one series gets a one-off shock, how do the others respond over the following periods?

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

How to read it

  1. Read each panel as one series' response to a one-off shock in another.
  2. Follow the path from period zero: how large, how long, which sign.
  3. Check the band: a path inside a band around zero is compatible with no response.

Watch out

  • Orthogonalized shocks depend on the order of the series, and these are model responses rather than proven causal effects.

Defaults

Rows
All, or the target above 4 series
Which responses and shocks to show.
Also: All series · Target series only

Pinned in the code

  • Orthogonalized responses Θ_i = Φ_i P with P the lower Cholesky factor of the residual covariance: the first listed series can move the others at once, the last only itself. Reordering changes the picture.
  • Bands are percentile intervals from a residual bootstrap with the lag order and rank held fixed.
  • Each row shares a y-axis so shocks can be compared for the same response; a response whose band excludes zero differs from no response at that step.

Use with care

These trace how the fitted system moves, under one assumed ordering. They support a causal reading only if that ordering reflects how the shocks really occur.

# Impulse responses — Codesplash Chart Lab (recipe "impulse-response")
# controls: scope=auto
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("impulse-response-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["responding series"] = pd.Categorical(df["responding series"].astype("string"), categories=["sales", "ad spend", "price"])
df["shock"] = pd.Categorical(df["shock"].astype("string"), categories=["sales", "ad spend", "price"])

_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")
H = "steps"
V = "response"
R = "responding series"
S = "shock"
LO = "low"
HI = "high"
responses = df[R].astype("category").cat.categories if not hasattr(df[R], "cat") else df[R].cat.categories
shocks = df[S].astype("category").cat.categories if not hasattr(df[S], "cat") else df[S].cat.categories
fig, axes = plt.subplots(len(responses), len(shocks), figsize=(8, 6), sharex=True, sharey="row", squeeze=False)
for i, r in enumerate(responses):
    for j, s in enumerate(shocks):
        ax = axes[i][j]
        d = df[(df[R] == r) & (df[S] == s)].sort_values(H)
        if LO and HI:
            ax.fill_between(d[H], d[LO], d[HI], color=PALETTE[0], alpha=0.2, linewidth=0)
        ax.axhline(0, color=REF, linewidth=0.8)
        ax.plot(d[H], d[V], color=PALETTE[0], linewidth=1.5)
        if i == 0:
            ax.set_title(f"Shock: {s}", fontsize=9)
        if j == 0:
            ax.set_ylabel(str(r), fontsize=9)
fig.supxlabel("steps after the shock", fontsize=9)
plt.show()

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