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. With model=None the target is the conditional contrast as a function, which has no interval and no TMLE fit yet.

Parameters:
modifierscleverly.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).

modelbasis, cleverly.bases.Sieve or None

The working model: a basis from cleverly.bases, or a sieve with a declared size. None asks for the conditional contrast itself.

treatmentAny

The treated arm t of a treatment with more than two levels. A binary treatment contrasts its second level with its first.

referenceAny

The reference arm r of a treatment with more than two levels.

See also

cleverly.bases.Modifiers

The modifier schema.

cleverly.bases.Linear

The basis that needs no domain.

ATE

The marginal effect, which a constant basis reproduces.

cleverly.estimators.TMLEResult.heterogeneity_test

The 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.

ConditionalContrast.model: Any = None#
ConditionalContrast.name: str = 'cate'#
ConditionalContrast.reference: Any = None#
ConditionalContrast.scale: Literal['difference', 'log_ratio'] = 'difference'#
ConditionalContrast.treatment: Any = None#
ConditionalContrast.modifiers: Modifiers#