library(knitr) opts_chunk$set( comment = "", message = FALSE, warning = FALSE, tidy.opts = list( keep.blank.line = TRUE, width.cutoff = 150 ), options(width = 150), eval = TRUE )
In general case it may be tricky to automatically extract interactions or variable transformations from model objects. A suggestion would be to create manually new variables that capture desired effects of interactions and add them to the model in an explicit way. This article describe an example of how to do this.
library(survminer) library(survival)
res.cox <- coxph(Surv(time, status) ~ ph.karno * age, data=lung) summary(res.cox, conf.int = FALSE)
Visualization of the hazard ratios using the function ggforest()
.
ggforest(res.cox, data = lung)
On the plot above, it can be seen that ggforest()
ignores the interaction term ph.karno:age
.
To fix this, a solution is to create manually the variable that handles the interaction:
lung$ph.karno_age <- lung$ph.karno * lung$age
and now you can fit an additive model and the ggforest()
function will include it in the plot:
res.cox2 <- coxph(Surv(time, status) ~ ph.karno + age + ph.karno_age, data = lung) summary(res.cox2 , conf.int = FALSE)
ggforest(res.cox2, data=lung)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.