2

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!

Mohamed Thasin ah
  • 10,754
  • 11
  • 52
  • 111

1 Answers1

1

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.

Cam.Davidson.Pilon
  • 1,606
  • 1
  • 17
  • 31
  • @TrueElement, can you check this as the correct answer? That way others will have an easier time finding the solution to your problem. – Cam.Davidson.Pilon Nov 06 '18 at 17:28
  • hello! Can u help me one more time. When we are using CoxTimeVaryingFitter for time depending covariates how can we get a baseline cummulative hazard rate λ_0(t) for that method? It needs to calculate integrals of X(t) trajectories for survival function. Thanks a lot! – – TrueElement Nov 29 '18 at 18:04
  • the baseline cumulative hazard is hard to interpret for that reason, and I typically avoid using it. Is there a reason you need the baseline hazard rate? – Cam.Davidson.Pilon Nov 29 '18 at 18:19
  • The idea is: if we have estimation for vector β, baseline cummulative hazard rate λ_0(t), then we can choose a point of time- t* and for a subject predict its survival function by integrating all realized piecewise determined x(t) covariates and λ_0(t) for t <= t*- that is S(t*), then calculate S(t* +Δt) by integrating again λ_0(t) and scenario value of x(t) for t > t*, and at the end we get conditional on x(t) S(t) probability for predictive time period. But its not clear what an λ_0(t) estimation for cox time dependent should be – TrueElement Nov 29 '18 at 19:30
  • I get it - so is your question about how lifelines calculates it? – Cam.Davidson.Pilon Nov 29 '18 at 20:04
  • Yes, is there any method in lifeline to calculate baseline cumulative hazard rate for cox model? And if there is not can u suggest any correct approach to estimate only baseline hazard for cox with time dependent covariates?– – TrueElement Nov 30 '18 at 04:40
  • For example, can we use nelson aalen estimator of BHR for that purpose or it should be specific consistent with a cox time deprndent model BHR edtimator. I am not sure about it.. – TrueElement Nov 30 '18 at 04:56