3

I am attempting to create an adjusted survival curve (from a Cox model) and would like to display this information as cumulative events.

I have attempted this:

library(survival)
data("ovarian")
library(survminer)

model<-coxph(Surv(futime, fustat) ~ age + strata(rx), data=ovarian)

gplot<-ggadjustedcurves(model) ## Expected plot of adjusted survival curve

Because the "fun=" still has not been implemented in ggadjustedcurves I took the advice of a user on this page and extracted the elements into plotdata and created a new column as shown below.

plotdata<-gplot$data
plotdata%<>%
  mutate(new=1-surv) ## 1-survival probability

I am new to R environment and ggplot so how can I then plot the new adjusted survival curve with the new created column and keep the theme of the original plot (contained in gplot).

Thanks!

Edit:

My current solution is as follows.

library(rms)
model<-coxph(Surv(futime, fustat) ~ age+ strata(rx), data=ovarian)

survfit(model, conf.type = "plain", conf.int = 1)
plot(survfit(model), conf.int = T,col = c(1,2), fun='event')

This achieves the survival curve I wanted however I am not sure if the confidence bars are really the standard errors (+/-1). I supplied 1 to the conf.int argument and believe this to create the standard errors in this way since conf.type is specified as plain.

How can I further customize this plot as the base graph looks rather bland! How do I get a display as close as possible to the survminer curves?

mindhabits
  • 421
  • 1
  • 3
  • 10
  • 1
    I get a warning on the creation of the -object. I also do not see any use of functions from the `rms` package. Both `survfit` and `plot.survfit` are from package `survival`. (This information might or might not be essential, since loading `rms` will probably load `survival`, but it clarifies where to find the proper help pages.) The usual convention is to plot confidence boundaries at `1.96*(+/-se)`. – IRTFM Aug 11 '19 at 17:16

1 Answers1

0

You can use the adjustedCurves package instead, which allows both plotting confidence intervals and naturally includes an option to display cumulative incidence functions. First, install it using:

devtools::install_github("https://github.com/RobinDenz1/adjustedCurves")

Now you can use:

library(adjustedCurves)
library(survival)
library(riskRegression)

# needs to be a factor
ovarian$rx <- factor(ovarian$rx)

# needs to include x=TRUE
model <- coxph(Surv(futime, fustat) ~ age + strata(rx), data=ovarian, x=TRUE)

adj <- adjustedsurv(data=ovarian,
                    event="fustat",
                    ev_time="futime",
                    variable="rx",
                    method="direct",
                    outcome_model=model,
                    conf_int=TRUE)
plot(adj, cif=TRUE, conf_int=TRUE)

Which produces: example_ovarian

I would probably not use this method here, though. Simulation studies have shown that the cox-regression based method performs badly in small sample sizes. You might want to take a look at method="iptw" or method="aiptw" inside the adjustedCurves package instead.

Denzo
  • 240
  • 1
  • 7