cleverly.inference.Transform#
- class cleverly.inference.Transform(name: str, forward: Callable[[float], float], inverse: Callable[[float], float], derivative: Callable[[float], float] | None = None)[source]#
A monotone map that a contrast’s interval and test are computed on.
The interval is \(f^{-1}(f(\hat h) \pm z \cdot se)\), with \(se\) the standard error of \(f(\hat h)\) by the chain rule. This is the
contrast = list(f, f_inv, h, fh_grad)form of Rdrtmle1.1.2ci()(R/confint.R, lines 146 to 167). The limits are sorted after the inverse map, so a decreasingfgives an ordered interval.A transform built from lambdas does not pickle.
log()andlogit()use module-level functions and pickle. A fitted result never stores a transformed estimate, soresult.save()does not depend on this.- Parameters:
- name
str A label for the transform, which
to_dictreports.- forward
callable() The map \(f\), from the scale of the contrast to the inference scale.
- inverse
callable() The inverse map \(f^{-1}\).
- derivative
callable()orNone, default=None The derivative \(f'\).
Nonetakes a central difference.
- name
See also
cleverly.estimators.TMLEResult.contrastTakes
transform=.
Examples
>>> from cleverly.inference import Transform >>> log = Transform.log() >>> log.name, round(log.forward(1.0), 6), round(log.inverse(0.0), 6) ('log', 0.0, 1.0)
Methods#
- classmethod Transform.log() Transform[source]#
The natural log, with
expas its inverse.- Returns:
TransformThe log transform, for a positive contrast such as a ratio.
- classmethod Transform.logit() Transform[source]#
The logit, with the logistic function as its inverse.
- Returns:
TransformThe logit transform, for a contrast inside
(0, 1)such as a probability.
- classmethod Transform.range_logit(low: float, high: float) Transform[source]#
The logit of a value’s position in the open interval
(low, high).The map is \(f(x) = \operatorname{logit}((x - a) / (b - a))\) with \((a, b)\) =
(low, high). On(0, 1)it is the logit. On(-1, 1)it is \(2 \operatorname{atanh}(x)\), so a symmetric interval on its scale is theatanhinterval of a difference of two probabilities.- Parameters:
- Returns:
TransformThe transform, named
"logit"on(0, 1)and"range_logit"otherwise.
- Raises:
ValueErrorIf
highis not abovelow, or either end is not finite.