Survivalanalyse in Python
Shae Wang
Senior Data Scientist
Hazardfunctie $h(t)$: kans dat het event optreedt op tijd t, gegeven overleving tot dan.
Hazardrate: het instantane tempo waarop het event optreedt
$$h(t)=-\frac{d}{dt}logS(t)$$
De hazardfunctie $h(t)$ en de overlevingsfunctie $S(t)$ zijn wederzijds afleidbaar.
De proportional hazards‑aanname: alle individuele hazards zijn proportioneel aan elkaar.
Voor individu $A$ en $B$: $$h_A(t)=c h_B(t)$$

Gebaseerd op de proportional hazards‑aanname: $$h(t|x)=b_0(t)exp\bigg(\sum^{n}_{i=1}b_i(x_i-\overline{x_i}\bigg)$$
$b_0(t)$: baseline‑hazard op populatieniveau, verandert met de tijd.
$exp\bigg(\sum^{n}_{i=1}b_i(x_i-\overline{x_i}\bigg)$: lineair verband tussen covariaten en de log‑hazard, verandert NIET met de tijd.
CoxPHFitter aanfrom lifelines import CoxPHFitter
coxph = CoxPHFitter()
.fit() aan om het model te trainencoxph.fit(df, duration_col, event_col)
coxph.summary()
coxph.predict()
mortgage_dfhouseprincipal interest property_taxcredit_scoreduration, paid_offfrom lifelines import CoxPHFittercoxph = CoxPHFitter() coxph.fit(df=mortgage_df, duration_col="duration", event_col="paid_off")
Filter het DataFrame:
new_df = mortgage_df.loc[:,
mortgage_df.columns!="house"]
coxph.fit(df=new_df,
duration_col="duration",
event_col="paid_off")
Gebruik de parameter formula:
coxph.fit(df=mortgage_df,
duration_col="duration",
event_col="paid_off",
formula="principal + interest
+ property_tax + credit_score")
print(coxph.summary)
<lifelines.CoxPHFitter: fitted with 1808 observations, 340 censored>
coef exp(coef) se(coef) z p
covariate house -0.38 0.68 0.19. -1.98 0.05
principal -0.06 0.94 0.02 -2.61 0.01
interest 0.31 1.37 0.31 1.02 0.31
property_tax -0.15 0.86 0.21 -0.71 0.48
credit_score -0.43 0.65 0.38 -1.14. 0.26
interest vanaf de mediaan -> de hazard verandert met factor $e^{0.31}=1.37$, dus 37% hoger dan de baseline.Survivalanalyse in Python