I had drawn kaplan meier plot for stanford heart transplant data.
library(tidyverse)
library(survival)
library(survminer)
library(flexsurv)
library(readxl)
data=read_excel("Desktop/stanford_heart_transplant_dataset_full.xlsx")
data
names(data)
data_log <- data %>%
mutate(log_time = log(SURVIVAL_TIME))
data_log$log_time
names(data_log)[enter image description here][1]
survobj2_new=Surv(data_log$log_time, data_log$SURVIVAL_STATUS);survobj2_new
KM_new=survfit(survobj2_new~1,data_log);KM_new
p=ggsurvplot(KM_new, data = data_log, time = "log_time", conf.int = FALSE)
p
Next I had drawn survival plot for the LOLLW with the estimated parameters
t1=data_log$log_time;t1
t2=data_log$AGE;t2
t3=data_log$PRIOR_SURGERY;t3
t4=data_log$TRANSPLANT_STATUS;t4
alpha <- 4.6
sigma <- 6.2
b0 <- 8.7
b1 <- -0.07
b2 <- 1.4
b3 <- 2.5
surv_function=function(alpha,sigma,b0,b1,b2,b3)
{
y=data_log$log_time
z=(y-b0-b1*t2-b2*t3-b3*t4)/sigma;
u2=exp(-exp(z))
l2=(1-(((1-u2)^alpha)/(((1-u2)^alpha)+((u2)^alpha))))
return(l2)[enter image description here][1]
}
x=data_log$log_time
y=surv_function(4.6,6.2,8.7,-0.07,1.4,2.5)
data <- data.frame(x = x, y = y)
p1=ggplot(data_log, aes(x = x, y = y)) +
geom_smooth()
p1
Now I tried multiple ways to merge these two plot.I would like to get a sample plot like belowenter image description here.How to get the plots merged into a single plot.