Estimation of Survival Function
Estimation of Survival Function
: 02
BSCST-511T Date: 03/08/224
Practical Name: Estimation of Survival Function.
Name:
install.packages("survival")
> #Q.3)
>
> event_times <- c(8, 12, 16, 20, 24)
> number_of_deaths <- c(2, 1, 3, 1, 2)
>
> #Create a survival object
>
> surv_obj <- Surv (time = event_times, event = number_of_deaths) Warning
message:
In Surv(time = event_times, event = number_of_deaths) :
Invalid status value, converted to NA
>
> # Fit the Kaplan-Meier estimator
> km_fit <- survfit(surv_obj ~ 1)
> km_fit
Call: survfit(formula = surv_obj ~ 1)