0
$\begingroup$

I am trying to plug the regression coefficients back into the cox ph model to manually find the partial hazard of the model, but am getting mixed results. I am using the lifelines python library for Cox PH.

enter image description here

For one observation:

The partial_hazard is the product the lifelines python library outputted. Each variable below is the sum of the observed value for xi * coefficient B.

partial_hazard = 0.606
n1 = 29835.02039 * 0.398
n2 = 3.949135 * 0.145
n3 = 0.477231 * 0.18
n4 = 123.658238 * -0.21
n5 = -0.771495 * 0.134
n6 = 0.750476 * -0.124

If I plug in the values from above it returns inf

np.exp(n1 + n2 + n3 + n4 + n5 + n6)

The baseline hazard = 0.001 according to the lifelines library.

To get the hazard h(t|x):

0.001 * np.exp(n1 + n2 + n3 + n4 + n5 + n6)

However, the sum (above) does not equal partial_hazard = np.log(0.606)

Is this logic correct? Any practical input would be appreciated.

$\endgroup$
1
$\begingroup$

I can't speak to lifelines-specific issues (software per se is generally off-topic on this site), but there are a few things you need to double-check and understand in general.

First, your n1 predictor has an outrageously high contribution to the log-partial hazard sum (the linear predictor from the model), leading to the overflow. Check that for a coding or scaling error, along with n4 (which is only extremely high). (A summed linear predictor value of only 2 means a hazard ratio greater than 7, which is quite high in my experience. On that basis, there's something terribly wrong with n1 and n4, maybe something like perfect separation in logistic regression.)

Second, the baseline hazard is a function of time. The only exception is if you have an exponential survival curve, in which case the baseline hazard is constant over time. I'm not sure just what the single value you report for "baseline hazard" represents.

Third, calculations involving baseline hazard for a Cox model typically originate in practice from the cumulative hazard over time rather than the instantaneous hazard at a specific time (even if explanation of the Cox model is typically done from the perspective of instantaneous hazard). A baseline cumulative hazard over time is straightforward to get once you have your Cox model. The (unsmoothed) instantaneous baseline hazard is then 0 except at an event time, when it's the change in cumulative baseline hazard at that time. See for example this answer, whose symbols are defined more fully in this answer.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.