RobinDenz1 / contsurvplot

An R-Package to Visualize the (Causal) Effect of a Continuous Variable on a Time-To-Event Outcome
https://robindenz1.github.io/contsurvplot/
GNU General Public License v3.0
12 stars 1 forks source link

Compatibility with Mixed Effects Survival Models (coxme(Surv())) #5

Closed Lassehhansen closed 1 year ago

Lassehhansen commented 1 year ago

Hi,

Firstly, I'd like to express my appreciation for this package. It's been incredibly useful and I'm grateful for your contribution.

Issue: I've been trying to use the package with mixed effects survival models, specifically models built with coxme(Surv()). You can find more about coxme(Surv()) here.

Error Encountered: When I attempted to use it as is, I encountered the following error:

' Error in check_inputs_curve_cont(data = data, variable = variable, group = group, : The 'variable' argument needs to be included as independent variable in the 'model' object. '

Request: Is there a possibility to enhance the package to be compatible with mixed effects survival models like coxme(Surv())?

Thank you!

RobinDenz1 commented 1 year ago

Thank you for the kind words.

It is absolutely possible to use the coxme model in this package. It would require you to do some coding though. Internally, the contsurvplot package calls the predictRisk function from the riskRegression package to obtain the required survival probability predictions given the model and a vector of covariates. That function supports quite a lot of models (see ?predictRisk), but it currently has no method for coxme objects.

The predictRisk function is a generic function, meaning you can write your own method for any model you want to use. If you want support for coxme models all you need to do is write a function called predictRisk.coxme that takes as input a coxme model, newdata (a dataset for which predictions should be made) and times (the points in time for which predictions should be made). This function should return a matrix with each row corresponding to individuals and each column corresponding to a single point in time, filled with cumulative incidence predictions (1 - S(t, X)). Maybe the predict.coxme function could be used to write such a method.

If you write such a function, the maintainers of the riskRegression function would probably be happy to include it in their package too.

Alternatively, you could use a frailty() term in a standard coxph call and use this model directly without having to do any of this work.