cleverly.ConditionalContrast#
- class cleverly.ConditionalContrast(modifiers: Modifiers, scale: Literal['difference', 'log_ratio'] = 'difference', model: Any = None, treatment: Any = None, reference: Any = None)[source]#
Ask how the effect of the treatment changes with the modifiers
V.On the difference scale the question is the conditional average treatment effect (CATE), \(E[Y^t - Y^r \mid V]\). On the log-ratio scale it is the log conditional risk ratio, \(\log(E[Y^t \mid V] / E[Y^r \mid V])\). Every modifier must be an adjustment column.
With
model=the target is the projection of that contrast onto the declared basis \(\varphi(V)\): on the difference scale the best linear approximation \(\varphi(V)^\top\beta\) in mean square, and on the log-ratio scale the minimiser of the log-ratio risk over the same span.method="tmle"estimates \(\beta\) with Wald intervals, a joint covariance and a test of the non-constant terms. When the contrast is not in the span of the basis the coefficients describe the best approximation, not the contrast itself. Withmodel=Nonethe target is the conditional contrast as a function, which has no interval and no TMLE fit yet.- Parameters:
- modifiers
cleverly.bases.Modifiers The modifier columns, with each continuous modifier’s domain and each categorical one’s levels.
- scale{“difference”, “log_ratio”}
The scale of the contrast. The log ratio needs a binary outcome or a nonnegative one declared on
q_bounds=(0, upper).- model
basis,cleverly.bases.SieveorNone The working model: a basis from
cleverly.bases, or a sieve with a declared size.Noneasks for the conditional contrast itself.- treatment
Any The treated arm
tof a treatment with more than two levels. A binary treatment contrasts its second level with its first.- reference
Any The reference arm
rof a treatment with more than two levels.
- modifiers
See also
cleverly.bases.ModifiersThe modifier schema.
cleverly.bases.LinearThe basis that needs no domain.
ATEThe marginal effect, which a constant basis reproduces.
cleverly.estimators.TMLEResult.heterogeneity_testThe test of the non-constant terms.
Examples
>>> from cleverly import ConditionalContrast >>> from cleverly.bases import Linear, Modifiers >>> estimand = ConditionalContrast(Modifiers(["W1"]), model=Linear(["W1"])) >>> estimand.name, estimand.model.terms ('cate', ('(intercept)', 'W1'))
Methods#
Attributes#
- ConditionalContrast.definition#
Return the contrast in words.