pythonsurvival-analysislifelines

Lifelines Survival Analysis in Python. What is the partial hazard in that method?


I am trying to use Python Lifelines package to calibrate and use Cox proportional hazard model.

So, the result summary is:

coef  exp(coef)  se(coef)        z      p  lower 0.95  upper 0.95 
PD    -1.1446     0.3183    0.0814 -14.0563 0.0000     -1.3042     -0.9850  ***
oil   -0.1275     0.8803    0.0016 -79.2128 0.0000     -0.1306     -0.1243  ***
curr  -0.1353     0.8735    0.0020 -67.3416 0.0000     -0.1392     -0.1313  ***
matur -0.0002     0.9998    0.0000 -13.6039 0.0000     -0.0002     -0.0002  ***
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Concordance = 0.602

Then i need to calculate partial hazard, for example, using first row of my survival data tab, which is:

PD  oil curr    Durat   binar   matur
0   0.135760    62.799048   59.004243   1.446575    0   179

it must be like that:

PD = 0.13576
oil = 62.799048
curr = 59.004243
matur = 179
np.exp(-1.1446*PD - 0.1275*oil - 0.1353*curr -0.0002*matur)

and equal to 9.387106981409155e-08, so it's very small figure and lead to Survival Probability equal to 1.0 for all t. But when i got a cph.predict_partial_hazard(cox_surv) method it gave me something like 0.32, and this correct figure, i think. For, example we have Baseline SP = 0.7 and by (0.7^0.32) to partial hazard we will get something like 0.892136633056215, it's normal. What is the mistake? How can we calculate partial hazard in a correct way? Thanks a lot!


Solution

  • author of lifelines here.

    The partial hazard in lifelines is computed by first de-meaning the variables, so in lifelines the calculation would like something like

    np.exp(-1.1446*(PD-mean_PD) - 0.1275*(oil-mean_oil) - 
              0.1353*(curr-mean_curr) -0.0002*(matur-mean_matur))
    

    This would probably give you a larger partial hazard (however the relative rank of all subjects stays the same).

    The doc string doesn't mention this, however, I'll fix that for v0.15.0.