Skip to contents

The number of subjects still at risk in each group of a kaplan_meier() or aalen_johansen() fit at a set of times, the table printed under a survival plot. get_risk_table_frame() gives the numbers as a data frame, and risk_table() draws them as a ggplot object, a table of text whose time axis lines up with a curve drawn over the same range.

Usage

get_risk_table_frame(fit, times = NULL)

risk_table(fit, times = NULL)

Arguments

fit

A kaplan_meier() or aalen_johansen() fit.

times

The times at which to count. The default is six evenly spaced, rounded times from 0 to the end of follow-up.

Value

get_risk_table_frame() gives a data frame with the columns strata, time, and n_risk, one row per group and time. risk_table() gives a ggplot object.

Details

The number at risk at time \(t\) is the number at risk at the first observed time at or after \(t\), so it counts the subjects still under follow-up just before \(t\). It's 0 after the end of follow-up.

See also

plot_survival() and plot_cif(), which stack the table under their curves with risk_table = TRUE.

Examples

fit <- kaplan_meier(Surv(time, status) ~ sex, data = lung)
get_risk_table_frame(fit, times = c(0, 250, 500, 750, 1000))
#>    strata time n_risk
#> 1   sex=1    0    138
#> 2   sex=1  250     62
#> 3   sex=1  500     20
#> 4   sex=1  750      7
#> 5   sex=1 1000      2
#> 6   sex=2    0     90
#> 7   sex=2  250     53
#> 8   sex=2  500     21
#> 9   sex=2  750      3
#> 10  sex=2 1000      0
risk_table(fit, times = c(0, 250, 500, 750, 1000))