Tapiwanashe Kanda
Tapiwanashe Kanda

Reputation: 21

how can i extract baseline hazards from a coxPHFitter function in Lifelines and the coefficients for my variates

Below is the sample code I got from the documentation website. I want to access the baseline hazards and the coefficients of the variates. '''

from lifelines import CoxPHFitter
from lifelines.datasets import load_rossi

rossi_dataset = load_rossi()


#rossi_dataset.head()
cph = CoxPHFitter()
cph.fit(rossi_dataset, duration_col='week', event_col='arrest',)

cph.print_summary()

'''

Upvotes: 2

Views: 1402

Answers (1)

Cam.Davidson.Pilon
Cam.Davidson.Pilon

Reputation: 1726

From the lifelines docs:

To access the coefficients and the baseline hazard directly, you can use params_ and baseline_hazard_ respectively.

from lifelines import CoxPHFitter
from lifelines.datasets import load_rossi

rossi_dataset = load_rossi()


#rossi_dataset.head()
cph = CoxPHFitter()
cph.fit(rossi_dataset, duration_col='week', event_col='arrest',)

print(cph.params_)

print(cph.baseline_survival_)

Upvotes: 2

Related Questions