# CPH Model full likelihood estimation #812

Closed
opened this issue Aug 27, 2019 · 2 comments
Closed

# CPH Model full likelihood estimation#812

opened this issue Aug 27, 2019 · 2 comments
Labels

### sursu commented Aug 27, 2019 • edited

 As I understand, CPH Models are estimated in 2 steps: Estimation of the regression parameters from the partial likelihood Compute the baseline hazard rates [using Breslow (1974) or Kaplan&Meier(1958)] Alternatively, this can be done in one step using a full likelihood estimation if the baseline hazard function can be parameterized. Popular examples are the exponential, Weibull, and Gompertz distributions. This is a suggestion to include these distributions in the `CoxPHFitter`, and add a new argument which would specify the distribution of the baseline hazard function. If passed then use the full likelihood estimation approach, else do it in 2 steps. This statement may be used to test the implementation: CPH models are identical to AFT models if the baseline hazard rate is Weibull distributied in a full likelihood estimation.

### CamDavidsonPilon commented Aug 27, 2019

 Yea, I really like this addition!
added the label Aug 27, 2019

### CamDavidsonPilon commented Nov 19, 2019 • edited

 I believe this is already available in lifelines, using custom models: https://lifelines.readthedocs.io/en/latest/jupyter_notebooks/Custom%20Regression%20Models.html For example, here's a Weibull baseline: ```class CPHWeibull(ParametricRegressionFitter): _fitted_parameter_names = ["lambda_", "rho_", "beta_"] def _cumulative_hazard(self, params, T, Xs): lambda_ = np.exp(np.dot(Xs["lambda_"], params["lambda_"])) rho_ = np.exp(np.dot(Xs["rho_"], params["rho_"])) weibull_baseline = (T / lambda_)**rho_ ph = np.exp(np.dot(Xs["beta_"], params["beta_"])) return weibull_baseline * ph cph = CPHWeibull(penalizer=.1) rossi = load_rossi() rossi["intercept"] = 1.0 covariates = {"beta_": rossi.columns, "rho_": ["intercept"], "lambda_": rossi.columns[1::2]} cph.fit(rossi, "week", event_col="arrest", regressors=covariates, timeline=np.arange(250)) cph.print_summary(2)```