mixdyn.inference.sensitivity¶
How far a channel's return moves under a confounder the model does not see (ADR 0061).
Both forms bound; neither corrects. Each reads one number, the strength a confounder would need to move the return, and reports what the return is at a strength the reader states.
The ridge engine (ridge_sensitivity): Cinelli and Hazlett (2020, JRSS-B 82(1)) on the least
squares of the fit's KPI on its design, the ridge's own columns at penalty 0, each channel's
saturated under its adstock and Hill. With t the channel's t-statistic and df the regression's
residual degrees of freedom, f = |t| / sqrt(df) is its partial Cohen's f and
R2(Y ~ D | X) = t^2 / (t^2 + df),
RV_q = (sqrt(f_q^4 + 4 f_q^2) - f_q^2) / 2, f_q = q f,
the share of both the channel's and the KPI's residual variance a confounder must explain to move
the coefficient by q of itself. RV_{q, alpha} moves the interval's near end there instead:
with f* = t_{df - 1, 1 - alpha / 2} / sqrt(df - 1) it is 0 where f_q <= f*, the root above at
f_q - f* where f* < f_q < 1 / f*, and (f_q^2 - f*^2) / (1 + f_q^2) past it, where the KPI's
share that moves the interval most is below the treatment's. A confounder that explains R2yu
of the KPI's residual variance given the channel and the design, and R2du of the channel's given
the design, moves the coefficient by at most
|bias| = se sqrt(df) sqrt(R2yu R2du / (1 - R2du)),
and the adjusted standard error is se sqrt((1 - R2yu) / (1 - R2du)) sqrt(df / (df - 1)). A
confounder k_d times as strong as an observed control on the channel and k_y times on the
KPI, and independent of it given the rest, has R2du = k_d R2(D ~ X_j | X_-j) / (1 - R2(D ~ X_j |
X_-j)) and the bound on R2yu of their Section 6.1. validation/sensitivity.mac checks each
closed form.
The return on the window's spend is the coefficient times the channel's saturated spend over the
window over that spend, so a share q of the coefficient is a share q of the return. The
statistics are the unpenalised regression's: the ridge's coefficient is shrunk from it, and a
geo test's anchor pulls it, and neither has a t-statistic of its own. RidgeSensitivity keeps the
fit's coefficient beside the regression's estimate.
The Bayesian engines (msm_sensitivity): a marginal sensitivity model of level Gamma on the
channel's spend given a hidden confounder (Tan 2006; the continuous form of Jesson et al. 2022).
Its density ratio's lower side, 1 / Gamma, holds the share of the channel's residual variance
the confounder explains to at most (1 - 1/Gamma)^2, a sharp share (Dorn and Guo 2023 for the
binary model's sharpness; chc.ChannelSensitivity since 0.22.0). Nothing bounds the KPI's side,
so R2yu is 1, and at each draw s of the posterior the coefficient moves by at most
kappa(Gamma) sigma_s / sd_s(D | X), kappa(Gamma) = (Gamma - 1) / sqrt(2 Gamma - 1),
kappa chc.ChannelSensitivity.factor, sigma_s the root mean square of the KPI less the draw's
mean over the fitted periods, and sd_s(D | X) that of the draw's saturated spend of the channel
less its least squares on the draw's other channels, the controls, the trend, the season and the
intercept. The return moves by the same share of itself. The bound at Gamma is the interval from
the (1 - level) / 2 quantile of the draws' return less their allowance to the (1 + level) / 2
quantile of the return plus it; Gamma* is the least Gamma at which that interval's lower end
reaches 0, found by bisection on kappa, along which it falls, and read back by
chc.ChannelSensitivity.level_at.
BiasBound(r2_outcome, r2_treatment, bias, estimate, se, lower, upper, label='')
dataclass
¶
A confounder's reach on a coefficient: it explains r2_outcome of the KPI's residual
variance given the channel and the design, and r2_treatment of the channel's given the
design. bias is the most it moves the estimate, estimate the estimate moved by it toward
0, se the adjusted standard error, and lower and upper the adjusted interval at the
sensitivity's level. label names a benchmark's control and its multiple, if it is one.
Benchmark(control, r2_treatment, r2_outcome)
dataclass
¶
RidgeSensitivity(channel, coefficient, estimate, se, dof, level, partial_r2, robustness, robustness_half, robustness_interval, robustness_interval_half, benchmarks)
dataclass
¶
A ridge fit's channel under Cinelli and Hazlett's sensitivity analysis.
coefficient is the ridge fit's; estimate, se and dof the least squares' on the same
design, which the rest reads. partial_r2 is R2(Y ~ D | X); robustness is RV_1, the
shares that bring the estimate to 0, and robustness_half RV_{1/2}, those that halve it;
robustness_interval and robustness_interval_half are RV_{1, alpha} and
RV_{1/2, alpha}, alpha = 1 - level. benchmarks holds each control's partial R^2.
channel
instance-attribute
¶
coefficient
instance-attribute
¶
estimate
instance-attribute
¶
se
instance-attribute
¶
dof
instance-attribute
¶
level
instance-attribute
¶
partial_r2
instance-attribute
¶
robustness
instance-attribute
¶
robustness_half
instance-attribute
¶
robustness_interval
instance-attribute
¶
robustness_interval_half
instance-attribute
¶
benchmarks
instance-attribute
¶
bound(r2_outcome, r2_treatment, label='')
¶
The estimate and its interval under a confounder that explains r2_outcome of the
KPI's residual variance and r2_treatment of the channel's.
Raises:
| Type | Description |
|---|---|
ValueError
|
on an |
benchmark(control, kd=1.0, ky=None)
¶
The bound under a confounder kd times as strong as control on the channel and ky
times on the KPI, kd by default, and independent of it given the rest of the design;
its shares are Cinelli and Hazlett's (2020, Section 6.1), the KPI's held to 1.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a control the fit does not have, a multiple not positive, or one so large the channel would be the confounder's alone. |
MsmSensitivity(channel, level, roi, gammas, lower, upper, allowance, scale, gamma_star)
dataclass
¶
A Bayesian fit's channel under the marginal sensitivity model.
roi is the posterior median of the channel's return on the window's spend, lower and
upper its interval at level at each of gammas, the confounder's allowance included, and
allowance the posterior median of how far the confounder can move the return at each.
scale is each draw's allowance per unit of kappa, sigma_s / sd_s(D | X) times the
draw's return over its coefficient. gamma_star is the least Gamma at which lower reaches
0: 1 where the interval holds 0 without a confounder.
robustness_value(t, df, q=1.0, alpha=None)
¶
Cinelli and Hazlett's RV_q of a coefficient of t-statistic t on df residual degrees of
freedom, or RV_{q, alpha} where alpha is given: the share of both residual variances a
confounder must explain to move the estimate, or its 1 - alpha interval's near end, by q
of the estimate.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a |
ridge_sensitivity(fit, channel, level=0.9)
¶
Cinelli and Hazlett's sensitivity of channel's coefficient in fit, its intervals at
level, read on the least squares of the fitted periods' KPI on the fit's design; a column
that does not vary over them is left out with the intercept.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a channel the fit does not have, a level outside (0, 1), a design not of full rank or fewer than two degrees of freedom left. |
msm_sensitivity(posterior, channel, gammas=(1.0, 1.1, 1.5, 2.0, 3.0), level=0.9)
¶
The marginal sensitivity model's bounds on channel's return in posterior at each of
gammas, its intervals at level, and Gamma*.
Raises:
| Type | Description |
|---|---|
ValueError
|
on a channel the fit does not have, a |