簡體   English   中英

在時間點創建具有生存概率的 Kaplan Meier 圖

[英]Creating a Kaplan Meier plot with Survival probabilities at time points

我正在嘗試在 R 中創建一個圖,該圖將在表中的指定時間點生成一個生存概率表。

目前,情節如下所示:

在此處輸入圖片說明

使用 survminer 包的繪圖的 R 代碼:

ggsurvplot(fit, 
           pval = TRUE, conf.int = TRUE,
           risk.table = TRUE, # Add risk table
           risk.table.col = "strata", # Change risk table color by groups
           linetype = "strata", # Change line type by groups
           ggtheme = theme_bw(), # Change ggplot2 theme
           palette = c("#E7B800", "#2E9FDF"))

理想情況下,我想要“按時間划分的風險數字”下方的表格,以顯示每個層在 250、500、750 和 1000 時間的生存概率。

我可以使用以下代碼檢索生存概率:

summary(fit, times=0:1000)

我為此做了一個功能。 它將 survfit 對象和時間序列作為參數,並返回生存概率。

ConstruirTabela = function(a, sequencia = seq(250,1000,by=250)){

quebra=NULL

for(i in 1:(length(a$time)-1)){
  if(a$time[i] > a$time[i+1]){
    quebra = c(quebra,i)
  }
}
quebra= c(quebra,length(a$time))

lsurv = list()
ltime = list()
previous = 0
for(i in 1:length(quebra)){
  periodo = c((previous+1):quebra[i])
  lsurv[[i]] = a$surv[periodo]
  ltime[[i]] = a$time[periodo]
  previous = quebra[i]
}

matriz=matrix(ncol=length(ltime),nrow=length(sequencia))
for(i in 1:length(sequencia)){
  for(j in 1:length(ltime)){
    indice = which.min(abs(ltime[[j]]-sequencia[i]))
    matriz[i,j] = lsurv[[j]][indice]
    }
}
retorno = as.data.frame(matriz)
f=strsplit(names(a$strata),"=")

names(retorno) = sapply(f, "[[", 2)
rownames(retorno) = as.character(sequencia)

return(retorno)}

這可能不是實現這一目標的最佳方法,但請檢查它是否適合您。

試試這個ggpubr庫。 看看這個頁面的最底部。 它顯示了一個帶有文本表的圖形。

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM