Survival analysis

Survival analysis is a statistical method used to analyze time-to-event data, such as time to death or time to failure. It is commonly used in fields such as medical research and engineering, where the goal is to understand the factors that influence the occurrence of a specific event.

For example, in pesticide research, survival analysis can be used to study the effects of pesticides on the survival of organisms. For example, researchers may use survival analysis to determine the effect of a pesticide on the survival of bees or other pollinators.

To perform survival analysis in R, the package “survival” can be used. This package provides a wide range of functions for fitting and analyzing survival data, including the popular Kaplan-Meier estimator for estimating survival probabilities.

# Survival analysis in R
# Load library (install first if needed)
library(survival)
library(survMisc)
# create a sample data set
data <- lung
# fit a survival model
fit <- survfit(Surv(time, status) ~ sex, data = data)
# print the summary of the model
summary(fit)
# plot the survival curve
autoplot(fit,
timeTicks = "custom", times = seq(1, 1000, 100),
plotTable = TRUE,
CI = TRUE,
bands = TRUE)
# compare survival curves
result <- survdiff(Surv(time, status) ~ sex, data = lung)
# print the result of the log-rank test
print(result)
view raw survival.r hosted with ❤ by GitHub
Survival in R
Lung cancer survival plot for both male (1) and female (2) patients.

The survdiff() function compares survivals between groups (e.g. female and male) using log-rank analysis (chi-squared) with the null hypothesis that the survival rate is the same between groups.