Causal Stability Selection (CausalStabSel)
Stable effect modifier discovery with false discovery control
Associated paper
- Causal stability selection
arXiv
Installation
pip install causalstabsel
Usage
from causalstabsel import causalstabsel
# load n-by-p feature matrix X, n-by-1 response vector y, and n-by-1 binary treatment indicator
# run causal stability selection
output = causalstabsel(X, y, treatment)
# select features based on target FDR
target_fdr = 0.1
q_values = output['q_values']
selected_features = [idx for idx, q_value in q_values.items() if q_value <= target_fdr]
print(f'Selected features (target FDR = {target_fdr}): {selected_features}')
Outputs
output = causalstabsel(X, y, treatment) is a dictionary containing:
efp_scores: Dictionary whose keys are feature indices and values are their efp scores (dict of lengthp).q_values: Dictionary whose keys are feature indices and values are their q-values (dict of lengthp).runtime: Runtime of the algorithm in seconds (float).selected_features: Indices of features selected by CausalStabSel; empty list iftarget_fpandtarget_fdrare not specified (list of ints).stability_paths: Estimated selection probabilities at each parameter (array of shape(n_alphas, p)).
Selecting features
Each feature (column of X) is assigned:
- a q-value: the minimum false discovery rate (FDR) at which the feature is selected
- an efp score: the minimum expected number of false positives (E(FP)) at which the feature is selected
To select features:
- Control FDR by choosing all features with
q_value ≤ target_fdr
Example: Selecting features withq_value ≤ 0.1controls the FDR at level 0.1 - Control E(FP) by choosing all features with
efp_score ≤ target_fp
Example: Selecting features withefp_score ≤ 2controls the E(FP) at level 2
CATE estimators
cate_estimator: method used to estimate pseudo-outcomes (str; default 'drlearner_gb'):
'drlearner_gb','drlearner_rf','drlearner_ridge': Doubly-robust (DR) learner, with gradient boosting (XGBoost), random forest, or ridge regression nuisance models.'tlearner_gb','tlearner_rf','tlearner_ridge': T-learner.'xlearner_gb','xlearner_rf','xlearner_ridge': X-learner.'causal_forest': Causal forest viaeconml'sCausalForestDML.econmlis not installed by default; install it withpip install causalstabsel[causal_forest].
cate_args: estimator-specific keyword arguments (dict; default None, which resolves to each estimator's own defaults).
propensity_estimator: how treatment propensities are estimated (used by the DR- and X-learners; default None, which assumes constant propensity of 0.5). Options:
'logistic_regression': Logistic regression (scikit-learn).'rf': Random forest (scikit-learn).'gb'or'xgb': Gradient boosting (XGBoost).- A float in
[0, 1]: Use this constant propensity for all samples. - Custom: a function
propensity_estimator(x_train, t_train, x_test) -> array of propensities for x_test.
Smoothing
Cross-fit CATE estimates are noisy at the sample level, so by default causalstabsel smooths them with a secondary regression model before running the base selector:
smooth_cate: Whether to smooth CATE pseudo-outcomes (bool; defaultNone, which resolves toFalseifselectoris'l1'/'adaptive_lasso'andTrueotherwise).smoother: Regression model class used for smoothing whensmooth_cate=True(defaultNone, which resolves toxgb.XGBRegressor). Must implement.fit(X, y)/.predict(X).smoother_args: Arguments passed tosmoother(dict; defaultNone, which resolves to{'n_estimators': 20, 'max_depth': 3}for the default smoother).
Full list of causalstabsel arguments
Required arguments:
X: Features (array of shape(n,p)), wherenis the number of samples andpis the number of features.y: Response (array of shape(n,)or(n, 1)).treatment: Binary treatment indicator (array of shape(n,), values in{0, 1}).
Optional arguments:
selector: Base algorithm used to score smoothed CATE estimates (str; default'gb'). See the IPSS documentation for all options, including custom feature importance functions.selector_args: Arguments for the base algorithm (dict; defaultNone).cate_estimator,cate_args,propensity_estimator: See CATE estimators above.smooth_cate,smoother,smoother_args: See Smoothing above.preselect: Preselect/filter features prior to subsampling (bool; defaultTrue).preselector,preselector_args: Preselection method and its arguments; see the IPSS documentation.target_fp: Target number of false positives to control (positive float; defaultNone).target_fdr: Target false discovery rate (FDR) (positive float; defaultNone).B: Number of subsampling steps (int; default100).n_alphas: Number of values in the regularization or threshold grid (int; defaultNone, resolves to an IPSS-determined default).ipss_function: Function applied to selection probabilities (str; default'h3'). Options'h1','h2','h3'; see IPSS.cutoff: Maximum value of the theoretical integral boundI(Lambda)(positive float; default0.05).delta: Defines probability measure; see IPSS (float, list of floats, orNone; defaultNoneresolves to2). If a list,causalstabselreturns one result dictionary per value.subsample_size: Size of each subsample used for cross-fitting (int, float in(0, 1), orNone; defaultNoneresolves ton // 2, and values aboven // 2are capped there since two disjoint subsamples of this size are drawn per step).standardize_X: Scale features to have mean 0, standard deviation 1 (bool; defaultNone).center_y: Center response to have mean 0 (bool; defaultNone).n_jobs: Number of jobs to run in parallel (int; default1).
Metadata
Release files for causalstabsel 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| causalstabsel-0.1.0.tar.gz | 8.0 kB | Without provenance | Details for causalstabsel-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| causalstabsel-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for causalstabsel-0.1.0-py3-none-any.whl |
Total release size: 16.1 kB
Release files / causalstabsel-0.1.0.tar.gz
| Download URL | causalstabsel-0.1.0.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e763805dca425d3114d670d3b75222cbdf0e3baabc5a69f9d4b39d0a75ee041f
|
|
BLAKE2b-256 checksum How to use checksums |
a237903f5a3c9284103f488719530bfc5168046f5641ea4c6dd152baa04a4b2f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / causalstabsel-0.1.0-py3-none-any.whl
| Download URL | causalstabsel-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ea3c6b20c9cf3776f49ba9aa80ed315e053ac3385bc43dd533d527367712b827
|
|
BLAKE2b-256 checksum How to use checksums |
cd7fab388be83712ddf89728c46a1eefa4b23787b50bb0cc448620a6fac02d24
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for causalstabsel 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.