cleverly.CausalResult#

class cleverly.CausalResult(*args, **kwargs)[source]#

Define operations shared by fitted causal-result families.

Concrete point-treatment and longitudinal results provide this interface. Use the protocol when application code accepts either result family.

Parameters:
*args, **kwargs

Present because typing.runtime_checkable() gives a protocol a synthetic constructor. A protocol is implemented, not instantiated.

Attributes:
estimatesmapping of str to ParameterEstimate

Estimates keyed by stable parameter alias.

identified_effectIdentifiedEffect

Causal question and identifying assumptions used for the fit.

methodEstimationMethod

Method configuration used for estimation.

parameter_keysmapping of str to ParameterKey

Structured identities for the reported aliases.

provenanceProvenance

Runtime and dependency information for the fit.

assessment_cachemapping

Saved diagnostic and sensitivity artifacts.

assessment_familystr

Result-owned capability family declaration.

estimateParameterEstimate

The sole parameter estimate. A concrete result raises ValueError here when it reports more than one parameter, so isinstance does not presence-check it. Use psi() or item access to name the parameter you want.

Notes

typing.runtime_checkable() gives isinstance a presence check over every member this class body declares. On Python 3.11 that check reads each member with hasattr(), which calls a property and swallows only AttributeError. A member whose read can raise anything else therefore turns isinstance into an exception. estimate is such a member, so this class declares it under typing.TYPE_CHECKING: a type checker still sees it, and the runtime check does not read it. Add a new member here only when reading it on every supported result cannot raise.

Methods#

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

Run the applicable post-fit assessment battery.

Parameters:
include_refitsbool

Run requested operations that refit nuisance models.

include_retargetsbool

Include moderate retargets; cheap E-value retargets run by default.

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.

CausalResult.contrast(function: Any, names: Sequence[str], **kwargs: Any) → Any[source]#

Apply the delta method to a smooth function of estimates.

Parameters:
functioncallable()

Function from a parameter vector to one scalar.

namessequence of str

Parameter aliases passed to function in order.

**kwargsAny

Options forwarded to the concrete result implementation.

Returns:
ParameterEstimate

Transformed estimate and influence-curve inference.

CausalResult.covariance(names: Sequence[str] | None = None) → Any[source]#

Estimate covariance for selected parameters.

Parameters:
namessequence of str or None

Parameter aliases in output order. None selects every estimate.

Returns:
ndarray

Covariance matrix in the requested order.

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

Return one point estimate by alias.

Parameters:
namestr or None

Parameter alias. Use None only when the result has one estimate.

Returns:
float

Point estimate on the parameter’s reported scale.

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

Return the risk ratio or odds ratio of two level estimates.

Parameters:
numeratorstr

Alias of the level in the numerator.

denominatorstr

Alias of the level in the denominator.

**kwargsAny

Options forwarded to the concrete result implementation.

Returns:
ParameterEstimate

The ratio, with its interval on the log scale.

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

Serialize the fitted result.

Parameters:
pathpath-like

Destination for the serialized result.

Returns:
Path

The destination path, as given.

CausalResult.summary(*, protocol: Literal['full', 'fingerprint'] = 'full') → str[source]#

Return a printable fit summary.

Parameters:
protocol{“full”, “fingerprint”}

How much of the protocol record the summary prints.

Returns:
str

The estimates, the settings, and the recorded facts of the fit.

CausalResult.to_frame() → Any[source]#

Return estimates in the input dataframe backend.

CausalResult.validate() → Any[source]#

Run validation checks available without new arguments.

Attributes#

CausalResult.diagnostics#

Return the diagnostics facade for saved fit artifacts.

CausalResult.influence_curves#

Return influence curves keyed by parameter alias.

CausalResult.replayability#

Report which analyses this result can replay.

CausalResult.sensitivity#

Return the sensitivity-analysis facade for this result.

CausalResult.estimates: Mapping[str, Any]#
CausalResult.identified_effect: Any#
CausalResult.method: Any#
CausalResult.parameter_keys: Mapping[str, Any]#
CausalResult.provenance: Any#
CausalResult.assessment_cache: Mapping[str, Any]#
CausalResult.assessment_family: str#