cleverly.TrialWithExternalData#
- class cleverly.TrialWithExternalData(outcome: str, treatment: str, adjustment: Sequence[str], source: str, trial: Any = 1, missingness: str | None = None, outcome_family: Literal['gaussian', 'binomial', 'auto'] = 'auto')[source]#
Declare a randomized trial pooled with external data on the same outcome.
The pooled frame holds the trial’s rows and the external rows, such as the controls of a registry or an earlier study, with one column marking trial membership. The design claims two things about the trial and nothing about the external rows: the treatment was randomized in the trial given the adjustment columns, and every trial row could get either arm. The adaptive TMLE (
method="atmle") learns how the external outcomes differ from the trial’s and removes that bias. After the fit it reports how well the trial covers the external rows’ covariates.- Parameters:
- outcome
str Outcome column.
- treatment
str Binary treatment column. A treatment with more than two levels, a continuous dose and a vector treatment are refused, because the estimator is derived for a binary treatment only.
- adjustmentsequence
ofstr Baseline covariate columns. At least one is required: the bias of the external rows is learned as a function of them.
- source
str The column that marks trial membership.
- trial
Any, default=1 The value of
sourceon trial rows. Every other value marks an external row.- missingness
strorNone, default=None Outcome-observation indicator. One means observed. The design then assumes the outcome is missing at random given the covariates and the arm in the trial, and assumes nothing about why external outcomes are missing.
- outcome_family{“auto”, “gaussian”, “binomial”}, default=”auto”
Outcome family.
"auto"infers it from observed values.
- outcome
- Raises:
DataErrorWhen two roles name one column, or
adjustmentis empty or repeats a column.CapabilityErrorWhen
treatmentnames more than one column.
See also
TrialATEThe effect this design identifies.
AdaptiveTMLEMethodThe method that estimates it.
PointTreatmentThe design for the trial rows alone.
Examples
>>> from cleverly import TrialWithExternalData >>> design = TrialWithExternalData( ... outcome="Y", treatment="A", adjustment=("W1", "W2"), source="S" ... ) >>> design.source, design.trial ('S', 1)
Methods#
- TrialWithExternalData.prepare(data: Any) CausalData[source]#
Validate the pooled data and encode the declared column roles.
- Parameters:
- data
dataframeorCausalData Pandas, Polars, or prepared causal data.
- data
- Returns:
CausalDataValidated internal representation, with trial membership in
source.
- Raises:
CapabilityErrorWhen the treatment takes more than two values.
DataErrorWhen the data hold no trial row, no external row, or a trial with one arm, or when a supplied
CausalDatawas built with other roles.
Attributes#
- TrialWithExternalData.treatment_name#
The treatment’s column.