Introduction
Survival analysis studies time-to-event data. It's common in medical research and reliability engineering.
Survival Objects
library(survival)
# Create survival object
surv_obj <- Surv(time, event)
# With censoring
surv_obj <- Surv(time, event == 1)
Kaplan-Meier Estimate
# Fit model
km_fit <- survfit(Surv(time, event) ~ group, data = df)
# Print summary
summary(km_fit)
# Plot
plot(km_fit)
Log-Rank Test
# Compare groups
survdiff(Surv(time, event) ~ group, data = df)
Cox Proportional Hazards
# Fit model
cox_model <- coxph(Surv(time, event) ~ vars, data = df)
# Summary
summary(cox_model)
# Plot
ggsurvplot(survfit(cox_model))
Summary
Survival analysis handles censored data. Use Kaplan-Meier for estimates and Cox for regression.