Smoothed dose-response curve#
What this solves#
For a continuous treatment \(A\), the dose-response curve \(\theta(a) = E\{\bar Q(a, W)\}\), with
\(\bar Q(a, W) = E(Y \mid A = a, W)\), is not pathwise differentiable at a fixed dose in a
nonparametric model, so no root-\(n\) interval exists for it. DoseResponseTMLE estimates its
kernel-smoothed version at declared bandwidths and doses, which is pathwise differentiable. It
reports a Wald interval per declared pair and one simultaneous band over every declared pair. The
band also covers the smoothed curve at a bandwidth chosen after the fit, provided the choice is one
of the declared bandwidths.
claim |
status |
|---|---|
point estimate and interval for \(\theta_h(a_0)\) at a declared \((h, a_0)\) |
ships |
a simultaneous band over every declared dose and bandwidth |
ships |
the band read at a bandwidth chosen after seeing the data |
ships, through the band only. A pointwise interval at a chosen bandwidth is not adjusted for the choice |
a bandwidth selector |
not shipped. The band makes the comparison across declared bandwidths |
an interval for the unsmoothed curve \(\theta(a_0)\), or a band over every dose in an interval |
refused, F39 |
import numpy as np
import pandas as pd
from sklearn.ensemble import HistGradientBoostingClassifier
from sklearn.linear_model import LogisticRegression
from cleverly.dose_response import DoseResponse
from cleverly.estimators import DoseResponseTMLE
rng = np.random.default_rng(0)
n = 800
w = rng.normal(size=n)
a = np.clip(2.5 + 0.8 * w + rng.normal(size=n), -1.0, 6.0)
y = rng.binomial(1, 1 / (1 + np.exp(-(0.6 * np.sin(a) + 0.5 * w))))
frame = pd.DataFrame({"W": w, "A": a, "Y": y})
curve = DoseResponse(doses=[1.0, 2.5, 4.0], bandwidths=[0.8, 1.2], support=(0.5, 4.5))
estimator = DoseResponseTMLE(
curve,
outcome_learner=HistGradientBoostingClassifier(max_depth=2, max_iter=50),
treatment_learner=LogisticRegression(),
density_bins=10,
random_state=0,
)
result = estimator.fit(frame, outcome="Y", treatment="A", covariates=["W"])
print(result.to_frame()[["bandwidth", "dose", "estimate", "band_lower", "band_upper"]])
cleverly.plotting.curve(result) draws one series per bandwidth, with the band. The
dose-response tutorial walks through one analysis.
Estimand#
The user declares, without reading the data, a dose interval \(D = [a_\mathrm{lo}, a_\mathrm{hi}]\),
evaluation doses \(a_{0,1} < \dots < a_{0,J}\) in \(D\), distinct bandwidths \(h_1 < \dots < h_L\), and a
kernel \(K\) ("epanechnikov", the default, "triweight" or "uniform"). For each pair \((h, a_0)\)
the weight is the local-linear equivalent kernel under Lebesgue measure on \(D\),
with \(K_h(u) = K(u/h)/h\), and the target is
property |
consequence |
|---|---|
\(w\) depends on \((K, h, a_0, D)\) only |
\(\theta_h\) is a known linear functional of \(\theta\) |
\(\int_D w = 1\) and \(\int_D w(a)(a - a_0)\,da = 0\) |
\(\theta_h(a_0) = \theta(a_0)\) wherever \(\theta\) is linear on the support of \(w\), at interior and boundary doses |
interior pair, symmetric \(K\): \(w = K_h(\cdot - a_0) \ge 0\) |
the target is the kernel average of Bibaut and van der Laan (2017), Section 1.3. Under |
boundary pair: \(w\) is signed |
for Epanechnikov at \(a_0 = a_\mathrm{lo}\), \(\min w \approx -0.92/h\), \(\int \lvert w \rvert \approx 1.57\) and \(\int w^2\) is about 7.5 times its interior value. The estimate can leave the outcome’s range, and its variance is larger |
\(\theta \in C^2\) near \(a_0\) |
\(\lvert \theta_h(a_0) - \theta(a_0) \rvert \le \tfrac12 \sup \lvert\theta''\rvert\, h^2 \int \lvert w \rvert\), so the smoothing bias is \(O(h^2)\) uniformly over \(D\) |
\(\theta_h(a_0)\) is also the intercept of the least-squares projection of \(\theta\) onto the working model \(\beta_0 + \beta_1 (a - a_0)/h\) with the known weight \(K_h(a - a_0) 1\{a \in D\}\). That is the projection parameter of Neugebauer and van der Laan (2003), Section 2.1, Equation (1), with the sum over regimes replaced by an integral over doses, as the shipped continuous MSM does. Lebesgue measure keeps the weight known. Kennedy, Ma, McHugh and Small (2017) weight by the marginal dose density instead, which is a functional of \(P\) with its own influence-function term.
\(D\) is part of the estimand. DoseResponse never reads \(A\), and an interval set from sample
quantiles of \(A\) moves the target at boundary pairs by \(O_P(n^{-1/2})\), a term the reported
interval omits. Identification needs consistency, conditional exchangeability, and positivity:
\(g_0(a \mid W) \ge c > 0\) for every \(a\) in the union of the declared weights’ supports, almost
surely.
Influence function and remainder#
The efficient influence function of \(\theta_h(a_0)\) in the nonparametric model is
Bibaut and van der Laan (2017), Section 1.3, page 5, give this form under a known \(g\). Their PDF prints \(\bar Q(a, W)\) in the first term, a typo for \(\bar Q(A, W)\). The step to an estimated \(g\) is this project’s derivation: \(\theta_h\) depends on \(P\) only through \((P_W, \bar Q)\), so its pathwise derivative along every score of \(g(\cdot \mid W)\) is zero, and \(D\) is then the gradient in the full nonparametric model, where the gradient is unique, provided \(w/g_0 \in L_2(P_0)\). Bibaut and van der Laan state \(\operatorname{Var} D \sim C h^{-1}\), so a pair’s standard error is about \((nh)^{-1/2}\).
The exact remainder is
It needs \(g > 0\) where \(w \ne 0\). No regression or mechanism is fitted on an estimated index, so the linear-remainder audit does not apply. The interval needs both nuisances consistent, in two forms.
Asymptotically, at a fixed \(h\), the product of the \(L_2\) errors of \(\hat g\) and \(\hat{\bar Q}\) over the kernel’s support is \(o_P(n^{-1/2})\), and \(1/\hat g\) is bounded there.
In a finite sample, the remainder is small next to the pair’s own standard error, about \((nh)^{-1/2}\). A narrower bandwidth asks for better nuisances.
With one nuisance inconsistent the remainder is first order. The estimate stays consistent, and the interval is not claimed.
The estimator#
The route is the generic CV-TMLE theorem of Zheng and van der Laan (2011), Theorems 1 and 2, whose inputs are the canonical gradient and the second-order remainder above.
Cross-fit \(\bar Q\) and \(g\) over
n_foldsfolds. \(g\) is the package’s pooled-hazard binned conditional density withdensity_binsbins. \(\bar Q\) is any outcome learner, with the dose as a feature.Build one quadrature rule shared by every pair: a composite Gauss-Legendre rule with
nodes_per_piecenodes on each piece of the partition of \(D\) at the density’s bin edges, every \(a_0 \pm h\) inside \(D\), and \(D\)’s endpoints. The weight is a polynomial on each piece and \(1/\hat g\) is constant there, so only \(\bar Q\) and the logistic map add integration error.For each pair, fit one pooled one-dimensional fluctuation over all rows, with the out-of-fold clever covariate \(H(A, W) = w_{h,a_0}(A)/\hat g(A \mid W)\): \(\operatorname{logit} \bar Q^*(a, W) = \operatorname{logit} \bar Q(a, W) + \varepsilon H(a, W)\) on the scaled outcome (
fluctuation="logistic", the default), or \(\bar Q^* = \bar Q + \varepsilon H\) (fluctuation="linear"). No fluctuation is shared between pairs.Report \(\hat\theta_h(a_0) = n^{-1}\sum_i \int_D w_{h,a_0}(a)\,\bar Q^*(a, W_i)\,da\) by the rule of step 2. The submodel is one function of \((a, W)\) read at the nodes, so the score equation \(P_n D(\hat P^*) = 0\) holds once the fluctuation is solved.
result.scoresrecords each pair’s score at its solution.Form each pair’s Wald interval from its cross-fitted influence curve, and the band from the stacked curves by the studentized max-\(t\) multiplier bootstrap (
simultaneous_bands).
The fit repeats steps 4 and 5 with twice the nodes and records the largest change relative to a
pair’s standard error as result.quadrature_shift. It adds a note to result.warnings when that
exceeds 0.05, and warns with DataWarning. A tree-based \(\bar Q\) puts its own jumps inside pieces, where the rule converges more
slowly.
The fit refuses before any learner runs when \(D\) leaves the observed dose range, since the binned
density is zero outside it, and when the nodes would need more than 4 GB. It refuses after the
nuisance fit, naming the pair, when the fitted density is zero where a weight is nonzero, and when
a pair’s fluctuation does not solve its score. Both raise DataError. Declare
\(D\) with a margin inside the expected dose range, and choose it without reading the sample: an
endpoint set from the sample changes the target.
Support#
result.pair_support holds one entry per reported estimate, and result.to_frame() repeats its main
columns.
field |
meaning |
|---|---|
|
rows whose observed dose gets a nonzero weight |
|
the Kish effective size of the clever covariate, \((\sum_i \lvert H_i \rvert)^2 / \sum_i H_i^2\), without observation weights |
|
the smallest fitted density over the loaded observed doses and the pair’s nodes |
|
the largest \(\lvert H_i \rvert\) |
|
whether |
A pair below the floor keeps its interval and its place in the band, and its estimate carries the
inference status low_dose_support_plugin, and the fit warns with DataWarning. The label says
that the normal approximation behind the interval rests on few effective rows. The default floor
is provisional, and the label is not a validated screen.
In the
dose-response pilot the Kish size did not separate the
intervals that under-cover: an unlabelled stratified pair with a mean Kish size of 69 covered
0.908 at n = 4,000, and at the tail pair a larger Kish size came with a smaller reported SE and no
smaller error. The registered run repeats both readings. The stratified pair at n = 8,000 (mean
Kish size 141, all but 2 of 4,000 fits unlabelled) covered 0.921 with an SE ratio of 0.93. At the
tail pair the unlabelled fits covered 0.929 and the labelled ones 0.944. The tail scenario
measures one pair near the floor, so its passing verdict does not validate the floor at other
doses, bandwidths or laws.
X95 records what would remove
the label.
Compositions#
composition |
status |
|---|---|
cross-fitted fit, with or without baseline strata |
accepted. A continuous \(Y\) needs |
in-sample fit ( |
accepted, with an |
clustered rows ( |
refused, |
a dose with fewer than 20 distinct values |
refused, |
|
not offered. Each pair takes its own one-dimensional fluctuation |
baseline strata |
each stratum \(v\) gets its own curve, \(E\{\int_D w(a) \bar Q(a, W)\,da \mid V = v\}\), from one nuisance fit, named with a |
a binary, categorical or vector treatment |
refused, |
missing outcome, missing treatment, intermediate variable |
refused, |
a treatment with declared dose atoms, or a declared known treatment mechanism |
refused, |
|
not wired. Fit |
Support label#
Each pair’s estimate carries support.label, and the band carries result.band.support. The
label reads supported when the registered study measured the
fit’s configuration, which
cleverly.estimators.dose_response.DOSE_RESPONSE_MEASURED lists. Every measured configuration is
cross-fitted, on iid unweighted rows with complete outcomes.
outcome |
fluctuation |
strata |
pointwise intervals |
band |
study scenario |
|---|---|---|---|---|---|
binary |
|
none |
|
|
|
binary |
|
baseline strata |
|
|
|
continuous, with |
|
none |
|
|
|
any other combination |
|
|
none |
The band reads supported only where the study’s band cell measured it, on the 15 pairs of the
binary declaration, with at least 10,000 Mammen draws. The pairs’ estimates carry no range, so the
band stays on the identity scale and a limit can leave [0, 1]. A pair below the support floor reads experimental with
X95 as its evidence, and a
band over such a pair reads experimental too. The label does not read the learners, the sample
size, the number or spacing of the pairs, or the law. The study measured declared sieve learners,
one law family and sizes from 1,000 to 8,000, and each label’s limits repeat that.
Assessing the curve#
result.diagnostics declares the dose_response assessment family, and result.validate() and
result.assess() read its rows. Every supported row restates numbers the fit stores. No row
refits, so a saved fit answers them too.
support()returns aDoseResponseSupportReport: thepair_supportrecords, the floor, the number of pairs below it and the quadrature shift. Its row readscompleted, orwarningwhen some pair is below the floor, naming the pairs that carry the experimentallow_dose_support_plugininterval. It never readspassed, because the floor is provisional (X95).score_equations()returns aDoseResponseScoreReport: each pair’s mean fluctuation score at its solution, on the scaled outcome, against the package’s score threshold, read with each pair’s plug-in standard error divided by the outcome scaler’s range. The fit already refuses a pair whose fluctuation does not solve its score to within about \(10^{-6}\,\widehat{sd}/\sqrt{n}\), while the package threshold is about \(10^{-3}\,\widehat{sd}/n\). Below about a million rows the solver’s bound is the tighter one (by a factor of about 40 at n = 600 and 10 at n = 8,000), so on such a fit this row restates convergence; near a million rows and above it can fail.nuisance_models()reports the outcome regression at the observed dose, from a record of \(n\) floats the fit keeps. It is out of fold on a cross-fitted fit and in sample withcross_fit=False, and its evaluation label says which.influence()reports each pair’s influence curve, as on a point fit.
corrections and truncation_curve do not apply: each pair is targeted by its own
one-dimensional fluctuation, and no bound enters the clever covariate, which divides by the
fitted density without a floor. refute and the omitted-variable and marginal bounds are
implementation_gap refusals that name
X82 part K, and the
simulated common cause names
X66 part (l). The E-value does not
apply, because a pair is a mean at one dose and not a contrast. The missingness tilt and its
tipping point do not apply, because the fit takes no missing outcome. replayability reads
summaries only: the result keeps no estimator or data. tests/unit/test_dose_response_assessment.py
checks each row, the score scale and the out-of-fold source of the outcome record.
Validation#
check |
test |
|---|---|
the pathwise derivative along outcome and covariate scores equals \(E[D s]\) on an exact law with three covariate levels and a piecewise-linear dose density, at interior and boundary pairs |
|
the derivative along a score of the dose law is zero, and so is its inner product with \(D\). This is a structural identity: it holds for any \(D\) of the form \(f(A, W)\{Y - \bar Q_0\} + c(W)\), so it cannot fail for a wrong clever covariate, which the rows above and below catch |
|
deliberate mutations (drop \(1/g\), read \(g\) at \(a_0\), omit the integral term) each fail a derivative check |
|
the exact remainder equals the product form, is nonzero with both nuisances wrong, and vanishes with either one right |
|
the equivalent kernel’s moments and sign, interior and boundary |
|
the composite rule is exact on a piecewise polynomial and fails without its breaks |
|
the estimator’s own targeting ( |
|
dropping \(1/g\), leaving the plug-in untargeted, or reading the regression at the wrong node each miss the truth at every pair |
|
every pair solves its score, including a 200-pair declaration; round trip; strata; support report; refusals before any learner fits |
the fit tests in the same file |
a pair whose fluctuation does not solve its score raises |
|
The registered study passes every gate: 27 primary rows
(lowest coverage 0.9215, worst standardized bias 0.031) and 7 property cells, including the band’s
joint coverage, exact-efficiency calibration and the targeting gain. It has no comparator.
A separate study pairs DoseResponseTMLE with
npcausal ctseff on a law where the curve is a line, so both smoothed curves equal it. That study
is declared, and its runs are pending a local R run.