'Is there a way to "horizontally merge" two Kaplan-Meier curves of the same dataset with two consecutive time-to-event variables?
I have a dataset consisting in observations of the developmental time and survival of an insect.
Developmental time is the time in days between egg exclosure and adult emergence, while survival of adults is the time between adult emergence and death (or censoring).
In my analysis, I am plotting a Kaplan-Meier reversed survival curve (ggsurvplot(survfit_obj, fun = "event")
) for developmental time, while for adult survival I am using a classical Kaplan-Meier curve.
Since I have these two time-to-event variables for every unique individual, I am wondering if there is the possibility to horizontally merge the two resulting Kaplan-Meier curves into a single comprehensive one, or eventually with a different estimator.
Actually, I am not even sure if it has a solid statistical meaning, it just graphically make sense (see last figure).
Keep in mind that the two time-to-events variables are substantially different, they are not representing a single recurrent event.
Below you can find my reproducible example.
Variable legend:
treat -> treatment
days2emerge -> days from egg to adult
new.ad = 1 -> successful adult emergence
days2event -> days from adult emergence to death/censoring
days2event = 1 -> adult death
days2event = 0 -> adult censoring
library(tidyverse)
library(survival)
library(survminer)
#import database
db <- matrix(c("BRA20", "BA84", "BRA20", "BRA20", "BRA20", "BRA20", "BRA20", "BRA20", "BA84", "BRA20", "BA84", "BA84", "BRA20", "BA84", "BRA20", "BA84", "BA84", "BA84", "BRA20", "BA84", "BA84", "BA84", "BRA20", "BRA20", "BA84", "BA84", "BRA20", "BA84", 45, 27, 34, 45, 45, 56, 59, 45, 27, 42, 56, 31, 52, 27, 56, 27, 31, 59, 42, 52, 27, 34, 49, 38, 34, 63, 52, 31, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 29, 50, 11, 14, 17, 35, 14, 39, 35, 14, 35, 7, 43, 35, 50, 21, 32, 17, 11, 11, 25, 51, 28, 15, 7, 25, 14, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0), ncol = 5, byrow = F)
colnames(db) <- c("treat", "days2emerge", "new.ad", "days2event", "death")
db <- as_tibble(db)
db$days2emerge <- as.numeric(db$days2emerge)
db$new.ad <- as.numeric(db$new.ad)
db$days2event <- as.numeric(db$days2event)
db$death <- as.numeric(db$death)
#nymph developmental time
db_devtfit <- survfit(Surv(days2emerge, new.ad) ~ treat, data = db)
np <- ggsurvplot(db_devtfit, data = db, fun = "event", linetype = c("strata"), legend.title = "Groups")
#adult survival
db_survfit <- survfit(Surv(days2event, death) ~ treat, data = db)
sp <- ggsurvplot(db_survfit, data = db, censor.shape = c("X"), linetype = c("strata"), legend.title = "Groups")
Considering this example, is there a way to horizontally merge the two different Kaplan-Meier curves, taking into account the statistics behind it?
A picture to somehow graphically represent what I mean:
Solution 1:[1]
I don't think you can do this natively in ggsurvplot
, but you can strip the data out of your plots and easily build a new one:
np_dat <- np$data.survplot
np_dat$time <- np_dat$time - max(np_dat$time)
np_dat$surv <- 1 - np_dat$surv
df <- rbind(np_dat, sp$data.survplot)
ggplot(df, aes(time, surv, color = strata)) +
geom_step() +
geom_vline(xintercept = 0, linetype = 2) +
theme_classic() +
labs(y = 'probability of being live adult',
x = 'time from emergence')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Allan Cameron |