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).

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)

Source distribution for causalstabsel 0.1.0
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)

Table of built distributions (wheels) for causalstabsel 0.1.0
File Interpreter ABI Platform Actions
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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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