2017-04-11 2 views
0

Je voudrais ajuster une courbe de Weibull à certaines données d'événement, puis inclure la courbe de Weibull ajustée dans un graphique de survie tracé par survminer :: ggsurvplot. Des idées de comment? Voici un exemple pour travailler sur:Intégration de weibull dans ggsurvplot

Une fonction de simulation de données weibull:

# N = sample size  
# lambda = scale parameter in h0() 
# rho = shape parameter in h0() 
# beta = fixed effect parameter 
# rateC = rate parameter of the exponential distribution of C 

simulWeib <- function(N, lambda, rho, beta, rateC) 
{ 
    # covariate --> N Bernoulli trials 
    x <- sample(x=c(0, 1), size=N, replace=TRUE, prob=c(0.5, 0.5)) 

    # Weibull latent event times 
    v <- runif(n=N) 
    Tlat <- (- log(v)/(lambda * exp(x * beta)))^(1/rho) 

    # censoring times 
    C <- rexp(n=N, rate=rateC) 

    # follow-up times and event indicators 
    time <- pmin(Tlat, C) 
    status <- as.numeric(Tlat <= C) 

    # data set 
    data.frame(id=1:N, 
      time=time, 
      status=status, 
      x=x) 
} 

générer des données

set.seed(1234) 
betaHat <- rep(NA, 1e3) 
for(k in 1:1e3) 
{ 
    dat <- simulWeib(N=100, lambda=0.01, rho=1, beta=-0.6, rateC=0.001) 
    fit <- coxph(Surv(time, status) ~ x, data=dat) 
    betaHat[k] <- fit$coef 
} 

#Estimate a survival function 
survfit(Surv(as.numeric(time), x)~1, data=dat) -> out0 

#plot  

library(survminer) 
ggsurvplot(out0, data = dat, risk.table = TRUE) 

gg1 <- ggsurvplot(
    out0,      # survfit object with calculated statistics. 
    data = dat, # data used to fit survival curves. 
    risk.table = TRUE,  # show risk table. 
    pval = TRUE,    # show p-value of log-rank test. 
    conf.int = TRUE,   # show confidence intervals for 
    # point estimaes of survival curves. 
    xlim = c(0,2000),  # present narrower X axis, but not affect 
    # survival estimates. 
    break.time.by = 500,  # break X axis in time intervals by 500. 
    ggtheme = theme_minimal(), # customize plot and risk table with a theme. 
    risk.table.y.text.col = T, # colour risk table text annotations. 
    risk.table.y.text = FALSE, 
    surv.median.line = "hv", 
    color = "darkgreen", 
    conf.int.fill = "lightblue", 
    title = "Survival probability",# show bars instead of names in text annotations 
    # in legend of risk table 
) 
gg1 

enter image description here

Répondre

0

Pour autant que je vois cela, il est impossible de le faire avec ggsurvplot en ce moment.

J'ai créé une question demandant cette fonction: https://github.com/kassambara/survminer/issues/276

Vous pouvez tracer les courbes de survie d'un modèle Weibull avec ggplot2 comme ceci:

library("survival") 
wbmod <- survreg(Surv(time, status) ~ x, data = dat) 
s <- seq(.01, .99, by = .01) 
t_0 <- predict(wbmod, newdata = data.frame(x = 0), 
       type = "quantile", p = s) 
t_1 <- predict(wbmod, newdata = data.frame(x = 1), 
       type = "quantile", p = s) 

smod <- data.frame(time = c(t_0, t_1), 
        surv = rep(1 - s, times = 2), 
        strata = rep(c(0, 1), each = length(s)), 
        upper = NA, lower = NA) 

head(surv_summary(cm)) 

library("ggplot2") 
ggplot() + 
    geom_line(data = smod, aes(x = time, y = surv, color = factor(strata))) + 
    theme_classic() 

enter image description here Cependant, à ma connaissance, vous ne pouvez pas utiliser survminer (encore):

library("survminer") 

# wrong: 
ggsurvplot(smod) 

# does not work: 
gg1$plot + geom_line(data = smod, aes(x = time, y = surv, color = factor(strata)))