Skip to main content

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 length p).
  • q_values: Dictionary whose keys are feature indices and values are their q-values (dict of length p).
  • runtime: Runtime of the algorithm in seconds (float).
  • selected_features: Indices of features selected by CausalStabSel; empty list if target_fp and target_fdr are 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 with q_value ≤ 0.1 controls the FDR at level 0.1
  • Control E(FP) by choosing all features with efp_score ≤ target_fp
    Example: Selecting features with efp_score ≤ 2 controls 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 via econml's CausalForestDML. econml is not installed by default; install it with pip 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; default None, which resolves to False if selector is 'l1'/'adaptive_lasso' and True otherwise).
  • smoother: Regression model class used for smoothing when smooth_cate=True (default None, which resolves to xgb.XGBRegressor). Must implement .fit(X, y) / .predict(X).
  • smoother_args: Arguments passed to smoother (dict; default None, 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)), where n is the number of samples and p is 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; default None).
  • 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; default True).
  • preselector, preselector_args: Preselection method and its arguments; see the IPSS documentation.
  • target_fp: Target number of false positives to control (positive float; default None).
  • target_fdr: Target false discovery rate (FDR) (positive float; default None).
  • B: Number of subsampling steps (int; default 100).
  • n_alphas: Number of values in the regularization or threshold grid (int; default None, 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 bound I(Lambda) (positive float; default 0.05).
  • delta: Defines probability measure; see IPSS (float, list of floats, or None; default None resolves to 2). If a list, causalstabsel returns one result dictionary per value.
  • subsample_size: Size of each subsample used for cross-fitting (int, float in (0, 1), or None; default None resolves to n // 2, and values above n // 2 are 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; default None).
  • center_y: Center response to have mean 0 (bool; default None).
  • n_jobs: Number of jobs to run in parallel (int; default 1).

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

causalstabsel-0.1.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

causalstabsel-0.1.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

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

Hashes for causalstabsel-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e763805dca425d3114d670d3b75222cbdf0e3baabc5a69f9d4b39d0a75ee041f
MD5 c1c92c7cc905a57be1cf6bcf08eaed24
BLAKE2b-256 a237903f5a3c9284103f488719530bfc5168046f5641ea4c6dd152baa04a4b2f

See more details on using hashes here.

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

Hashes for causalstabsel-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ea3c6b20c9cf3776f49ba9aa80ed315e053ac3385bc43dd533d527367712b827
MD5 5cda1499daf41254e6e970b0d940e5ce
BLAKE2b-256 cd7fab388be83712ddf89728c46a1eefa4b23787b50bb0cc448620a6fac02d24

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page