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 nameate. 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:
- estimates
dictofstrtoParameterEstimate The estimate, keyed
ate.- fit
AdaptiveTMLEFit The engine’s fit: the influence curve, the working models and the targeting record.
- data
CausalData The prepared pooled data.
- identified_effect
IdentifiedEffect The identified question this fit answers.
- method
AdaptiveTMLEMethod The declared method.
- parameter_keys
dictofstrtoParameterKey The structured identity of each estimate.
- provenance
Provenance The fit’s record of versions, data and split.
- learners
dictofstrtoAny The resolved learner of each role.
- g_bounds
tupleoffloat The bounds the treatment probabilities were clipped to.
- fit_warnings
tupleofFitWarning The warnings the fit raised.
- estimates
- Attributes:
estimateParameterEstimateThe sole estimate.
inference_statusstrThe inference status of the fit,
"working_model_projection".nintThe number of rows, trial and external.
influence_curvesdictThe influence curves by parameter name.
working_modelstupleThe working models each fold selected, with their coefficients.
foldsFoldsThe outer split of the fit.
diagnosticsDiagnosticsFacadeThe support, score, working-model and update diagnostics of the fit.
replayabilityReplayabilityWhich assessment operations survive from the stored fit.
See also
cleverly.TrialWithExternalDataThe design.
cleverly.TrialATEThe estimand.
cleverly.AdaptiveTMLEMethodThe method.
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:
- Returns:
AssessmentReportValidation, 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:
- function
callable() A smooth scalar function of the selected estimates.
- namessequence
ofstr The names passed to
functionin order.- name
strorNone The name of the derived estimate.
- gradient
callable()orNone The analytic gradient.
Noneuses central differences.- transform
TransformorNone The map the interval is computed on.
- function
- Returns:
ParameterEstimateThe 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:
AdaptiveTMLECorrectionsThe engine’s targeting record.
- AdaptiveTMLEResult.covariance(names: Sequence[str] | None = None) NDArray[float64][source]#
Return the joint covariance of selected estimates.
- Parameters:
- Returns:
ndarrayThe 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 equalsstd_error ** 2.
- AdaptiveTMLEResult.items() Any[source]#
The
(name, estimate)pairs.- Returns:
ItemsViewThe pairs, in report order.
- AdaptiveTMLEResult.keys() Any[source]#
The parameter names.
- Returns:
KeysViewThe names, in report order.
- AdaptiveTMLEResult.nuisance_report() AdaptiveTMLENuisanceReport[source]#
The learners and the working models each fold selected.
- Returns:
AdaptiveTMLENuisanceReportOne record per selection.
- AdaptiveTMLEResult.psi(name: str | None = None) float[source]#
Return a point estimate by parameter name.
- AdaptiveTMLEResult.ratio(numerator: str, denominator: str, **kwargs: Any) ParameterEstimate[source]#
Refuse a ratio: only the difference scale is derived.
- Parameters:
- Returns:
ParameterEstimateNever returns.
- Raises:
CapabilityErrorAlways.
- 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 withVersionMismatchWarning.- Parameters:
- pathpath-like
Destination file.
- Returns:
PathThe destination path.
- AdaptiveTMLEResult.score_report() AdaptiveTMLEScoreReport[source]#
The score equations at the end of the fit, with the stopping rule’s threshold.
- Returns:
AdaptiveTMLEScoreReportThe 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:
SummaryThe 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:
AdaptiveTMLESupportThe engine’s record of both.
- AdaptiveTMLEResult.to_frame() Any[source]#
One row per reported parameter, in the backend the data came from.
- Returns:
dataframeThe columns of a point-treatment report, plus
populationandform.
- AdaptiveTMLEResult.validate() Any[source]#
Run the inexpensive default battery without refitting.
- Returns:
ValidationReportOne item per validated check, read off the stored fit.
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.folds#
The outer split of the fit.
- 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.provenance: Provenance#
- AdaptiveTMLEResult.assessment_cache: AssessmentCache#
Assessment results keyed by operation and normalized arguments.
init=False, so a mapping handed to the constructor bydataclasses.replacecannot answer for another fit.