Skip to content

chc.irf

Stability tier: evolving.

Dynamic causal effects: the impulse-response / carryover kernel for control.

CHC's one-step estimate_control_effect gives the scalar d x_next/d u; a controller planning over a horizon needs the whole d x_{t+h}/d u_t, h = 0..H -- how an intervention propagates over time (the impulse response, or an MMM adstock carryover kernel). This is Jorda local projections: one regression per horizon of the h-step-ahead outcome on the treatment plus an adjustment set, so conditioning on the state/confounders blocks the backdoor path exactly as the one-step estimate does. The dynamic sibling of chc.causal.estimate_control_effect. This is a causal-effect estimator, not a sequence model.

DelayEstimate dataclass

How long a causal effect takes to arrive, with an interval rather than a bare point.

lag is in steps, and delay, lo and hi in the caller's time unit (lag * dt). peak_response keeps its sign, so an effect that arrives negative is visible as such even though the peak is located on |beta|.

lo and hi bound the delay: the bootstrap interval of the whole step the response peaks at, widened by half a step on each side and cut at zero. A delay between two samples peaks at the nearer one, up to half a step from it, and every resample peaks there too, so the bootstrap alone carries the peak's spread and not that distance. The half step holds under the premise delay_estimate states. lag and delay, refined or not, lie within half a step of the whole step the full sample peaks at.

censored marks a peak sitting on an end of the horizon, where the delay is not identified: the true peak may lie anywhere beyond the window, so the number is a bound on the delay and must not be read as an estimate of it.

local_projection_irf(data, horizon, treatment='u', outcome='x', adjust_for=('x',), lags=0)

Jorda local-projections IRF beta_h = d outcome_{t+h}/d treatment_t, h = 0..horizon.

data holds aligned trajectory columns. For each h the h-step-ahead outcome is regressed on [treatment_t, *adjust_for_t] and an intercept; the treatment coefficient is the horizon-h dynamic causal effect. With adjust_for the backdoor path is blocked (effect identified); omit the confounder and it stays confounded. Returns the length H + 1 IRF.

lags > 0 adds lags own-lags of the outcome and of the treatment to every projection -- lag augmentation (Montiel Olea & Plagborg-Moller 2021). It buys inference: without it, a coefficient's confidence interval loses coverage on persistent data and at long horizons, and a plant with a delay is persistent by construction.

The premise: adjust_for and the lags hold every parent of treatment_t that also reaches the outcome. A persistent treatment's own past is one on a plant with dead time or carryover: u_{t-1} is still in the pipeline the outcome has not seen, and it moves with u_t. Without its lag the projection reads that pipeline as the effect, and the lags change the estimand, not just its interval. On x_{t+1} = 0.5 x_t + u_{t-4} + e with an AR(0.9) treatment, beta_1..beta_4 came back 0.27, 0.58, 0.92, 1.27 where the effect is 0, and with lags=1 within 0.01 of 0. With the lags in, beta_h is the total effect of setting u_t, which counts the treatment's own response to it, since u_{t+1} follows u_t: 1.0, 1.41, 1.51 at h = 5, 6, 7, where an impulse with the later treatment held is 1.0, 0.5, 0.25. So on a persistent treatment pass lags of at least its autoregressive order. The default stays 0 so existing callers get the estimates they had, and a warning is logged (chc_event="persistent_treatment") where the treatment's residual on the projection's controls is autocorrelated, a Ljung-Box test at level 0.001 over lags 1..horizon: on that plant with lags=0 it fires, with lags=1 it does not.

Raises:

Type Description
ValueError

on negative lags, a series too short for the horizon, or a treatment that adjust_for names too. The outcome may be adjusted for, as by default: its level at t is a control for its level at t + h.

peak_lag(irf, refine=False)

Location of the IRF's largest-magnitude response, and whether it is censored.

Returns (lag, censored). Magnitude, not signed value, because a dynamic effect that overshoots and returns changes sign; the arrival time is where the response is largest, whichever way it points.

refine fits a parabola through the peak and its two neighbours and returns the vertex, so the answer is not quantised to the sampling step. It is off by default because a causal impulse response is one-sided -- zero before the effect arrives, decaying after -- and so is maximally asymmetric at exactly the point being located. On a geometrically decaying response with ratio phi the vertex lands at lag + phi/(2 * (2 - phi)): 0.41 of a step late at phi = 0.9, a bias that does not shrink with the sample and swamps the bootstrap width. Turn it on when the response is genuinely smooth across the grid -- a delay that is not an integer multiple of dt smears across neighbouring bins, and then the integer argmax can only quantise. Even there the vertex is exact only for a symmetric peak: a lag split (1 - f, f) across two bins puts it at f/(4 - 6f), so f = 1/2 comes back exactly and f = 1/3 comes back as 1/6. It moves the right way and continuously; it is not unbiased.

A peak at either end of the horizon is returned unrefined and flagged censored: there is no neighbour to fit through, and the response is still rising at the edge, so the true peak may lie outside the window. censored is not a test for an identified peak -- an effect that never arrives within the horizon leaves noise, whose argmax sits wherever noise puts it. What flags that case is the width of the interval delay_estimate returns, not this flag.

The fit is local to three points, so a plateau wider than that is read from its leading edge: two tied bins give the midpoint (the wanted answer for a delay halfway between samples), three give the midpoint of the first two. Every closed form here is derived in validation/delay_estimate_bias.mac.

delay_estimate(data, horizon, dt=1.0, treatment='u', outcome='x', adjust_for=('x',), lags=0, refine=False, n_resamples=400, level=0.95, seed=0)

Estimate how long a causal effect takes to propagate, with a bootstrap interval.

This is the delay half of a delay causal graph: an edge already carries a lag from chc.discovery.LaggedGraph, but a lag with no uncertainty is a claim nobody can check.

The estimand is the transport lag of the treatment-to-outcome path -- how long an intervention takes to show its largest effect -- read off local_projection_irf with adjust_for blocking the backdoor path, so it is the delay of the causal effect and not of a correlation. That is the tau of a plant whose delay sits on the actuation path; chc.delay.DelayedDynamics carries its delay on the state-feedback path instead, so its tau is a different quantity and this estimate does not identify it.

The peak is the transport lag only under local_projection_irf's premise, and only for a treatment that does not persist. A persistent treatment needs its own lag (lags), or the response before the dead time reads its pipeline; and even with it, the total effect of setting it keeps rising past the dead time as the treatment follows itself: an AR(0.9) treatment into a dead time of 5 steps read its largest mean response at 6 steps without lags and at 7 with lags=1, where the total effect peaks.

On a treatment that does not persist, set lags > 0 if you intend to read coefficients off irf; it does not change this interval. Lag augmentation fixes the asymptotic variance of a single local-projection coefficient under persistence (Montiel Olea & Plagborg-Moller 2021), and a delayed plant is persistent by construction -- but the peak is a location statistic, invariant to a common rescaling of the IRF, and the block bootstrap below already handles the serial dependence non-parametrically. Measured over 40 replications at phi in {0.98, 0.999, 1.0}, coverage of the peak's nominal 95% interval, before the half steps below were added to it, was 0.95-1.00 with and without augmentation and the widths agreed to 3%. So the default matches local_projection_irf, and the option is offered rather than imposed.

The interval is a moving-block percentile bootstrap over the aligned projection rows, refit and re-peaked on every resample, with block length lags + horizon + 1. Blocks, because a local projection's rows overlap by construction -- rows closer together than the window share observations -- so resampling rows independently would destroy the dependence that sets the width and report an interval far too narrow. That window length is also exactly the separation at which two rows stop sharing anything, which is what makes it the natural block.

A flat or noise-dominated IRF is not rejected and not smoothed over: the peak wanders across the horizon under resampling and the interval comes back wide, which is the honest report. A sharply identified lag goes the other way: the resampled peak never leaves its step, and the interval is that step and half a step on each side, which holds one whole number of steps.

The half step is what makes the interval bound the delay, not only the peak. The interval's ends are the percentiles of the resampled peaks' whole steps, each a step some resample peaked at, widened by half a step on each side and cut at zero, since no causal effect arrives before its cause. The premise: the delay lies within half a step of the step the response peaks at. It holds for a delay of whole steps, and for a transport lag of c steps seen through an input held over each step and an outcome read as its change over the step: the samples of the response are then the hat 1 - |h - c|, whose largest sample is at c rounded, up to half a step from it (validation/delay_interval_resolution.mac). The same two samples are also the response of a plant whose effect arrives split between two whole steps, largest at the step of the larger share, so the data cannot place the delay closer than the half step without a premise about the response's shape inside a step. An outcome read at instants under a held input peaks up to a whole step late, and the half step does not cover that.

On chc.research.benchmark.DelayOscillationTask's log, a delay of 3.33 steps that peaks at step 3, the interval without the half step held the delay on 0 of 400 seeds, with refine and without; with it, on 400 of 400, and on 400 of 400 at a delay of 6.67 steps, which peaks at step 7.

refine moves lag and delay off the whole step through peak_lag; read its warning before turning it on. The interval reads the whole step either way: the refined peak is off the delay by up to a sixth of a step on the hat and by up to half a step on a one-sided response, and on that log the sixth is more than its spread: an interval of the refined peak held the delay on none of those seeds either.

Whether a fitted model's plant reads its lever late at all is chc.dynamics_id.lag_check's question: the fit's residual against its earlier levers.

innovations(series, order)

Prewhitened residual: fit an AR(order) via Levinson, return series - AR-prediction.

The Box-Jenkins innovation -- the unpredictable part left after the autoregressive structure is removed. Prewhitening both series before cross-correlating de-biases it under autocorrelation -- a classical complement to the MCI test in chc.independence.

structured_irf(data, horizon, order=4, treatment='u', outcome='x', adjust_for=('x',))

Structured IRF: AR dynamics from Levinson + the one-step impact, propagated (transfer fn).

Fits the outcome's AR(order) via Levinson on the biased (PSD) autocorrelation -- the dynamic propagation -- and the one-step treatment impact (confounding-adjusted h = 1 local projection), then propagates g_0 = 0, g_1 = impact, g_h = sum_i a_i g_{h-i}. Agrees with the local-projections IRF but makes the AR structure explicit (reflection coeffs).

irf_control_sequence(irf, target)

Feed-forward control to track a target output, by deconvolving the impulse response.

The output is the causal convolution of the control with the IRF (x = G u, G lower-tri Toeplitz of the response), so achieving a target trajectory x* is the deconvolution u = G^{-1} x* -- solved with the Toeplitz machinery. This makes the whole dynamic effect actionable: it accounts for carryover, where a one-step controller that inverts only g_1 over-actuates on a delayed plant (steady-state error sum_h g_h / g_1).