causallib.survival.weighted_survival module

class causallib.survival.weighted_survival.WeightedSurvival(weight_model: Optional[causallib.estimation.base_weight.WeightEstimator] = None, survival_model: Optional[Any] = None)[source]

Bases: causallib.survival.base_survival.SurvivalBase

Weighted survival estimator

Weighted survival estimator. :param weight_model: causallib compatible weight model (e.g., IPW) :param survival_model: Three alternatives:

  1. None - compute non-parametric KaplanMeier survival curve

  2. Scikit-Learn estimator (needs to implement predict_proba) - compute parametric curve by fitting a

    time-varying hazards model

  3. lifelines UnivariateFitter - use lifelines fitter to compute survival curves from events and durations

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

Returns population averaged survival curves.

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|int) – Followup durations, size (num_subjects,).

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

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

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

Returns

with timestep index, treatment values as columns and survival as entries

Return type

pd.DataFrame

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

Fits internal weight module (e.g. IPW module, adversarial weighting, etc).

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) – NOT USED (for compatibility only)

  • y (pd.Series) – NOT USED (for compatibility only)

  • fit_kwargs (dict) – Optional kwargs for fit call of survival model (NOT USED, since fit call of survival model occurs in ‘estimate_population_outcome’ rather than here)

Returns

self