简体   繁体   中英

How can I visualize an interaction in cox model in r?

I fitted a model and had a significant interaction effect. How can I plot this in a graphic?

It follows a toy example (only for illustration purposes):

library(survival)
# includes bladder data set
library(survminer)
fit2 <- coxph(Surv(stop, event) ~ rx*enum, data = bladder )
# It plots only one single curve
ggadjustedcurves(fit2, data = bladder, variable = "rx")

I would like something like these:

ggadjustedcurves(fit2, data = bladder, variable = "rx") +
  facet_wrap(~enum)
ggadjustedcurves(fit2, data = bladder, variable = c("enum","rx"))

It would be nice that the answer would work both for categoricalxcategorical interaction and categorical versus continuous interaction.

Categorical x categorical

If you consider your variables categorical, in variable "rx" you have 2 groups and in variable "enum" 4 groups, which gives you a total of 8 curves.

(1) One way to visualize them would be to plot all curves on the same graph:

bladder$rx_enum <- paste(as.character(bladder$rx), as.character(bladder$enum), sep="_")
ggadjustedcurves(fit2, data = bladder, method='average', variable = "rx_enum")

This is probably not the most elegant way, and you would also have to adjust the colours/linetypes to look nicer. I would probably try to set the line type according to "rx" and color according to "enum" in this case. Modifying color is relatively easy with palette -argument:

ggadjustedcurves(fit2, data = bladder, method='average', palette = c(1,2,3,4,1,2,3,4), variable = "rx_enum")

...while modifying line type is probably more tricky.

(2) Obviously, you can also make separate panels for different levels of either of variables. With "rx" variable you´ll have a panel for dataframe subset where "rx"==1 and another where "rx"==2. I probably wouldn´t use separate panels/graphs because you can visually represent all of the information on one plot - unless it is necessary/justified by your narrative. But if you want to go that way, let me know.

Categorical x Continuous

The same approach will work with continuous variable as well, if you categorize it. I am not sure how one could make a KM for continuous variable while keeping it continuous (not sure how it is even possible).

NB: This answer considered only the KM-plots which are the most common for survival analysis, but there are probably other options as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM