causallib.survival.weighted_standardized_survival module

class causallib.survival.weighted_standardized_survival.WeightedStandardizedSurvival(weight_model: causallib.estimation.base_weight.WeightEstimator, survival_model: Any, stratify: bool = True, outcome_covariates=None, weight_covariates=None)[source]

Bases: causallib.survival.standardized_survival.StandardizedSurvival

Combines WeightedSurvival and StandardizedSurvival:
  1. Adjusts for treatment assignment by creating weighted pseudo-population (e.g., inverse propensity weighting).

  2. Computes parametric curve by fitting a time-varying hazards model that includes baseline covariates.

Parameters
  • weight_model – causallib compatible weight model (e.g., IPW)

  • survival_model

    Two alternatives:
    1. Scikit-Learn estimator (needs to implement predict_proba) - compute parametric curve by fitting a

      time-varying hazards model that includes baseline covariates. Note that the model is fitted on a person-time table with all covariates, and might be computationally and memory expansive.

    2. lifelines RegressionFitter - use lifelines fitter to compute survival curves from baseline covariates,

      events and durations

    stratify (bool): if True, fit a separate model per treatment group outcome_covariates (array): Covariates to use for outcome model.

    If None - all covariates passed will be used. Either list of column names or boolean mask.

    weight_covariates (array): Covariates to use for weight model.

    If None - all covariates passed will be used. Either list of column names or boolean mask.

estimate_individual_outcome(X: pandas.core.frame.DataFrame, a: pandas.core.series.Series, t: pandas.core.series.Series, y: Optional[Any] = None, timeline_start: Optional[int] = None, timeline_end: Optional[int] = None) pandas.core.frame.DataFrame[source]

Returns individual survival curves for each subject row in X/a/t

Parameters
  • X (pd.DataFrame) – Baseline covariate matrix of size (num_subjects, num_features).

  • a (pd.Series) – Treatment assignment of size (num_subjects,).

  • t (pd.Series) – Followup durations, size (num_subjects,).

  • y – NOT USED (for API compatibility only).

  • timeline_start (int) – Common start time-step. If provided, will generate survival curves starting from ‘timeline_start’ for all patients. If None, will predict from first observed event (t.min()).

  • timeline_end (int) – Common end time-step. If provided, will generate survival curves up to ‘timeline_end’ for all patients. If None, will predict up to last observed event (t.max()).

Returns

with time-step index, subject IDs (X.index) as columns and point survival as entries

Return type

pd.DataFrame

fit(X: pandas.core.frame.DataFrame, a: pandas.core.series.Series, t: pandas.core.series.Series, y: pandas.core.series.Series, w: Optional[pandas.core.series.Series] = None, fit_kwargs: Optional[dict] = None)[source]

Fits parametric models and calculates internal survival functions.

Parameters
  • X (pd.DataFrame) – Baseline covariate matrix of size (num_subjects, num_features).

  • a (pd.Series) – Treatment assignment of size (num_subjects,).

  • t (pd.Series) – Followup duration, size (num_subjects,).

  • y (pd.Series) – Observed outcome (1) or right censoring event (0), size (num_subjects,).

  • w (pd.Series) – NOT USED (for compatibility only) optional subject weights.

  • fit_kwargs (dict) – Optional kwargs for fit call of survival model

Returns

self