Skip to content
Submodule
causalis.scenarios.classic_rct.model

model

Submodule causalis.scenarios.classic_rct.model with no child pages and 4 documented members.

Classes

Jump directly into the documented classes for this page.

1 items
class
causalis.scenarios.classic_rct.model.DiffInMeans

DiffInMeans

Difference-in-means model for Randomized Controlled Trials (RCT).

The difference-in-means estimator is the simplest way to estimate the Average Treatment Effect (ATE) in a randomized experiment. Because treatment assignment is random, the difference in sample means between the treated and control groups is an unbiased estimator of the ATE.

Notes

The Average Treatment Effect (ATE) is defined as:

τ=E[Y(1)Y(0)]\tau = E[Y(1) - Y(0)]

In an RCT, $D \perp (Y(0), Y(1))$, so:

τ=E[YD=1]E[YD=0]\tau = E[Y | D=1] - E[Y | D=0]

The estimator implemented here is the simple difference in sample means:

τ^=1n1i:Di=1Yi1n0i:Di=0Yi\hat{\tau} = \frac{1}{n_1} \sum_{i: D_i=1} Y_i - \frac{1}{n_0} \sum_{i: D_i=0} Y_i

Standard errors and confidence intervals are computed using Welch’s t-test by default, which does not assume equal variances between groups:

SE(τ^)=s12n1+s02n0SE(\hat{\tau}) = \sqrt{\frac{s_1^2}{n_1} + \frac{s_0^2}{n_0}}

where $s_g^2$ is the sample variance in group $g$.

Examples

Generate synthetic RCT data

Attributes

dataCausalData or None

The dataset used for fitting and estimation.

Canonical target

causalis.scenarios.classic_rct.model.DiffInMeans

Sections

NotesAttributesExamples
Link to this symbol
method
causalis.scenarios.classic_rct.model.DiffInMeans.fit

fit

Fit the model by storing the CausalData object.

In the DiffInMeans scenario, “fitting” primarily involves validating the data structure and storing it for subsequent estimation.

Parameters

dataCausalData

The CausalData object containing treatment and outcome variables. Treatment must be binary (0/1).

Returns

DiffInMeans

The fitted model instance.

Raises

ValueError

If the input is not a CausalData object.

Canonical target

causalis.scenarios.classic_rct.model.DiffInMeans.fit

Sections

ParametersReturnsRaises
Link to this symbol
method
causalis.scenarios.classic_rct.model.DiffInMeans.estimate

estimate

Compute the treatment effect using the specified method.

Parameters

method{“ttest”, “welch_permutation_t_test”, “conversion_ztest”}, default “ttest”

The inference method to use: - “ttest”: Standard Welch’s two-sample t-test (handles unequal variances). - “welch_permutation_t_test”: Permutation-based p-value using the Welch statistic. - “conversion_ztest”: Z-test for proportions, suitable for binary (0/1) outcomes.

alphafloat, default 0.05

Significance level for calculating confidence intervals.

diagnostic_databool, default True

Whether to include diagnostic data in the result (e.g., covariate balance if confounders exist).

**kwargsAny

Additional arguments passed to the underlying inference function: - For “welch_permutation_t_test”: B (iterations), alternative, seed. - For “conversion_ztest”: ci_method, se_for_test.

Returns

CausalEstimate

A results object containing: - value: The estimated ATE (absolute difference). - p_value: The statistical significance. - ci_lower_absolute, ci_upper_absolute: Confidence interval bounds. - value_relative: The relative effect (% lift).

Raises

RuntimeError

If the model has not been fitted yet. ValueError If an unsupported method is specified.

Canonical target

causalis.scenarios.classic_rct.model.DiffInMeans.estimate

Sections

ParametersReturnsRaises
Link to this symbol
method
causalis.scenarios.classic_rct.model.DiffInMeans.__repr__

__repr__

Canonical target

causalis.scenarios.classic_rct.model.DiffInMeans.__repr__

Link to this symbol