cleverly.AdaptiveTMLEResult#

class cleverly.AdaptiveTMLEResult(estimates: dict[str, ParameterEstimate], fit: AdaptiveTMLEFit, data: CausalData, identified_effect: IdentifiedEffect, method: AdaptiveTMLEMethod, parameter_keys: dict[str, Any], provenance: Provenance, learners: dict[str, Any] = <factory>, g_bounds: tuple[float, float] = (0.0, 1.0), fit_warnings: tuple[FitWarning, ...] = ())[source]#

The adaptive TMLE estimate of a trial’s effect with external data.

Behaves as a mapping from parameter name to ParameterEstimate, with the one name ate. The estimate is the working-model projection of the trial effect, with status "working_model_projection": the interval is shown and covers the projection, and covers the trial effect itself only under the oracle-approximation condition of arXiv:2405.07186v2, Theorem 1.

Parameters:
estimatesdict of str to ParameterEstimate

The estimate, keyed ate.

fitAdaptiveTMLEFit

The engine’s fit: the influence curve, the working models and the targeting record.

dataCausalData

The prepared pooled data.

identified_effectIdentifiedEffect

The identified question this fit answers.

methodAdaptiveTMLEMethod

The declared method.

parameter_keysdict of str to ParameterKey

The structured identity of each estimate.

provenanceProvenance

The fit’s record of versions, data and split.

learnersdict of str to Any

The resolved learner of each role.

g_boundstuple of float

The bounds the treatment probabilities were clipped to.

fit_warningstuple of FitWarning

The warnings the fit raised.

Attributes:
estimateParameterEstimate

The sole estimate.

inference_statusstr

The inference status of the fit, "working_model_projection".

nint

The number of rows, trial and external.

influence_curvesdict

The influence curves by parameter name.

working_modelstuple

The working models each fold selected, with their coefficients.

foldsFolds

The outer split of the fit.

diagnosticsDiagnosticsFacade

The support, score, working-model and update diagnostics of the fit.

replayabilityReplayability

Which assessment operations survive from the stored fit.

Examples

>>> import numpy as np
>>> import pandas as pd
>>> from sklearn.linear_model import LinearRegression, LogisticRegression
>>> from cleverly import CausalStudy, TrialATE, TrialWithExternalData
>>> rng = np.random.default_rng(0)
>>> n = 400
>>> s = rng.binomial(1, 0.5, n)
>>> w = rng.normal(size=n)
>>> a = np.where(s == 1, rng.binomial(1, 0.5, n), rng.binomial(1, 0.3, n))
>>> y = 1.0 + a + w + 0.5 * (1 - s) + rng.normal(size=n)
>>> frame = pd.DataFrame({"Y": y, "A": a, "W": w, "S": s})
>>> study = CausalStudy(
...     frame,
...     design=TrialWithExternalData(outcome="Y", treatment="A", adjustment=("W",), source="S"),
... )
>>> result = study.identify(TrialATE(population="trial")).estimate(
...     outcome_learner=LinearRegression(),
...     treatment_learner=LogisticRegression(),
...     n_folds=3,
...     random_state=0,
... )
>>> result.inference_status
'working_model_projection'
>>> bool(abs(result.psi() - 1.0) < 0.5)
True

Methods#

AdaptiveTMLEResult.assess(*, include_refits: bool = False, include_retargets: bool = False, arguments: Mapping[str, Mapping[str, Any]] | None = None, random_state: int | None = None) → Any[source]#

Run the applicable post-fit assessment battery.

Every sensitivity row refuses on this fit: no bound is derived for an adaptive working-model fit.

Parameters:
include_refitsbool

Run requested operations that refit nuisance models.

include_retargetsbool

Include moderate retargets.

argumentsmapping or None

Per-operation keyword arguments.

random_stateint or None

Common seed for stochastic refit operations.

Returns:
AssessmentReport

Validation, diagnostics, and sensitivity in one report.

AdaptiveTMLEResult.contrast(function: Callable[[FloatArray], float], names: Sequence[str], *, name: str | None = None, gradient: Callable[[FloatArray], FloatArray] | None = None, transform: Transform | None = None) → ParameterEstimate[source]#

Return a smooth function of estimates with delta-method inference.

Parameters:
functioncallable()

A smooth scalar function of the selected estimates.

namessequence of str

The names passed to function in order.

namestr or None

The name of the derived estimate.

gradientcallable() or None

The analytic gradient. None uses central differences.

transformTransform or None

The map the interval is computed on.

Returns:
ParameterEstimate

The derived estimate, on the difference scale, with the status of its inputs.

AdaptiveTMLEResult.corrections_report() → AdaptiveTMLECorrections[source]#

The updates after selection: the trial-membership passes and the model steps.

Returns:
AdaptiveTMLECorrections

The engine’s targeting record.

AdaptiveTMLEResult.covariance(names: Sequence[str] | None = None) → NDArray[float64][source]#

Return the joint covariance of selected estimates.

Parameters:
namessequence of str or None

Names in output order. None selects all estimates.

Returns:
ndarray

The covariance of the estimators. The result holds one estimate, so this is its variance under the fit’s own rule, the mean of the validation folds’ variances for form="cv", which equals std_error ** 2.

AdaptiveTMLEResult.items() → Any[source]#

The (name, estimate) pairs.

Returns:
ItemsView

The pairs, in report order.

AdaptiveTMLEResult.keys() → Any[source]#

The parameter names.

Returns:
KeysView

The names, in report order.

AdaptiveTMLEResult.nuisance_report() → AdaptiveTMLENuisanceReport[source]#

The learners and the working models each fold selected.

Returns:
AdaptiveTMLENuisanceReport

One record per selection.

AdaptiveTMLEResult.psi(name: str | None = None) → float[source]#

Return a point estimate by parameter name.

Parameters:
namestr or None

The parameter name. None takes the sole estimate.

Returns:
float

The point estimate.

AdaptiveTMLEResult.ratio(numerator: str, denominator: str, **kwargs: Any) → ParameterEstimate[source]#

Refuse a ratio: only the difference scale is derived.

Parameters:
numeratorstr

The numerator’s name.

denominatorstr

The denominator’s name.

**kwargsAny

Ignored.

Returns:
ParameterEstimate

Never returns.

Raises:
CapabilityError

Always.

AdaptiveTMLEResult.save(path: Any) → Any[source]#

Persist the fitted result to a trusted joblib artifact.

The artifact records cleverly.__version__. A load by a different version warns with VersionMismatchWarning.

Parameters:
pathpath-like

Destination file.

Returns:
Path

The destination path.

AdaptiveTMLEResult.score_report() → AdaptiveTMLEScoreReport[source]#

The score equations at the end of the fit, with the stopping rule’s threshold.

Returns:
AdaptiveTMLEScoreReport

The four score means and the threshold.

AdaptiveTMLEResult.summary(*, detail: Literal['short', 'full'] = 'short') → Summary[source]#

The estimate, the trial and external rows, and what the interval covers.

Parameters:
detail{“short”, “full”}, default=”short”

"full" adds the assumptions and the settings.

Returns:
Summary

The summary. It prints as text and renders as HTML in a notebook.

AdaptiveTMLEResult.support_report() → AdaptiveTMLESupport[source]#

The overlap of the trial with the external rows (A3) and the trial’s arms.

Returns:
AdaptiveTMLESupport

The engine’s record of both.

AdaptiveTMLEResult.to_frame() → Any[source]#

One row per reported parameter, in the backend the data came from.

Returns:
dataframe

The columns of a point-treatment report, plus population and form.

AdaptiveTMLEResult.validate() → Any[source]#

Run the inexpensive default battery without refitting.

Returns:
ValidationReport

One item per validated check, read off the stored fit.

AdaptiveTMLEResult.values() → Any[source]#

The estimates.

Returns:
ValuesView

The estimates, in report order.

Attributes#

AdaptiveTMLEResult.assessment_family: ClassVar[str] = 'augmented_trial'#

The assessment family: one declaration per assessment operation in cleverly.assessment.ASSESSMENT_CAPABILITIES. The fit holds no point-treatment nuisance or targeting state, so the point declarations do not describe it.

AdaptiveTMLEResult.diagnostics#

The support, score, working-model and update diagnostics of the fit.

AdaptiveTMLEResult.estimate#

The sole estimate.

AdaptiveTMLEResult.fit_warnings: tuple[FitWarning, ...] = ()#

The warnings the fit raised (cleverly._warnings).

AdaptiveTMLEResult.fitted_method: ClassVar[str] = 'atmle'#

The method identity of the result.

AdaptiveTMLEResult.folds#

The outer split of the fit.

AdaptiveTMLEResult.g_bounds: tuple[float, float] = (0.0, 1.0)#
AdaptiveTMLEResult.inference_status#

The inference status of the fit, "working_model_projection".

AdaptiveTMLEResult.influence_curves#

The influence curves by parameter name.

AdaptiveTMLEResult.n#

The number of rows, trial and external.

AdaptiveTMLEResult.replayability#

Which assessment operations survive from the stored fit.

AdaptiveTMLEResult.sensitivity#

The sensitivity-analysis facade, whose every row refuses on this fit.

AdaptiveTMLEResult.working_models#

The working models each fold selected, with their coefficients.

AdaptiveTMLEResult.estimates: dict[str, ParameterEstimate]#
AdaptiveTMLEResult.fit: AdaptiveTMLEFit#
AdaptiveTMLEResult.data: CausalData#
AdaptiveTMLEResult.identified_effect: IdentifiedEffect#
AdaptiveTMLEResult.method: AdaptiveTMLEMethod#
AdaptiveTMLEResult.parameter_keys: dict[str, Any]#
AdaptiveTMLEResult.provenance: Provenance#
AdaptiveTMLEResult.learners: dict[str, Any]#
AdaptiveTMLEResult.assessment_cache: AssessmentCache#

Assessment results keyed by operation and normalized arguments. init=False, so a mapping handed to the constructor by dataclasses.replace cannot answer for another fit.