0
$\begingroup$

I want to write a code that calculates the Cox Proportional Hazard rate:

$h(t|x_it,e_i)=e^{x_it \beta + \lambda(t) + e_i}$

where $\lambda_t$ is a spline in slopes and $e_i$ is an unobserved term. My data includes age,status,health variables of people. I am pretty new in the topic so I wonder what is the best way to do this. Specifically, if I can use the data to calculate a survival function and start from there. I know there are packages in R and python for this but I need to do the coding from scratch.

$\endgroup$

1 Answer 1

1
$\begingroup$

Short answer: Just code the likelihood function and maximize it using python or R.

Herndon and Harrell show the log-likelihood for a proportional hazards model with a restricted cubic spline for the baseline hazard in Equation 9. Royston and Parmer show likelihoods for spline-based proportional hazards and proportional odds models in Section 3.4. The choice of knot locations for the splines is not done by maximum likelihood, however. That's done with respect to the distribution of event times, as described in those papers.

The Royston-Parmer approach is implemented as part of the flexsurv package in R. It's not clear why you "need to do the coding from scratch," but the code in that package should help show the way.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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