Código
library(survival)
library(KMsurv)
library(survminer)
library(ggfortify)
library(flexsurv)
library(actuar)
library(dplyr)
library(knitr)
library(kableExtra)Aplicación del análisis de supervivencia utilizando el conjunto de datos tongue
El análisis de supervivencia constituye una herramienta fundamental para estudiar el tiempo transcurrido hasta la ocurrencia de un evento de interés.
Survival analysis is a fundamental statistical methodology for studying time-to-event data.
El análisis de supervivencia permite modelar el tiempo transcurrido hasta la ocurrencia de un evento de interés Kleinbaum y Klein (2012).
Los datos censurados son una característica distintiva de este tipo de estudios Klein y Moeschberger (2003).
El estimador no paramétrico más utilizado para estimar la función de supervivencia es el propuesto por Kaplan y Meier (1958).
Para comparar curvas de supervivencia entre grupos suele emplearse la prueba Log-Rank propuesta por Mantel (1966).
La implementación computacional se realizó mediante el paquete survival de R Therneau (2024) y la visualización mediante survminer Kassambara, Kosinski, y Biecek (2024).
\[ S(t)=P(T>t) \]
\[ \hat S(t)=\prod_{t_i\leq t}\left(1-\frac{d_i}{n_i}\right) \]
library(survival)
library(KMsurv)
library(survminer)
library(ggfortify)
library(flexsurv)
library(actuar)
library(dplyr)
library(knitr)
library(kableExtra)data("tongue")
head(tongue) type time delta
1 1 1 1
2 1 3 1
3 1 3 1
4 1 4 1
5 1 10 1
6 1 13 1
| Variable | Descripción |
|---|---|
| type | Tipo de tumor |
| time | Tiempo de seguimiento |
| delta | Indicador del evento |
tongue %>%
summarise(
n = n(),
tiempo_promedio = mean(time),
tiempo_mediana = median(time),
tiempo_maximo = max(time)
) %>%
kable(caption = "Estadísticas descriptivas generales")| n | tiempo_promedio | tiempo_mediana | tiempo_maximo |
|---|---|---|---|
| 80 | 73.825 | 69.5 | 400 |
objeto_surv <- Surv(
time = tongue$time,
event = tongue$delta
)
objeto_surv [1] 1 3 3 4 10 13 13 16 16 24 26 27 28 30 30
[16] 32 41 51 65 67 70 72 73 77 91 93 96 100 104 157
[31] 167 61+ 74+ 79+ 80+ 81+ 87+ 87+ 88+ 89+ 93+ 97+ 101+ 104+ 108+
[46] 109+ 120+ 131+ 150+ 231+ 240+ 400+ 1 3 4 5 5 8 12 13
[61] 18 23 26 27 30 42 56 62 69 104 104 112 129 181 8+
[76] 67+ 76+ 104+ 176+ 231+
El estimador de Kaplan-Meier fue propuesto por Kaplan y Meier (1958).
fit <- survfit(
Surv(time, delta) ~ type,
data = tongue
)
fitCall: survfit(formula = Surv(time, delta) ~ type, data = tongue)
n events median 0.95LCL 0.95UCL
type=1 52 31 93 67 NA
type=2 28 22 42 23 112
p <- ggsurvplot(
fit,
data = tongue,
conf.int = TRUE,
pval = TRUE,
risk.table = TRUE,
risk.table.height = 0.25,
palette = c("#D55E00", "#0072B2"),
ggtheme = theme_bw(),
legend.title = "Tipo de Tumor",
legend.labs = c("Tipo 1", "Tipo 2")
)
plogrank <- survdiff(
Surv(time, delta) ~ type,
data = tongue
)
pvalor <- 1 - pchisq(
logrank$chisq,
length(logrank$n)-1
)
pvalor[1] 0.0948707
La curva correspondiente al grupo de tumor tipo 1 permanece por encima de la curva del grupo tipo 2 durante gran parte del seguimiento.
Los resultados obtenidos son consistentes con los procedimientos descritos por Therneau y Grambsch (2000) y Lee y Wang (2013).
sessionInfo()R version 4.6.0 (2026-04-24 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 26200)
Matrix products: default
LAPACK version 3.12.1
locale:
[1] LC_COLLATE=Spanish_Mexico.utf8 LC_CTYPE=Spanish_Mexico.utf8
[3] LC_MONETARY=Spanish_Mexico.utf8 LC_NUMERIC=C
[5] LC_TIME=Spanish_Mexico.utf8
time zone: America/Ciudad_Juarez
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] kableExtra_1.4.1 knitr_1.52 dplyr_1.2.1 actuar_3.3-7
[5] flexsurv_2.3.2 ggfortify_0.4.24 survminer_0.5.2 ggpubr_1.0.0
[9] ggplot2_4.0.3 KMsurv_0.1-6 survival_3.8-6
loaded via a namespace (and not attached):
[1] gtable_0.3.6 xfun_0.57 htmlwidgets_1.6.4
[4] rstatix_1.1.0 lattice_0.22-9 numDeriv_2016.8-1.1
[7] quadprog_1.5-8 vctrs_0.7.3 tools_4.6.0
[10] generics_0.1.4 tibble_3.3.1 pkgconfig_2.0.3
[13] Matrix_1.7-5 data.table_1.18.6.1 RColorBrewer_1.1-3
[16] S7_0.2.2 lifecycle_1.0.5 compiler_4.6.0
[19] farver_2.1.2 stringr_1.6.0 textshaping_1.0.5
[22] statmod_1.5.2 carData_3.0-6 mstate_0.3.3
[25] litedown_0.9 htmltools_0.5.9 yaml_2.3.12
[28] Formula_1.2-6 pillar_1.11.1 car_3.1-5
[31] tidyr_1.3.2 muhaz_1.2.6.5 abind_1.4-8
[34] commonmark_2.0.0 tidyselect_1.2.1 digest_0.6.39
[37] mvtnorm_1.4-2 stringi_1.8.7 purrr_1.2.2
[40] labeling_0.4.3 splines_4.6.0 fastmap_1.2.0
[43] grid_4.6.0 cli_3.6.6 magrittr_2.0.5
[46] broom_1.0.13 withr_3.0.3 scales_1.4.0
[49] backports_1.5.1 rmarkdown_2.31 ggtext_0.2.0
[52] otel_0.2.0 gridExtra_2.3.1 deSolve_1.42
[55] ggsignif_0.6.4 expint_0.2-1 evaluate_1.0.5
[58] viridisLite_0.4.3 markdown_2.0 rlang_1.2.0
[61] gridtext_0.1.6 Rcpp_1.1.1-1.1 glue_1.8.1
[64] xml2_1.5.2 svglite_2.2.2 rstudioapi_0.18.0
[67] jsonlite_2.0.0 R6_2.6.1 systemfonts_1.3.2