cleverly.CausalStudy#
- class cleverly.CausalStudy(data: Any, *, design: PointTreatment | LongitudinalTreatment | TimeToEvent | LongPanel, protocol: StudyProtocol | None = None)[source]#
Validate observed data against an immutable causal-study design.
- Parameters:
- data
dataframe,CausalData,orLongitudinalData Observed study data. Pandas and Polars dataframes are supported.
- design
PointTreatment,LongitudinalTreatment,TimeToEvent,orLongPanel Column roles and treatment-time structure.
- protocol
StudyProtocolorNone Scientific study protocol.
Nonerecords that no protocol was supplied.
- data
- Attributes:
dataCausalDataorLongitudinalDataReturn the validated internal data representation.
designPointTreatment,LongitudinalTreatment,TimeToEvent,orLongPanelReturn the immutable study design.
protocolStudyProtocolorNoneReturn the scientific study protocol, if one was supplied.
See also
PointTreatmentThe design declaration for treatment given once.
LongitudinalTreatmentThe design declaration for time-varying treatment.
TimeToEventThe design declaration for one follow-up time and one event code per unit.
LongPanelThe design declaration for one row per unit and decision time.
IdentifiedEffectWhat
identify()returns.
Examples
>>> from cleverly import ATE, CausalStudy, PointTreatment >>> from cleverly.datasets import make_linear_ate >>> frame, _ = make_linear_ate(n=40, seed=1) >>> study = CausalStudy( ... frame, ... design=PointTreatment( ... outcome="Y", treatment="A", adjustment=("W1", "W2", "W3", "W4") ... ), ... ) >>> study.identify(ATE()).estimand.name 'ate'
Methods#
- CausalStudy.estimate(estimand: ATE | ATT | ATC | CounterfactualMean | NaturalCourseMean | PopulationAttributableRisk | PopulationAttributableFraction | RiskRatio | OddsRatio | RegimeMean | RegimeContrast | LearnedRuleValue | ModifiedTreatmentPolicy | ModifiedTreatmentPolicyEffect | IncrementalMean | IncrementalEffect | MSMProjection | ControlledDirectEffect, method: str | EstimationMethod = 'tmle', **overrides: Any) TMLEResult | LongitudinalResult[source]#
Identify and estimate one causal quantity.
- Parameters:
- estimand
Estimand Typed causal quantity.
- method
strorEstimationMethod Named method or configured method object.
- **overrides
Any Method fields overridden for this fit.
- estimand
- Returns:
TMLEResultorLongitudinalResultFitted result for the declared design.
- CausalStudy.identify(estimand: ATE | ATT | ATC | CounterfactualMean | NaturalCourseMean | PopulationAttributableRisk | PopulationAttributableFraction | RiskRatio | OddsRatio | RegimeMean | RegimeContrast | LearnedRuleValue | ModifiedTreatmentPolicy | ModifiedTreatmentPolicyEffect | IncrementalMean | IncrementalEffect | MSMProjection | ControlledDirectEffect, *, provider: IdentificationProvider | None = None) IdentifiedEffect[source]#
Bind one typed estimand to an observed-data functional.
- Parameters:
- estimand
Estimand Typed causal quantity, such as
ATE(). String aliases are not accepted.- provider
IdentificationProviderorNone Identification strategy.
Noneuses explicit adjustment or history.
- estimand
- Returns:
IdentifiedEffectQuestion, functional, assumptions, and available methods before fitting.
- Raises:
CapabilityErrorIf the estimand type or its composition with the design or the data is unsupported, or if a typed estimand holds an intervention of another kind.
DataErrorIf the estimand names a value that the data lack, or if the set of a point estimand is a mapping, an iterator, a string, or a single item.
See also
IdentifiedEffectThe identified question returned by this method.
CausalStudy.estimateIdentify and estimate in one call.
Notes
Pass a typed estimand such as
ATE(). String aliases are refused with aCapabilityErrorso the failure identifies the required public object.Examples
>>> from cleverly import ATE, CausalStudy, PointTreatment >>> from cleverly.datasets import make_linear_ate >>> frame, _ = make_linear_ate(n=40, seed=1) >>> study = CausalStudy( ... frame, ... design=PointTreatment( ... outcome="Y", treatment="A", adjustment=("W1", "W2", "W3", "W4") ... ), ... ) >>> effect = study.identify(ATE(reference=0)) >>> effect.estimand.reference 0
Attributes#
- CausalStudy.data#
Return the validated internal data representation.
- CausalStudy.design#
Return the immutable study design.
- CausalStudy.protocol#
Return the scientific study protocol, if one was supplied.