# 1. Import Dependencies and Dataset
from lifelines import CoxPHFitter
from lifelines.datasets import load_rossi
import maketables as mt
rossi = load_rossi()
# 2. Fit Stratified Cox Proportional Hazards Model
cph = CoxPHFitter()
cph.fit(rossi, duration_col="week", event_col="arrest")
# Define variable labels based on Rossi et al. (1980)
labels = {
"fin": "Financial Aid",
"age": "Age at Release",
"race": "Black",
"wexp": "Prior Work Experience",
"mar": "Married",
"paro": "On Parole",
"prio": "Prior Convictions",
"arrest": "Arrest Event",
}
# Create table with Hazard Ratios
mt.ETable(cph, labels=labels, coef_fmt="hr* \n (se)")| Arrest Event | |
|---|---|
| (1) | |
| coef | |
| Financial Aid | 0.684** (0.191) |
| Age at Release | 0.944*** (0.022) |
| Black | 1.369 (0.308) |
| Prior Work Experience | 0.861 (0.212) |
| Married | 0.648 (0.382) |
| On Parole | 0.919 (0.196) |
| Prior Convictions | 1.096*** (0.029) |
| stats | |
| Observations | 432 |
| Events | 114 |
| Concordance | 0.64 |
| Log-likelihood | -658.748 |
| Significance levels: * p < 0.1, ** p < 0.05, *** p < 0.01. Format of coefficient cell: Hazard Ratio (Std. Error) | |