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).
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file causalstabsel-0.1.0.tar.gz.
File metadata
- Download URL: causalstabsel-0.1.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e763805dca425d3114d670d3b75222cbdf0e3baabc5a69f9d4b39d0a75ee041f
|
|
| MD5 |
c1c92c7cc905a57be1cf6bcf08eaed24
|
|
| BLAKE2b-256 |
a237903f5a3c9284103f488719530bfc5168046f5641ea4c6dd152baa04a4b2f
|
File details
Details for the file causalstabsel-0.1.0-py3-none-any.whl.
File metadata
- Download URL: causalstabsel-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea3c6b20c9cf3776f49ba9aa80ed315e053ac3385bc43dd533d527367712b827
|
|
| MD5 |
5cda1499daf41254e6e970b0d940e5ce
|
|
| BLAKE2b-256 |
cd7fab388be83712ddf89728c46a1eefa4b23787b50bb0cc448620a6fac02d24
|