causalis.scenarios.classic_rct.inference.ttest

T-test inference for Diff_in_Means model

Module Contents

Functions

ttest

Perform a Welch two-sample t-test comparing outcomes between groups.

API

causalis.scenarios.classic_rct.inference.ttest.ttest(data: causalis.data_contracts.CausalData, alpha: float = 0.05) Dict[str, Any]

Perform a Welch two-sample t-test comparing outcomes between groups.

The Welch t-test (also known as the unequal variances t-test) is used to test the hypothesis that two populations have equal means. It is more robust than Student’s t-test when the two samples have unequal variances and/or unequal sample sizes.

Notes

The Welch t-statistic is calculated as:

.. math::

t = \frac{\bar{Y}_1 - \bar{Y}_0}{\sqrt{\frac{s_1^2}{n_1} + \frac{s_0^2}{n_0}}}

The degrees of freedom $\nu$ are approximated using the Welch-Satterthwaite equation:

.. math::

\nu \approx \frac{\left(\frac{s_1^2}{n_1} + \frac{s_0^2}{n_0}\right)^2}
{\frac{(s_1^2/n_1)^2}{n_1-1} + \frac{(s_0^2/n_0)^2}{n_0-1}}

For the relative difference (percent lift), the variance is estimated using the Delta method:

.. math::

Var\left(\frac{\bar{Y}_1}{\bar{Y}_0}\right) \approx
\frac{1}{\bar{Y}_0^2} Var(\bar{Y}_1) + \frac{\bar{Y}_1^2}{\bar{Y}_0^4} Var(\bar{Y}_0)

Examples

from causalis.scenarios.classic_rct.dgp import generate_classic_rct_26 from causalis.scenarios.classic_rct.inference.ttest import ttest data = generate_classic_rct_26(n=2000, seed=42) results = ttest(data) print(f”P-value: {results[‘p_value’]:.4f}”) 0.1685

Parameters

data : CausalData The CausalData object containing treatment and outcome variables. alpha : float, default 0.05 The significance level for calculating confidence intervals.

Returns

Dict[str, Any] A dictionary containing: - p_value: Welch t-test p-value. - absolute_difference: $\bar{Y}_1 - \bar{Y}_0$. - absolute_ci: (lower, upper) CI for absolute difference. - relative_difference: Percent change relative to control. - relative_se: Delta-method standard error for the relative difference. - relative_ci: (lower, upper) CI for relative difference.