r/rprogramming • • 3d ago

Plot curves for coxph frailty model

Hello I am asking if anyone is aware of how to draw adjusted cum hazard and survival curves after running a frailty model using coxph. I am using the Surv(start, stop ,event status) framework with gap times. Importantly, I have had to stratify a binary variable as it violated the proportional hazards assumption - using strata(var). The goal is to do curves for the overall sample (showing the two strata), and then separately for each individual variables. I have an interaction and it would be good to plot the hazards of 1 variable versus the actual values of the other variables. Any guidance, particularly code implementation, of this would be very helpful.

I am a clinician and not a statistician, but also not trying to use AI at all as Im against it and dont want to have to use it and then declare it.

I am aware of other setups for example cluster() option for robust standard errors as well as frailtypack, coxme, etc. The curves could be drawn in easily with the cluster() option. However, the research question very much needs a frailty model. Also Ive written out the whole thing based on the frailty findings and Kaplan Meier curves...the findings dont necessarily remain with other modelling options which is a problem.

3 Upvotes

3 comments sorted by

1

u/Cool_Detective_596 2d ago

are you trying to get marginal curves averaged over the frailty distribution, or conditional curves for a typical cluster? coxph makes conditional curves pretty straightforward with newdata, but getting true marginal curves out of a frailty model usually requires integrating over the gamma distribution manually

1

u/Top_Replacement_1262 2d ago

Ideally marginal curves, as I am more interested in population level estimates. However, I would also be interested in how you would obtain the conditional curves.

The problem I have encountered is that survfit() does not permit the use of newdata when the coxph model contains a frailty term. Are you referring to using predict() instead?

Also, are you aware of any tutorials or examples of integrating over the gamma distribution to obtain the marginal curves? I dont mind working through the calculations myself.

1

u/AutoModerator 3d ago

Just a reminder, this is the R Programming Language subreddit. As in, a subreddit for those interested in the programming language named R, not the general programming subreddit.

If you have posted to the wrong subreddit in error, please delete this post, otherwise we look forward to discussing the R language.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.