Extract Survival Analysis Results from Kaplan-Meier Table Using Person-Years Method
Source:R/extractfromKM.R
extractfromKM.Rd
This function estimates hazard rates and median survival time from published Kaplan-Meier table data using the person-years method, assuming exponential distribution within each interval.
Arguments
- time_points
Numeric vector of time points (length n+1 for n intervals)
- n_risk
Numeric vector of number at risk at each time point (length n+1)
- n_censored
Numeric vector of cumulative number censored at each time point (length n+1)
- warn_negative_events
Logical, whether to warn about negative events (default TRUE)
Value
List containing:
- hazard_table
Data frame with interval summaries and hazard rates
- median_survival
Estimated median survival time (NA if not reached)
Details
The function calculates:
Number of events in each interval (accounting for risk set changes)
Person-time using trapezoidal rule
Hazard rates as events/person-time
Median survival time using exponential survival function
Examples
# Example 1: Basic usage
time_points <- c(0, 6, 12, 18, 24)
n_risk <- c(200, 165, 130, 95, 65)
n_censored <- c(0, 15, 35, 53, 65)
result <- extractfromKM(time_points, n_risk, n_censored)
print(result$hazard_table)
#> interval n_at_risk_start n_censored_interval n_events hazard_rate
#> 1 [0,6) 200 15 20 0.01826484
#> 2 [6,12) 165 20 15 0.01694915
#> 3 [12,18) 130 18 17 0.02518519
#> 4 [18,24) 95 12 18 0.03750000
print(paste("Median survival:", result$median_survival, "months"))
#> [1] "Median survival: NA months"