Estimating with TwoStagesFitter¤
Estimation¤
In the following we apply the estimation method of Meir et al. (2022). Note that the data dataframe must not contain a column named 'C'.
Standard Error of the Regression Coefficients¤
Regularization¤
It is possible to add regularization when estimating the Beta coefficients. It is done by using the CoxPHFitter (Lifelines) penalizer and l1_ratio arguments, which can be passed using the fit_beta_kwargs argument to the fit() method. The added regularization term is of the form: $$ \mbox{Penalizer} \cdot \Bigg( \frac{1-\mbox{L1_ratio}}{2}||\beta||_{2}^{2} + \mbox{L1_ratio} ||\beta||_1 \Bigg) $$ Examples for adding L1, L2 and Elastic Net regularization are followed.
L1¤
L2¤
Elastic Net¤
Separated Penalty Coefficients¤
The above methods can be applied with a separate penalty coefficient to each of the covariates by passing a vector (with same length as the number of covariates) to the penalizer keyword instead of a scalar. For example, applying L2 regularization only to covariates Z1, Z2 can be done as follows:
Prediction¤
Full prediction is given by the method predict_cumulative_incident_function()
The input is a pandas.DataFrame() containing for each observation the covariates columns which were used in the fit() method (Z1-Z5 in our example).
The following columns will be added:
- The overall survival at each time point t
- The hazard for each failure type \(j\) at each time point t
- The probability of event type \(j\) at time t
- The Cumulative Incident Function (CIF) of event type \(j\) at time t
In the following, we provide predictions for the individuals with ID values (pid) 0, 1 and 2. We transposed the output for easy view.