causalis.scenarios.classic_rct.inference.welch_permutation_t_test

Welch permutation t-test inference for the classic RCT scenario.

The p-value is computed from a permutation distribution of the Welch studentized statistic. Confidence intervals use the usual Welch-Satterthwaite approximation so the result can still populate the shared CausalEstimate contract.

Module Contents

Functions

welch_permutation_t_test

Run a Welch permutation t-test comparing treated and control outcomes.

Data

Alternative

API

causalis.scenarios.classic_rct.inference.welch_permutation_t_test.Alternative

None

causalis.scenarios.classic_rct.inference.welch_permutation_t_test.welch_permutation_t_test(data: causalis.dgp.causaldata.CausalData, alpha: float = 0.05, B: int = 10000, alternative: causalis.scenarios.classic_rct.inference.welch_permutation_t_test.Alternative = 'two-sided', seed: Optional[int] = None) Dict[str, Any]

Run a Welch permutation t-test comparing treated and control outcomes.

This test uses the Welch t-statistic as the test statistic but calculates the p-value using a permutation distribution rather than the t-distribution. This is useful when the normality assumption of the t-test is suspect, while still being robust to unequal variances between groups.

Notes

The permutation p-value is calculated as:

.. math::

p = \frac{\sum_{b=1}^B I(|t^*_b| \ge |t_{obs}|) + 1}{B + 1}

where $t_{obs}$ is the observed Welch t-statistic and $t^*_b$ are the t-statistics calculated from $B$ random permutations of the treatment labels. The addition of 1 in the numerator and denominator is a standard correction to ensure the test is valid (never returning a p-value of exactly 0).

Confidence intervals for the absolute and relative differences are still calculated using the Welch-Satterthwaite and Delta method approximations respectively, to remain consistent with other inference methods.

Examples

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

Parameters

data : CausalData The CausalData object containing treatment and outcome variables. alpha : float, default 0.05 Significance level for the theoretical Welch confidence interval. B : int, default 10000 Number of Monte Carlo label permutations. alternative : {“two-sided”, “greater”, “less”}, default “two-sided” Alternative hypothesis for the permutation p-value. seed : int, optional Random seed for reproducible permutations.

Returns

Dict[str, Any] A dictionary containing the permutation p-value, observed Welch statistic, absolute and relative differences, confidence intervals, number of permutations, and alternative.