#Paquetes
library(readxl) library(dplyr)
library(survival)
tabla_vida <- read_excel(“Tablas de Vida.xlsx”)
View(tabla_vida)
tabla_vida\(Nacimiento <- as.Date(tabla_vida\)Nacimiento) tabla_vida\(Muerte <- as.Date(tabla_vida\)Muerte)
tabla_vida\(Nacimiento <- as.Date(tabla_vida\)Nacimiento) tabla_vida\(Muerte <- as.Date(tabla_vida\)Muerte)
tabla_vida\(edad_muerte <- ifelse( is.na(tabla_vida\)Muerte), as.numeric(difftime(Sys.Date(), tabla_vida\(Nacimiento, units = "days")), as.numeric(difftime(tabla_vida\)Muerte, tabla_vida$Nacimiento, units = “days”)) )
supervivencia_general <- Surv( time = tabla_vida\(edad_muerte / 365, event = !is.na(tabla_vida\)Muerte) )
km_general <- survfit(supervivencia_general ~ 1)
plot(km_general, main = “Curva de supervivencia general”, xlab = “Edad (anhos)”, ylab = “Probabilidad de supervivencia”, col = “black”, lwd = 2)
##Curva de supervivencia de hombres tabla_vida_h <- tabla_vida %>% filter(Sexo == “M”)
supervivencia_h <- Surv( time = tabla_vida_h\(edad_muerte / 365, event = !is.na(tabla_vida_h\)Muerte) )
km_h <- survfit(supervivencia_h ~ 1)
plot(km_h, main = “Curva de supervivencia hombres”, xlab = “Edad (anhos)”, ylab = “Probabilidad de supervivencia”, col = “purple”, lwd = 2)
##Curva de supervivencia de mujeres {r} tabla_vida_m <- tabla_vida %>% filter(Sexo == “F”)
{r} supervivencia_m <- Surv( time = tabla_vida_m\(edad_muerte / 365, event = !is.na(tabla_vida_m\)Muerte) )
km_m <- survfit(supervivencia_m ~ 1)
plot(km_m, main = “Curva de supervivencia mujeres”, xlab = “Edad (anhos)”, ylab = “Probabilidad de supervivencia”, col = “green”, lwd=2)