Skip to contents

This function calculates median survival time from time points and hazard rates using piecewise exponential survival function.

Usage

getMediansurv(time_points, hazard_rates)

Arguments

time_points

Numeric vector of time points defining intervals

hazard_rates

Numeric vector of hazard rates for each interval

Value

Numeric scalar of median survival time (NA if not reached)

Details

The function assumes piecewise exponential survival with constant hazard within each interval. It calculates survival probabilities at each time point and finds the time where survival probability equals 0.5.

Mathematical formulation: $$S(t) = \exp\left(-\sum_{j=1}^{k} \lambda_j \cdot \Delta t_j\right)$$ where \(\lambda_j\) is hazard rate in interval j and \(\Delta t_j\) is the length of interval j up to time t.

Examples

# Calculate median for 4-interval model
time_points <- c(0, 6, 12, 18, 24)
hazard_rates <- c(0.05, 0.08, 0.12, 0.15)

median_time <- getMediansurv(time_points, hazard_rates)
print(paste("Median survival:", round(median_time, 2), "months"))
#> [1] "Median survival: 10.91 months"