rm_survsum.RdDisplays event counts, median survival time and survival rates at specified times points for the entire cohort and by group. The logrank test of differences in survival curves is displayed.
rm_survsum(
data,
time,
status,
group = NULL,
survtimes = NULL,
survtimeunit = NULL,
survtimesLbls = NULL,
CIwidth = 0.95,
unformattedp = FALSE,
conf.type = "log",
na.action = "na.omit",
showCounts = TRUE,
showLogrank = TRUE,
eventProb = FALSE,
digits = getOption("reportRmd.digits", 2),
caption = NULL,
tableOnly = FALSE,
add.reverse.KM = FALSE,
fontsize = NULL,
cencode = 0,
eventcode = 1,
digits.reverse.KM = 1
)data frame containing survival data
string indicating survival time variable
string indicating the event status variable. The status
variable may be numeric, character, or factor; censoring and event values
can be specified using cencode and eventcode.
string or character vector indicating the variable(s) to group observations by. If this is left as NULL (the default) then summaries are provided for the entire cohort.
numeric vector specifying when survival probabilities should be calculated.
unit of time to suffix to the time column label if survival probabilities are requested, should be plural
if supplied, a vector the same length as survtimes with descriptions (useful for displaying years with data provided in months)
width of the survival probabilities, default is 95%
boolean indicating if you would like the p-value to be returned unformatted (ie not rounded or prefixed with '<'). Should be used in conjunction with the digits argument.
type of confidence interval see survival::survfit for
details. Default is 'log'.
default is to omit missing values, but can be set to throw and error using na.action='na.fail'
boolean indicating if the at risk, events and censored columns should be output; default is TRUE
boolean indicating if the log-rank test statistic and p-value should be output; default is TRUE
boolean indicating if event probabilities, rather than survival probabilities, should be displayed; default is FALSE
the number of digits in the survival rate, default is 2, unless the reportRmd.digits option is set
table caption for markdown output
should a dataframe or a formatted object be returned
boolean indicating if median follow-up and its confidence interval should be estimated using the reverse Kaplan-Meier method and displayed in the table; default is FALSE.
PDF/HTML output only, manually set the table fontsize
value of the status variable indicating censoring. May be numeric, character, or factor-compatible. Default is 0.
value of the status variable indicating the event of interest. May be numeric, character, or factor-compatible. Default is 1.
number of digits used to display the median follow-up and confidence interval estimated using the reverse Kaplan-Meier method; default is 1.
A character vector of the survival table source code, unless tableOnly=TRUE in which case a data frame is returned
This summary table is supplied for simple group comparisons only. To examine
differences in groups with stratification see rm_survdiff. To
summarise differences in survival rates controlling for covariates see
rm_survtime.
# Simple median survival table
data("pembrolizumab")
rm_survsum(data=pembrolizumab,time='os_time',status='os_status')
#> <table class="table table" style="margin-left: auto; margin-right: auto; margin-left: auto; margin-right: auto;">
#> <thead>
#> <tr>
#> <th style="text-align:left;position: sticky; top:0; background-color: #FFFFFF;"> Events/Total </th>
#> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Median (95% CI) </th>
#> </tr>
#> </thead>
#> <tbody>
#> <tr>
#> <td style="text-align:left;"> 64/94 </td>
#> <td style="text-align:right;"> 13.96 (9.00, 20.14) </td>
#> </tr>
#> </tbody>
#> </table>
# Survival table with yearly survival rates
rm_survsum(data=pembrolizumab,time='os_time',status='os_status',
survtimes=c(12,24),survtimesLbls=1:2, survtimeunit='yr')
#> <table class="table table" style="margin-left: auto; margin-right: auto; margin-left: auto; margin-right: auto;">
#> <thead>
#> <tr>
#> <th style="text-align:left;position: sticky; top:0; background-color: #FFFFFF;"> Events/Total </th>
#> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Median (95% CI) </th>
#> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> 1yr (95% CI) </th>
#> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> 2yr (95% CI) </th>
#> </tr>
#> </thead>
#> <tbody>
#> <tr>
#> <td style="text-align:left;"> 64/94 </td>
#> <td style="text-align:right;"> 13.96 (9.00, 20.14) </td>
#> <td style="text-align:right;"> 0.53 (0.44, 0.64) </td>
#> <td style="text-align:right;"> 0.33 (0.24, 0.44) </td>
#> </tr>
#> </tbody>
#> </table>
# Median survival by group
rm_survsum(data=pembrolizumab,time='os_time',status='os_status',group='sex')
#> <table class="table table" style="margin-left: auto; margin-right: auto; margin-left: auto; margin-right: auto;">
#> <thead>
#> <tr>
#> <th style="text-align:left;position: sticky; top:0; background-color: #FFFFFF;"> Group </th>
#> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Events/Total </th>
#> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Median (95% CI) </th>
#> </tr>
#> </thead>
#> <tbody>
#> <tr>
#> <td style="text-align:left;"> Female </td>
#> <td style="text-align:right;"> 39/58 </td>
#> <td style="text-align:right;"> 14.29 (9.69, 23.82) </td>
#> </tr>
#> <tr>
#> <td style="text-align:left;"> Male </td>
#> <td style="text-align:right;"> 25/36 </td>
#> <td style="text-align:right;"> 11.24 (6.14, 25.33) </td>
#> </tr>
#> <tr>
#> <td style="text-align:left;"> Log Rank Test </td>
#> <td style="text-align:right;"> ChiSq </td>
#> <td style="text-align:right;"> 0.5 on 1 df </td>
#> </tr>
#> <tr>
#> <td style="text-align:left;"> </td>
#> <td style="text-align:right;"> p-value </td>
#> <td style="text-align:right;"> 0.46 </td>
#> </tr>
#> </tbody>
#> </table>
# Survival Summary by cohort, displayed in years
rm_survsum(data=pembrolizumab,time='os_time',status='os_status',
group="cohort",survtimes=seq(12,72,12),
survtimesLbls=seq(1,6,1),
survtimeunit='years')
#> For stratum 'cohort=A', requested survival time(s) 36, 48, 60, 72 exceed the maximum follow-up time of 28.780287474332. Survival probabilities could not be estimated and were set to 'Not Estimable'.
#> For stratum 'cohort=B', requested survival time(s) 24, 36, 48, 60, 72 exceed the maximum follow-up time of 23.9835728952775. Survival probabilities could not be estimated and were set to 'Not Estimable'.
#> For stratum 'cohort=C', requested survival time(s) 36, 48, 60, 72 exceed the maximum follow-up time of 35.3839835728967. Survival probabilities could not be estimated and were set to 'Not Estimable'.
#> For stratum 'cohort=D', requested survival time(s) 36, 48, 60, 72 exceed the maximum follow-up time of 32.9199178644757. Survival probabilities could not be estimated and were set to 'Not Estimable'.
#> For stratum 'cohort=E', requested survival time(s) 36, 48, 60, 72 exceed the maximum follow-up time of 35.4168377823416. Survival probabilities could not be estimated and were set to 'Not Estimable'.
#> <table class="table table" style="margin-left: auto; margin-right: auto; margin-left: auto; margin-right: auto;">
#> <thead>
#> <tr>
#> <th style="text-align:left;position: sticky; top:0; background-color: #FFFFFF;"> Group </th>
#> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Events/Total </th>
#> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Median (95% CI) </th>
#> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> 1years (95% CI) </th>
#> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> 2years (95% CI) </th>
#> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> 3years (95% CI) </th>
#> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> 4years (95% CI) </th>
#> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> 5years (95% CI) </th>
#> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> 6years (95% CI) </th>
#> </tr>
#> </thead>
#> <tbody>
#> <tr>
#> <td style="text-align:left;"> A </td>
#> <td style="text-align:right;"> 12/16 </td>
#> <td style="text-align:right;"> 8.30 (4.24, Not Estimable) </td>
#> <td style="text-align:right;"> 0.38 (0.20, 0.71) </td>
#> <td style="text-align:right;"> 0.23 (0.09, 0.59) </td>
#> <td style="text-align:right;"> Not Estimable </td>
#> <td style="text-align:right;"> Not Estimable </td>
#> <td style="text-align:right;"> Not Estimable </td>
#> <td style="text-align:right;"> Not Estimable </td>
#> </tr>
#> <tr>
#> <td style="text-align:left;"> B </td>
#> <td style="text-align:right;"> 16/18 </td>
#> <td style="text-align:right;"> 8.82 (4.67, 20.73) </td>
#> <td style="text-align:right;"> 0.32 (0.16, 0.64) </td>
#> <td style="text-align:right;"> Not Estimable </td>
#> <td style="text-align:right;"> Not Estimable </td>
#> <td style="text-align:right;"> Not Estimable </td>
#> <td style="text-align:right;"> Not Estimable </td>
#> <td style="text-align:right;"> Not Estimable </td>
#> </tr>
#> <tr>
#> <td style="text-align:left;"> C </td>
#> <td style="text-align:right;"> 12/18 </td>
#> <td style="text-align:right;"> 17.56 (7.95, Not Estimable) </td>
#> <td style="text-align:right;"> 0.61 (0.42, 0.88) </td>
#> <td style="text-align:right;"> 0.44 (0.27, 0.74) </td>
#> <td style="text-align:right;"> Not Estimable </td>
#> <td style="text-align:right;"> Not Estimable </td>
#> <td style="text-align:right;"> Not Estimable </td>
#> <td style="text-align:right;"> Not Estimable </td>
#> </tr>
#> <tr>
#> <td style="text-align:left;"> D </td>
#> <td style="text-align:right;"> 4/12 </td>
#> <td style="text-align:right;"> Not Estimable </td>
#> <td style="text-align:right;"> 0.67 (0.45, 0.99) </td>
#> <td style="text-align:right;"> 0.67 (0.45, 0.99) </td>
#> <td style="text-align:right;"> Not Estimable </td>
#> <td style="text-align:right;"> Not Estimable </td>
#> <td style="text-align:right;"> Not Estimable </td>
#> <td style="text-align:right;"> Not Estimable </td>
#> </tr>
#> <tr>
#> <td style="text-align:left;"> E </td>
#> <td style="text-align:right;"> 20/30 </td>
#> <td style="text-align:right;"> 14.26 (9.69, Not Estimable) </td>
#> <td style="text-align:right;"> 0.63 (0.48, 0.83) </td>
#> <td style="text-align:right;"> 0.34 (0.20, 0.57) </td>
#> <td style="text-align:right;"> Not Estimable </td>
#> <td style="text-align:right;"> Not Estimable </td>
#> <td style="text-align:right;"> Not Estimable </td>
#> <td style="text-align:right;"> Not Estimable </td>
#> </tr>
#> <tr>
#> <td style="text-align:left;"> </td>
#> <td style="text-align:right;"> </td>
#> <td style="text-align:right;"> </td>
#> <td style="text-align:right;"> </td>
#> <td style="text-align:right;"> </td>
#> <td style="text-align:right;"> </td>
#> <td style="text-align:right;"> Log Rank Test </td>
#> <td style="text-align:right;"> ChiSq </td>
#> <td style="text-align:right;"> 11.3 on 4 df </td>
#> </tr>
#> <tr>
#> <td style="text-align:left;"> </td>
#> <td style="text-align:right;"> </td>
#> <td style="text-align:right;"> </td>
#> <td style="text-align:right;"> </td>
#> <td style="text-align:right;"> </td>
#> <td style="text-align:right;"> </td>
#> <td style="text-align:right;"> </td>
#> <td style="text-align:right;"> p-value </td>
#> <td style="text-align:right;"> 0.023 </td>
#> </tr>
#> </tbody>
#> </table>
# Survival Summary by Sex and ctDNA group
rm_survsum(data=pembrolizumab,time='os_time',status='os_status',
group=c('sex','change_ctdna_group'),survtimes=c(12,24),survtimeunit='mo')
#> 21 observations with missing data were removed.
#> <table class="table table" style="margin-left: auto; margin-right: auto; margin-left: auto; margin-right: auto;">
#> <thead>
#> <tr>
#> <th style="text-align:left;position: sticky; top:0; background-color: #FFFFFF;"> Group </th>
#> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Events/Total </th>
#> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Median (95% CI) </th>
#> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> 12mo (95% CI) </th>
#> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> 24mo (95% CI) </th>
#> </tr>
#> </thead>
#> <tbody>
#> <tr>
#> <td style="text-align:left;"> Female, Decrease from baseline </td>
#> <td style="text-align:right;"> 7/19 </td>
#> <td style="text-align:right;"> Not Estimable </td>
#> <td style="text-align:right;"> 0.84 (0.69, 1.00) </td>
#> <td style="text-align:right;"> 0.67 (0.48, 0.93) </td>
#> </tr>
#> <tr>
#> <td style="text-align:left;"> Female, Increase from baseline </td>
#> <td style="text-align:right;"> 17/21 </td>
#> <td style="text-align:right;"> 13.90 (7.89, 27.47) </td>
#> <td style="text-align:right;"> 0.52 (0.35, 0.79) </td>
#> <td style="text-align:right;"> 0.24 (0.11, 0.51) </td>
#> </tr>
#> <tr>
#> <td style="text-align:left;"> Male, Decrease from baseline </td>
#> <td style="text-align:right;"> 7/14 </td>
#> <td style="text-align:right;"> 25.33 (14.26, Not Estimable) </td>
#> <td style="text-align:right;"> 0.71 (0.51, 0.99) </td>
#> <td style="text-align:right;"> 0.55 (0.34, 0.90) </td>
#> </tr>
#> <tr>
#> <td style="text-align:left;"> Male, Increase from baseline </td>
#> <td style="text-align:right;"> 15/19 </td>
#> <td style="text-align:right;"> 6.54 (5.68, Not Estimable) </td>
#> <td style="text-align:right;"> 0.42 (0.25, 0.71) </td>
#> <td style="text-align:right;"> 0.16 (0.05, 0.51) </td>
#> </tr>
#> <tr>
#> <td style="text-align:left;"> </td>
#> <td style="text-align:right;"> </td>
#> <td style="text-align:right;"> Log Rank Test </td>
#> <td style="text-align:right;"> ChiSq </td>
#> <td style="text-align:right;"> 15.1 on 3 df </td>
#> </tr>
#> <tr>
#> <td style="text-align:left;"> </td>
#> <td style="text-align:right;"> </td>
#> <td style="text-align:right;"> </td>
#> <td style="text-align:right;"> p-value </td>
#> <td style="text-align:right;"> 0.002 </td>
#> </tr>
#> </tbody>
#> </table>
# Character event status and reverse Kaplan-Meier median follow-up
pembrolizumab$status_chr <- ifelse(pembrolizumab$os_status == 1, "Death",
"Censored")
rm_survsum(data = pembrolizumab, time = "os_time", status = "status_chr",
group = "sex", cencode = "Censored", eventcode = "Death",
survtimes = c(12, 24), survtimeunit = "mo", add.reverse.KM = TRUE)
#> <table class="table table" style="margin-left: auto; margin-right: auto; margin-left: auto; margin-right: auto;">
#> <thead>
#> <tr>
#> <th style="text-align:left;position: sticky; top:0; background-color: #FFFFFF;"> Group </th>
#> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Median follow-up (mo; 95% CI) </th>
#> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Events/Total </th>
#> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> Median (95% CI) </th>
#> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> 12mo (95% CI) </th>
#> <th style="text-align:right;position: sticky; top:0; background-color: #FFFFFF;"> 24mo (95% CI) </th>
#> </tr>
#> </thead>
#> <tbody>
#> <tr>
#> <td style="text-align:left;"> Female </td>
#> <td style="text-align:right;"> 27.2 (25.1, 30.8) </td>
#> <td style="text-align:right;"> 39/58 </td>
#> <td style="text-align:right;"> 14.29 (9.69, 23.82) </td>
#> <td style="text-align:right;"> 0.55 (0.44, 0.69) </td>
#> <td style="text-align:right;"> 0.34 (0.24, 0.50) </td>
#> </tr>
#> <tr>
#> <td style="text-align:left;"> Male </td>
#> <td style="text-align:right;"> 28.8 (25.9, Not Estimable) </td>
#> <td style="text-align:right;"> 25/36 </td>
#> <td style="text-align:right;"> 11.24 (6.14, 25.33) </td>
#> <td style="text-align:right;"> 0.50 (0.36, 0.69) </td>
#> <td style="text-align:right;"> 0.31 (0.18, 0.52) </td>
#> </tr>
#> <tr>
#> <td style="text-align:left;"> </td>
#> <td style="text-align:right;"> </td>
#> <td style="text-align:right;"> </td>
#> <td style="text-align:right;"> Log Rank Test </td>
#> <td style="text-align:right;"> ChiSq </td>
#> <td style="text-align:right;"> 0.5 on 1 df </td>
#> </tr>
#> <tr>
#> <td style="text-align:left;"> </td>
#> <td style="text-align:right;"> </td>
#> <td style="text-align:right;"> </td>
#> <td style="text-align:right;"> </td>
#> <td style="text-align:right;"> p-value </td>
#> <td style="text-align:right;"> 0.46 </td>
#> </tr>
#> </tbody>
#> </table>