reportRmd is a package designed to facilitate the reporting of common statistical outputs easily in RMarkdown documents. The package supports pdf, html and word output without any changes to the body of the report. The main features are Table 1 style summaries, combining multiple univariate regression models into a single table, tidy multivariable model output and combining univariate and multivariable regressions into a single table. Single table summaries of median survival times and survival probabilities are also provided. A highly customisable survival curve function, based on ggplot2 can be used to create publication-quality plots. Visualisation plots are also available for bivariate relationships and logistic regression models.
A word of caution:
The reportRmd package is designed to facilitate statistical reporting and does not provide any checks regarding the suitability of the models fit.
Basic summary statistics
| n=94 | |
|---|---|
| Age at study entry | |
| Mean (sd) | 57.9 (12.8) |
| Median (Min,Max) | 59.1 (21.1, 81.8) |
| Patient Sex | |
| Female | 58 (62) |
| Male | 36 (38) |
Set IQR = T for interquartile range instead of
Min/Max
| n=94 | |
|---|---|
| Age at study entry | |
| Mean (sd) | 57.9 (12.8) |
| Median (Q1,Q3) | 59.1 (49.5, 68.7) |
| Patient Sex | |
| Female | 58 (62) |
| Male | 36 (38) |
Or all.stats=T for both
| n=94 | |
|---|---|
| Age at study entry | |
| Mean (sd) | 57.9 (12.8) |
| Median (Q1,Q3) | 59.1 (49.5, 68.7) |
| Range (min, max) | (21.1, 81.8) |
| Patient Sex | |
| Female | 58 (62) |
| Male | 36 (38) |
This will produce summary statistics by Sex
| Full Sample (n=94) | Female (n=58) | Male (n=36) | p-value | |
|---|---|---|---|---|
| Age at study entry | 0.30 | |||
| Mean (sd) | 57.9 (12.8) | 56.9 (12.6) | 59.3 (13.1) | |
| Median (Min,Max) | 59.1 (21.1, 81.8) | 56.6 (34.1, 78.2) | 61.2 (21.1, 81.8) | |
| PD L1 percent | 0.76 | |||
| Mean (sd) | 13.9 (29.2) | 15.0 (30.5) | 12.1 (27.3) | |
| Median (Min,Max) | 0 (0, 100) | 0.5 (0.0, 100.0) | 0 (0, 100) | |
| Missing | 1 | 0 | 1 | |
| Did ctDNA increase or decrease from baseline to cycle 3 | 0.84 | |||
| Decrease from baseline | 33 (45) | 19 (48) | 14 (42) | |
| Increase from baseline | 40 (55) | 21 (52) | 19 (58) | |
| Missing | 21 | 18 | 3 |
To indicate which statistical test was used use
show.tests=TRUE
rm_covsum(data=pembrolizumab, maincov = 'sex',
covs=c('age','pdl1','change_ctdna_group'),
show.tests=TRUE)| Full Sample (n=94) | Female (n=58) | Male (n=36) | p-value | StatTest | |
|---|---|---|---|---|---|
| Age at study entry | 0.30 | Wilcoxon Rank Sum | |||
| Mean (sd) | 57.9 (12.8) | 56.9 (12.6) | 59.3 (13.1) | ||
| Median (Min,Max) | 59.1 (21.1, 81.8) | 56.6 (34.1, 78.2) | 61.2 (21.1, 81.8) | ||
| PD L1 percent | 0.76 | Wilcoxon Rank Sum | |||
| Mean (sd) | 13.9 (29.2) | 15.0 (30.5) | 12.1 (27.3) | ||
| Median (Min,Max) | 0 (0, 100) | 0.5 (0.0, 100.0) | 0 (0, 100) | ||
| Missing | 1 | 0 | 1 | ||
| Did ctDNA increase or decrease from baseline to cycle 3 | 0.84 | Chi Sq | |||
| Decrease from baseline | 33 (45) | 19 (48) | 14 (42) | ||
| Increase from baseline | 40 (55) | 21 (52) | 19 (58) | ||
| Missing | 21 | 18 | 3 |
Effect sizes can be added with effSize = TRUE. Effect
size measures include the Wilcoxon r for Wilcoxon rank-sum test, Cohen’s
d for t-test, Omega for ANOVA, Epsilon for Kruskal Wallis test, and
Cramer’s V for categorical variables.
| Full Sample (n=94) | Female (n=58) | Male (n=36) | p-value | Effect Size | |
|---|---|---|---|---|---|
| Age at study entry | 0.30 | 0.11 | |||
| Mean (sd) | 57.9 (12.8) | 56.9 (12.6) | 59.3 (13.1) | ||
| Median (Min,Max) | 59.1 (21.1, 81.8) | 56.6 (34.1, 78.2) | 61.2 (21.1, 81.8) | ||
| Did ctDNA increase or decrease from baseline to cycle 3 | 0.84 | 0.020 | |||
| Decrease from baseline | 33 (45) | 19 (48) | 14 (42) | ||
| Increase from baseline | 40 (55) | 21 (52) | 19 (58) | ||
| Missing | 21 | 18 | 3 |
Group comparisons are non-parametric by default, specify
testcont='ANOVA' for t-tests/ANOVA
rm_covsum(data=pembrolizumab, maincov = 'sex',
covs=c('age','pdl1'),
testcont='ANOVA',
show.tests=TRUE, effSize=TRUE)| Full Sample (n=94) | Female (n=58) | Male (n=36) | p-value | Effect Size | StatTest | |
|---|---|---|---|---|---|---|
| Age at study entry | 0.39 | 0.18 | t-test, Cohen’s d | |||
| Mean (sd) | 57.9 (12.8) | 56.9 (12.6) | 59.3 (13.1) | |||
| Median (Min,Max) | 59.1 (21.1, 81.8) | 56.6 (34.1, 78.2) | 61.2 (21.1, 81.8) | |||
| PD L1 percent | 0.63 | 0.100 | t-test, Cohen’s d | |||
| Mean (sd) | 13.9 (29.2) | 15.0 (30.5) | 12.1 (27.3) | |||
| Median (Min,Max) | 0 (0, 100) | 0.5 (0.0, 100.0) | 0 (0, 100) | |||
| Missing | 1 | 0 | 1 |
The default is to indicate percentages by columns (ie. percentages within columns add to 100)
| Full Sample (n=94) | Female (n=58) | Male (n=36) | |
|---|---|---|---|
| Study Cohort | |||
| A | 16 (17) | 3 (5) | 13 (36) |
| B | 18 (19) | 18 (31) | 0 (0) |
| C | 18 (19) | 18 (31) | 0 (0) |
| D | 12 (13) | 7 (12) | 5 (14) |
| E | 30 (32) | 12 (21) | 18 (50) |
But you can also specify to show by row instead
| Full Sample (n=94) | Female (n=58) | Male (n=36) | |
|---|---|---|---|
| Study Cohort | |||
| A | 16 | 3 (19) | 13 (81) |
| B | 18 | 18 (100) | 0 (0) |
| C | 18 | 18 (100) | 0 (0) |
| D | 12 | 7 (58) | 5 (42) |
| E | 30 | 12 (40) | 18 (60) |
The rm_compactsum function is similar to the
rm_covsum function, but condenses the table by excluding
the reference rows and missing data rows and creating instead a missing
data column. The arguments largely function the same way with the
exception that displaying the iqr is the default and the function
provides more flexibility. Future versions will align the two
functions.
| Full Sample (n=94) | Missing | |
|---|---|---|
| Did ctDNA increase or decrease from baseline to cycle 3 - Increase from baseline | 40 (55%) | 21 |
| Target lesion size at baseline | 73.5 (49.2-108.8) | 0 |
The default summary statistic for numerical variables is median. To
specify which numerical variables should have mean displayed instead,
change the use_mean argument. Unspecified xvars will use
the default median
rm_compactsum(data=pembrolizumab, xvars=c('age','pdl1','change_ctdna_group'), grp = 'sex', use_mean = c("pdl1"), effSize = T, show.tests = T)| Full Sample (n=94) | Female (n=58) | Male (n=36) | p-value | Effect Size (95% CI) | Missing | pTest | effStat | |
|---|---|---|---|---|---|---|---|---|
| Age at study entry | 59.1 (49.5-68.7) | 56.6 (45.8-67.8) | 61.2 (52.0-69.4) | 0.30 | 0.11 (-0.10, 0.21) | 0 | Wilcoxon Rank Sum | Wilcoxon r |
| PD L1 percent | 13.9 (29.2) | 15.0 (30.5) | 12.1 (27.3) | 0.63 | 0.10 (-0.38, 0.20) | 1 | t-test | Cohen’s d |
| Did ctDNA increase or decrease from baseline to cycle 3 - Increase from baseline | 40 (55%) | 21 (52%) | 19 (58%) | 0.84 | 0.02 (-0.21, 0.05) | 21 | ChiSq | Cramer’s V |
The digits and digits.cat arguments can be changed to a custom numerical value. The default digits is 1, the default digits.cat is 0
rm_compactsum(data=pembrolizumab, xvars=c('age','pdl1','change_ctdna_group'), grp = 'sex', use_mean = c("pdl1"), digits = 2, digits.cat = 1, effSize = T, show.tests = T)| Full Sample (n=94) | Female (n=58) | Male (n=36) | p-value | Effect Size (95% CI) | Missing | pTest | effStat | |
|---|---|---|---|---|---|---|---|---|
| Age at study entry | 59.12 (49.54-68.71) | 56.64 (45.80-67.83) | 61.16 (51.99-69.44) | 0.30 | 0.11 (-0.09, 0.21) | 0 | Wilcoxon Rank Sum | Wilcoxon r |
| PD L1 percent | 13.90 (29.24) | 15.02 (30.55) | 12.06 (27.26) | 0.63 | 0.10 (-0.39, 0.20) | 1 | t-test | Cohen’s d |
| Did ctDNA increase or decrease from baseline to cycle 3 - Increase from baseline | 40 (54.8%) | 21 (52.5%) | 19 (57.6%) | 0.84 | 0.02 (-0.19, 0.05) | 21 | ChiSq | Cramer’s V |
To specify custom digit arguments for different numerical variables,
change the digits argument. Unspecified variables will use
the default value.
rm_compactsum(data=pembrolizumab, xvars=c('age','pdl1','l_size'), grp = 'sex', digits = c("age" = 3, "l_size" = 2), effSize = T, show.tests = T)| Full Sample (n=94) | Female (n=58) | Male (n=36) | p-value | Effect Size (95% CI) | Missing | pTest | effStat | |
|---|---|---|---|---|---|---|---|---|
| Age at study entry | 59.121 (49.542-68.708) | 56.643 (45.800-67.834) | 61.164 (51.992-69.438) | 0.30 | 0.11 (-0.09, 0.21) | 0 | Wilcoxon Rank Sum | Wilcoxon r |
| PD L1 percent | 0.0 (0.0-10.0) | 0.5 (0.0-13.8) | 0.0 (0.0-4.5) | 0.76 | 0.03 (-0.17, 0.06) | 1 | Wilcoxon Rank Sum | Wilcoxon r |
| Target lesion size at baseline | 73.50 (49.25-108.75) | 68.00 (44.25-97.75) | 93.00 (65.50-121.00) | 0.066 | 0.19 (0.01, 0.35) | 0 | Wilcoxon Rank Sum | Wilcoxon r |
To view the self-generated description for the summary table:
Both rm_covsum and rm_compactsum support
tidyselect syntax, allowing you to use bare column names instead of
character strings. This also enables piping with |>:
| Full Sample (n=94) | Female (n=58) | Male (n=36) | p-value | Missing | |
|---|---|---|---|---|---|
| Age at study entry | 59.1 (49.5-68.7) | 56.6 (45.8-67.8) | 61.2 (52.0-69.4) | 0.30 | 0 |
| PD L1 percent | 0.0 (0.0-10.0) | 0.5 (0.0-13.8) | 0.0 (0.0-4.5) | 0.76 | 1 |
| Did ctDNA increase or decrease from baseline to cycle 3 - Increase from baseline | 40 (55%) | 21 (52%) | 19 (58%) | 0.84 | 21 |
The xvars/grp aliases can also be used with
rm_covsum for a consistent interface:
| Full Sample (n=94) | Female (n=58) | Male (n=36) | p-value | |
|---|---|---|---|---|
| Age at study entry | 0.30 | |||
| Mean (sd) | 57.9 (12.8) | 56.9 (12.6) | 59.3 (13.1) | |
| Median (Min,Max) | 59.1 (21.1, 81.8) | 56.6 (34.1, 78.2) | 61.2 (21.1, 81.8) | |
| PD L1 percent | 0.76 | |||
| Mean (sd) | 13.9 (29.2) | 15.0 (30.5) | 12.1 (27.3) | |
| Median (Min,Max) | 0 (0, 100) | 0.5 (0.0, 100.0) | 0 (0, 100) | |
| Missing | 1 | 0 | 1 | |
| Did ctDNA increase or decrease from baseline to cycle 3 | 0.84 | |||
| Decrease from baseline | 33 (45) | 19 (48) | 14 (42) | |
| Increase from baseline | 40 (55) | 21 (52) | 19 (58) | |
| Missing | 21 | 18 | 3 |
Header rows can be added to any table using the
header_above argument in outTable(). This
works for HTML, PDF and Word output. The argument takes a named vector
where the names are the header labels and the values are the number of
columns each label spans.
tab <- rm_covsum(data = pembrolizumab, maincov = cohort,
covs = c(age, pdl1, sex), full = FALSE,
pvalue = FALSE, tableOnly = TRUE)
outTable(tab, header_above = c(" " = 1, "Cohorts A-C" = 3, "Cohorts D,E" = 2))| Covariate | A (n=16) | B (n=18) | C (n=18) | D (n=12) | E (n=30) |
|---|---|---|---|---|---|
| Age at study entry | |||||
| Mean (sd) | 62.9 (6.1) | 56.3 (14.0) | 57.9 (10.8) | 63.8 (10.0) | 53.7 (15.3) |
| Median (Min,Max) | 62.1 (51.0, 70.9) | 56.6 (35.5, 74.8) | 53.9 (36.5, 74.0) | 64.6 (45.0, 78.2) | 51.8 (21.1, 81.8) |
| PD L1 percent | |||||
| Mean (sd) | 32.8 (42.1) | 7.5 (21.3) | 7.9 (10.2) | 25.8 (40.2) | 7.2 (24.0) |
| Median (Min,Max) | 2 (0, 100) | 0 (0, 90) | 2.5 (0.0, 30.0) | 1 (0, 95) | 0 (0, 95) |
| Missing | 1 | 0 | 0 | 0 | 0 |
| Patient Sex | |||||
| Female | 3 (19) | 18 (100) | 18 (100) | 7 (58) | 12 (40) |
| Male | 13 (81) | 0 (0) | 0 (0) | 5 (42) | 18 (60) |
Combining multiple univariate regression analyses into a single table. The function will try to determine the most appropriate model from the data.
| OR(95%CI) | p-value | N | Event | |
|---|---|---|---|---|
| Age at study entry | 0.96 (0.91, 1.00) | 0.089 | 94 | 78 |
| PD L1 percent | 0.97 (0.95, 0.98) | <0.001 | 93 | 77 |
| Did ctDNA increase or decrease from baseline to cycle 3 | 73 | 58 | ||
| Decrease from baseline | Reference | 33 | 19 | |
| Increase from baseline | 28.74 (5.20, 540.18) | 0.002 | 40 | 39 |
If the response is continuous linear regression is the default. Using
type = 'linear' will ensure linear regression.
| Estimate(95%CI) | p-value | N | |
|---|---|---|---|
| Age at study entry | -0.58 (-1.54, 0.38) | 0.23 | 94 |
| Study Cohort | 94 | ||
| A | Reference | 16 | |
| B | -38.04 (-74.95, -1.13) | 0.044 | 18 |
| C | 20.35 (-16.56, 57.26) | 0.28 | 18 |
| D | -24.79 (-65.82, 16.23) | 0.23 | 12 |
| E | 31.69 (-1.56, 64.95) | 0.062 | 30 |
If the response is binomial, logistic regression will be run (or
specified with type = 'logistic').
| OR(95%CI) | p-value | N | Event | |
|---|---|---|---|---|
| Age at study entry | 0.96 (0.91, 1.00) | 0.089 | 94 | 78 |
| Study Cohort | 94 | 78 | ||
| A | Reference | 16 | 13 | |
| B | 7.3e+07 (8.5e-76, NA) | 0.99 | 18 | 18 |
| C | 7.3e+07 (7.7e-74, NA) | 0.99 | 18 | 18 |
| D | 0.12 (0.02, 0.60) | 0.015 | 12 | 4 |
| E | 1.15 (0.21, 5.49) | 0.86 | 30 | 25 |
If the response is integer, poisson regression will be run (or
specified with type = 'poisson').
pembrolizumab$Counts <- rpois(nrow(pembrolizumab),lambda = 3)
rm_uvsum(data=pembrolizumab, response='Counts',covs=c('age','cohort'))| RR(95%CI) | p-value | N | |
|---|---|---|---|
| Age at study entry | 1.00 (0.99, 1.01) | 0.70 | 94 |
| Study Cohort | 94 | ||
| A | Reference | 16 | |
| B | 1.17 (0.78, 1.77) | 0.45 | 18 |
| C | 1.06 (0.70, 1.62) | 0.78 | 18 |
| D | 1.14 (0.72, 1.79) | 0.57 | 12 |
| E | 1.12 (0.78, 1.64) | 0.55 | 30 |
offset terms can be specified as well, but must correspond to a variable in the data set
pembrolizumab$length_followup <- rnorm(nrow(pembrolizumab),mean = 72,sd=3)
pembrolizumab$log_length_followup <- log(pembrolizumab$length_followup)
rm_uvsum(data=pembrolizumab, response='Counts',covs=c('age','cohort'),
offset = "log_length_followup")| RR(95%CI) | p-value | N | |
|---|---|---|---|
| Age at study entry | 1.00 (0.99, 1.01) | 0.78 | 94 |
| Study Cohort | 94 | ||
| A | Reference | 16 | |
| B | 1.17 (0.78, 1.76) | 0.45 | 18 |
| C | 1.05 (0.70, 1.60) | 0.80 | 18 |
| D | 1.15 (0.73, 1.81) | 0.54 | 12 |
| E | 1.12 (0.78, 1.64) | 0.54 | 30 |
To run negative binomial regression instead specify
type = 'negbin'
rm_uvsum(data=pembrolizumab, response='Counts', type='negbin',
covs=c('age','cohort'),
offset = "log_length_followup")| RR(95%CI) | p-value | N | |
|---|---|---|---|
| Age at study entry | 1.00 (0.99, 1.01) | 0.80 | 94 |
| Study Cohort | 94 | ||
| A | Reference | 16 | |
| B | 1.17 (0.76, 1.81) | 0.48 | 18 |
| C | 1.06 (0.68, 1.65) | 0.81 | 18 |
| D | 1.15 (0.71, 1.87) | 0.56 | 12 |
| E | 1.12 (0.76, 1.69) | 0.56 | 30 |
If two response variables are specified and then survival analysis is
run (specified with type='coxph').
rm_uvsum(data=pembrolizumab, response=c('os_time','os_status'),
covs=c('age','pdl1','change_ctdna_group'),whichp = "levels")| HR(95%CI) | p-value | N | Event | |
|---|---|---|---|---|
| Age at study entry | 0.99 (0.97, 1.01) | 0.16 | 94 | 64 |
| PD L1 percent | 0.99 (0.98, 1.00) | 0.026 | 93 | 63 |
| Did ctDNA increase or decrease from baseline to cycle 3 | 73 | 46 | ||
| Decrease from baseline | Reference | 33 | 14 | |
| Increase from baseline | 3.06 (1.62, 5.77) | <0.001 | 40 | 32 |
Clustered analyses can also be run
data("diabetic", package = "survival")
rm_uvsum(data=diabetic, response=c('time','status'),
covs=c('trt','laser','age','eye'),id='id')| HR(95%CI) | p-value | N (obs|clusters) | Event (total|clusters with event) | |
|---|---|---|---|---|
| trt | 0.46 (0.34, 0.61) | <0.001 | 394|197 | 155|117 |
| laser | 394|197 | 155|117 | ||
| xenon | Reference | 228|114 | 87|63 | |
| argon | 1.02 (0.73, 1.44) | 0.90 | 166|83 | 68|54 |
| age | 1.00 (0.99, 1.01) | 0.64 | 394|197 | 155|117 |
| eye | 394|197 | 155|117 | ||
| left | Reference | 197|197 | 69|69 | |
| right | 1.32 (1.00, 1.76) | 0.053 | 197|197 | 86|86 |
Competing risk models need to be explicitly specified using
type='crr'.
rm_uvsum(data=pembrolizumab, response=c('os_time','os_status'),
covs=c('age','pdl1','change_ctdna_group'),
type='crr')| HR(95%CI) | p-value | N | Event | |
|---|---|---|---|---|
| Age at study entry | 0.99 (0.97, 1.00) | 0.15 | 94 | 64 |
| PD L1 percent | 0.99 (0.98, 1.00) | 0.017 | 93 | 63 |
| Did ctDNA increase or decrease from baseline to cycle 3 | 73 | 46 | ||
| Decrease from baseline | Reference | 33 | 14 | |
| Increase from baseline | 3.06 (1.64, 5.69) | <0.001 | 40 | 32 |
Correlated observations can be handled using GEE
data("ctDNA")
rm_uvsum(response = 'size_change',
covs=c('time','ctdna_status'),
gee=TRUE,
id='id', corstr="exchangeable",
family=gaussian("identity"),
data=ctDNA,showN=TRUE)| Estimate(95%CI) | p-value | N (obs|clusters) | |
|---|---|---|---|
| Number of weeks on treatment | -0.12 (-0.44, 0.19) | 0.44 | 262|72 |
| Change in ctDNA since baseline | 262|72 | ||
| Clearance | Reference | 134|14 | |
| No clearance, decrease from baseline | 61.29 (37.49, 85.09) | <0.001 | 42|17 |
| No clearance, increase from baseline | 82.52 (64.75, 100.28) | <0.001 | 86|41 |
Outputs from multiple imputations can be summarised as follows (not run):
miss_data <- pembrolizumab
miss_data$age[sample(1:nrow(pembrolizumab),50,replace=F)] <- NA
miss_data$cohort[sample(1:nrow(pembrolizumab),50,replace=F)] <- NA
require(mice)
ini <- mice::mice(miss_data, maxit = 0)
pred_matrix <- ini$predictorMatrix
pred_matrix[1, ] <- 0
pred_matrix[, 1] <- 0
imp <- mice::mice(miss_data, m = 5, predictorMatrix = pred_matrix, printFlag = FALSE)
imputed_datasets <- purrr::map(1:5, \(m) mice::complete(imp, m))
fits <- lapply(imputed_datasets, function(dat) {
glm(orr ~ age+cohort, data = dat,family='binomial')
})
model <- mice::as.mira(fits)
rm_mvsum(model) If you want to check the underlying models, set
returnModels = TRUE
## $age
##
## Call: glm(formula = orr ~ age, family = binomial, data = data)
##
## Coefficients:
## (Intercept) age
## 4.12269 -0.04231
##
## Degrees of Freedom: 93 Total (i.e. Null); 92 Residual
## Null Deviance: 85.77
## Residual Deviance: 82.53 AIC: 86.53
The data analysed can be examined by interrogating the data object appended to each model
mList <- rm_uvsum(response = 'orr',
covs=c('age'),
data=pembrolizumab,returnModels = TRUE)
head(mList$age$data)## # A tibble: 6 × 18
## id age sex cohort l_size pdl1 tmb baseline_ctdna change_ctdna_group
## <fct> <dbl> <fct> <fct> <dbl> <dbl> <dbl> <dbl> <fct>
## 1 INS-A… 62.1 Male A 140 2 0.574 114. Increase from bas…
## 2 INS-A… 62.2 Male A 108 0 0.921 4.26 Increase from bas…
## 3 INS-A… 70.9 Male A 11 100 0.375 205. Decrease from bas…
## 4 INS-A… 57.9 Male A 39 45 0.824 169. Increase from bas…
## 5 INS-A… 65.7 Fema… A 90 0 0.114 425. Decrease from bas…
## 6 INS-A… 60.9 Male A 124 2 0.717 15.8 Increase from bas…
## # ℹ 9 more variables: orr <fct>, cbr <fct>, os_status <dbl>, os_time <dbl>,
## # pfs_status <dbl>, pfs_time <dbl>, Counts <int>, length_followup <dbl>,
## # log_length_followup <dbl>
Multiple comparisons can be controlled for with the p.adjust
argument, which accepts any of the options from the
p.adjust function.
| OR(95%CI) | p-value | N | Event | |
|---|---|---|---|---|
| Age at study entry | 0.96 (0.91, 1.00) | 0.11 | 94 | 78 |
| Patient Sex | 94 | 78 | ||
| Female | Reference | 58 | 51 | |
| Male | 0.41 (0.13, 1.22) | 0.11 | 36 | 27 |
| PD L1 percent | 0.97 (0.95, 0.98) | <0.001 | 93 | 77 |
Note: The raw p-value column is suppressed when there are categorical variables with >2 levels, to prevent three columns of p-values from appearing.
To create a nice display for multivariable models the multivariable model first needs to be fit.
By default, the variance inflation factor will be shown to check for
multicollinearity. To suppress this column set vif=FALSE.
Note: variance inflation factors are not computed (yet) for multilevel
or GEE models.
glm_fit <- glm(orr~change_ctdna_group+pdl1+age,
family='binomial',
data = pembrolizumab)
rm_mvsum(glm_fit, showN = TRUE, vif=TRUE)| OR(95%CI) | p-value | N | Event | VIF | |
|---|---|---|---|---|---|
| Did ctDNA increase or decrease from baseline to cycle 3 | 73 | 58 | 1.03 | ||
| Decrease from baseline | Reference | 33 | 19 | ||
| Increase from baseline | 23.92 (3.69, 508.17) | 0.006 | 40 | 39 | |
| PD L1 percent | 0.97 (0.95, 0.99) | 0.011 | 73 | 58 | 1.24 |
| Age at study entry | 0.94 (0.87, 1.00) | 0.078 | 73 | 58 | 1.23 |
p-values can be adjusted for multiple comparisons using any of the
options available in the p.adjust function. This argument
is also available for univariate models run with rm_uvsum.
| OR(95%CI) | p-value | N | Event | VIF | |
|---|---|---|---|---|---|
| Did ctDNA increase or decrease from baseline to cycle 3 | 73 | 58 | 1.03 | ||
| Decrease from baseline | Reference | 33 | 19 | ||
| Increase from baseline | 23.92 (3.69, 508.17) | 0.018 | 40 | 39 | |
| PD L1 percent | 0.97 (0.95, 0.99) | 0.022 | 73 | 58 | 1.24 |
| Age at study entry | 0.94 (0.87, 1.00) | 0.078 | 73 | 58 | 1.23 |
As of version 0.1.3, you can include univariate (unadjusted)
estimates alongside the multivariable estimates in a single table by
setting include_unadjusted = TRUE. This provides a
convenient way to compare unadjusted and adjusted estimates
side-by-side.
glm_fit <- glm(orr~change_ctdna_group+pdl1+age,
family='binomial',
data = pembrolizumab)
rm_mvsum(glm_fit, include_unadjusted = TRUE, showN = TRUE, vif = TRUE)| Unadjusted OR(95%CI) | Unadjusted p-value | Adjusted OR(95%CI) | Adjusted p-value | N | Event | VIF | |
|---|---|---|---|---|---|---|---|
| Did ctDNA increase or decrease from baseline to cycle 3 | 73 | 58 | 1.03 | ||||
| Decrease from baseline | Reference | Reference | 33 | 19 | |||
| Increase from baseline | 28.74 (5.20, 540.18) | 0.002 | 23.92 (3.69, 508.17) | 0.006 | 40 | 39 | |
| PD L1 percent | 0.97 (0.96, 0.99) | 0.002 | 0.97 (0.95, 0.99) | 0.011 | 73 | 58 | 1.24 |
| Age at study entry | 0.96 (0.90, 1.00) | 0.078 | 0.94 (0.87, 1.00) | 0.078 | 73 | 58 | 1.23 |
The data are taken from the model itself, so the data
argument is not needed. This includes Cox proportional hazards models,
where the response is a Surv() object:
require(survival)
cox_fit <- coxph(Surv(os_time, os_status) ~ age + sex + baseline_ctdna,
data = pembrolizumab)
rm_mvsum(cox_fit, include_unadjusted = TRUE)| Unadjusted HR(95%CI) | Unadjusted p-value | Adjusted HR(95%CI) | Adjusted p-value | N | Event | VIF | |
|---|---|---|---|---|---|---|---|
| Age at study entry | 0.99 (0.97, 1.01) | 0.16 | 0.98 (0.96, 1.00) | 0.088 | 94 | 64 | 1.06 |
| sex | 94 | 64 | 1.11 | ||||
| Female | Reference | Reference | 58 | 39 | |||
| Male | 1.21 (0.73, 2.00) | 0.46 | 1.19 (0.70, 2.02) | 0.52 | 36 | 25 | |
| Baseline ctDNA | 1.00 (1.00, 1.00) | 0.019 | 1.00 (1.00, 1.00) | 0.021 | 94 | 64 | 1.09 |
Transformed terms are summarised on the scale they were fit on, so
the unadjusted estimate for log(l_size) below is the slope
from glm(orr ~ log(l_size)), not from
glm(orr ~ l_size):
rm_mvsum(glm(orr ~ log(l_size) + sex, family = 'binomial', data = pembrolizumab),
include_unadjusted = TRUE)| Unadjusted OR(95%CI) | Unadjusted p-value | Adjusted OR(95%CI) | Adjusted p-value | N | Event | VIF | |
|---|---|---|---|---|---|---|---|
| Target lesion size at baseline | 1.66 (0.75, 3.72) | 0.21 | 1.86 (0.83, 4.39) | 0.14 | 94 | 78 | 1.04 |
| Patient Sex | 94 | 78 | 1.04 | ||||
| Female | Reference | Reference | 58 | 51 | |||
| Male | 0.41 (0.13, 1.22) | 0.11 | 0.36 (0.11, 1.09) | 0.074 | 36 | 27 |
Two points are worth knowing when reading these tables.
The univariate models are fit on the same complete-case sample as the
multivariable model, so the two sets of estimates are directly
comparable and the N column applies to both. This differs
from calling rm_uvsum() yourself, which uses all rows
available for each covariate.
A covariate that appears only inside an interaction term has no adjusted estimate of its own. Such covariates are appended to the end of the table with an unadjusted estimate and a blank adjusted column, rather than being dropped:
rm_mvsum(glm(orr ~ pdl1 + age:sex, family = 'binomial', data = pembrolizumab),
include_unadjusted = TRUE)| Unadjusted OR(95%CI) | Unadjusted p-value | Adjusted OR(95%CI) | Adjusted p-value | N | Event | VIF | |
|---|---|---|---|---|---|---|---|
| PD L1 percent | 0.97 (0.95, 0.98) | <0.001 | 0.96 (0.94, 0.98) | <0.001 | 93 | 77 | 1.15 |
| age:sex | 93 | 77 | |||||
| age:sexFemale | 0.95 (0.88, 1.01) | 0.11 | 58 | 51 | |||
| age:sexMale | 0.93 (0.87, 0.98) | 0.018 | 35 | 26 | |||
| Age at study entry | 0.96 (0.91, 1.00) | 0.085 | 93 | 77 | |||
| Patient Sex | 93 | ||||||
| Female | Reference | 58 | 51 | ||||
| Male | 0.40 (0.13, 1.18) | 0.098 | 35 | 26 |
Terms that expand to a matrix, such as poly(age, 2), can
not be fit univariately; these are skipped with a warning and their
unadjusted cells are left blank.
To display both models in a single table run the rm_uvsum and
rm_mvsum functions with tableOnly=TRUE and combine.
uvsumTable <- rm_uvsum(data=pembrolizumab, response='orr',
covs=c('age','sex','pdl1','change_ctdna_group'),tableOnly = TRUE)
glm_fit <- glm(orr~change_ctdna_group+pdl1,
family='binomial',
data = pembrolizumab)
mvsumTable <- rm_mvsum(glm_fit, showN = TRUE,tableOnly = TRUE)
rm_uv_mv(uvsumTable,mvsumTable)| Unadjusted OR(95%CI) | p | Adjusted OR(95%CI) | p (adj) | |
|---|---|---|---|---|
| Age at study entry | 0.96 (0.91, 1.00) | 0.089 | ||
| Patient Sex | ||||
| Female | Reference | |||
| Male | 0.41 (0.13, 1.22) | 0.11 | ||
| PD L1 percent | 0.97 (0.95, 0.98) | <0.001 | 0.98 (0.95, 1.00) | 0.024 |
| Did ctDNA increase or decrease from baseline to cycle 3 | ||||
| Decrease from baseline | Reference | Reference | ||
| Increase from baseline | 28.74 (5.20, 540.18) | 0.002 | 24.71 (4.19, 479.13) | 0.004 |
Note: This can also be done with adjusted p-values, but when combined the raw p-values are dropped.
uvsumTable <- rm_uvsum(data=pembrolizumab, response='orr',
covs=c('age','sex','pdl1','change_ctdna_group'),tableOnly = TRUE,p.adjust='holm')
glm_fit <- glm(orr~change_ctdna_group+pdl1,
family='binomial',
data = pembrolizumab)
mvsumTable <- rm_mvsum(glm_fit,tableOnly = TRUE,p.adjust='holm')
rm_uv_mv(uvsumTable,mvsumTable)| Unadjusted OR(95%CI) | p | Adjusted OR(95%CI) | p (adj) | |
|---|---|---|---|---|
| Age at study entry | 0.96 (0.91, 1.00) | 0.18 | ||
| Patient Sex | ||||
| Female | Reference | |||
| Male | 0.41 (0.13, 1.22) | 0.18 | ||
| PD L1 percent | 0.97 (0.95, 0.98) | <0.001 | 0.98 (0.95, 1.00) | 0.024 |
| Did ctDNA increase or decrease from baseline to cycle 3 | ||||
| Decrease from baseline | Reference | Reference | ||
| Increase from baseline | 28.74 (5.20, 540.18) | 0.005 | 24.71 (4.19, 479.13) | 0.007 |
If you need to make changes to the tables, setting
tableOnly=TRUE will return a data frame for any of the
rm_ functions. Changes can be made, and the table output
using outTable()
mvsumTable <- rm_mvsum(glm_fit, showN = TRUE,tableOnly = TRUE)
names(mvsumTable)[1] <-'Predictor'
outTable(mvsumTable)| Predictor | OR(95%CI) | p-value | N | Event | VIF |
|---|---|---|---|---|---|
| Did ctDNA increase or decrease from baseline to cycle 3 | 73 | 58 | 1.01 | ||
| Decrease from baseline | Reference | 33 | 19 | ||
| Increase from baseline | 24.71 (4.19, 479.13) | 0.004 | 40 | 39 | |
| PD L1 percent | 0.98 (0.95, 1.00) | 0.024 | 73 | 58 | 1.01 |
Tables can be nested with the nestTable() function
cohortA <- rm_uvsum(data=subset(pembrolizumab,cohort=='A'),
response = 'pdl1',
covs=c('age','sex'),
tableOnly = T)
cohortA$Cohort <- 'Cohort A'
cohortE <- rm_uvsum(data=subset(pembrolizumab,cohort=='E'),
response = 'pdl1',
covs=c('age','sex'),
tableOnly = T)
cohortE$Cohort <- 'Cohort E'
nestTable(rbind(cohortA,cohortE),head_col = 'Cohort',to_col = 'Covariate')| Estimate(95%CI) | p-value | N | |
|---|---|---|---|
| Cohort A | |||
| Age at study entry | 2.94 (-0.70, 6.58) | 0.10 | 15 |
| Patient Sex | 15 | ||
| Female | Reference | 3 | |
| Male | -40.25 (-96.25, 15.75) | 0.14 | 12 |
| Cohort E | |||
| Age at study entry | -0.44 (-1.02, 0.15) | 0.14 | 30 |
| Patient Sex | 30 | ||
| Female | Reference | 12 | |
| Male | -14.86 (-32.57, 2.85) | 0.097 | 18 |
If you are rendering to html format you can use the
scrollTable function to create a scrollable table. This is
useful for tables with many rows. If the output format is not html then
a regular table will be displayed.
long_table <- rm_compactsum(data=pembrolizumab,xvars = c(age,sex,cohort,pdl1,tmb,baseline_ctdna,change_ctdna_group,orr,cbr))
scrolling_table(long_table,pixelHeight = 300)| Full Sample (n=94) | Missing | |
|---|---|---|
| Age at study entry | 59.1 (49.5-68.7) | 0 |
| Patient Sex - Male | 36 (38%) | 0 |
| Study Cohort | 0 | |
| A | 16 (17%) | |
| B | 18 (19%) | |
| C | 18 (19%) | |
| D | 12 (13%) | |
| E | 30 (32%) | |
| PD L1 percent | 0.0 (0.0-10.0) | 1 |
| log of TMB | 0.7 (0.4-1.3) | 0 |
| Baseline ctDNA | 86.0 (7.5-416.6) | 0 |
| Did ctDNA increase or decrease from baseline to cycle 3 - Increase from baseline | 40 (55%) | 21 |
| Objective Response - SD/PD | 78 (83%) | 0 |
| Clinical Beneficial Response - PD/SD<C6 | 70 (74%) | 0 |
Displaying survival probabilities at different times by sex using Kaplan Meier estimates
rm_survsum(data=pembrolizumab,time='os_time',status='os_status',
group="sex",survtimes=seq(12,36,12),survtimeunit='months')| Group | Events/Total | Median (95% CI) | 12months (95% CI) | 24months (95% CI) | 36months (95% CI) |
|---|---|---|---|---|---|
| Female | 39/58 | 14.29 (9.69, 23.82) | 0.55 (0.44, 0.69) | 0.34 (0.24, 0.50) | Not Estimable |
| Male | 25/36 | 11.24 (6.14, 25.33) | 0.50 (0.36, 0.69) | 0.31 (0.18, 0.52) | Not Estimable |
| Log Rank Test | ChiSq | 0.5 on 1 df | |||
| p-value | 0.46 |
The reverse Kaplan-Meier follow-up time can also be displayed.
rm_survsum(data=pembrolizumab,time='os_time',status='os_status',
group="sex",survtimes=seq(12,24,12),survtimeunit='months',
add.reverse.KM = T)| Group | Median follow-up (months; 95% CI) | Events/Total | Median (95% CI) | 12months (95% CI) | 24months (95% CI) |
|---|---|---|---|---|---|
| Female | 27.2 (25.1, 30.8) | 39/58 | 14.29 (9.69, 23.82) | 0.55 (0.44, 0.69) | 0.34 (0.24, 0.50) |
| Male | 28.8 (25.9, Not Estimable) | 25/36 | 11.24 (6.14, 25.33) | 0.50 (0.36, 0.69) | 0.31 (0.18, 0.52) |
| Log Rank Test | ChiSq | 0.5 on 1 df | |||
| p-value | 0.46 |
Displaying survival probabilities at different times by sex using Cox PH estimates
rm_survtime(data=pembrolizumab,time='os_time',status='os_status',
strata="sex",survtimes=c(12,24),survtimeunit='mo',type='PH')| Time (mo) | At Risk | Events | Censored | Survival Rate (95% CI) |
|---|---|---|---|---|
| Overall | 94 | |||
| 12 | 48 | 44 | 2 | 0.53 (0.44, 0.64) |
| 24 | 24 | 17 | 7 | 0.33 (0.25, 0.45) |
| Female | 58 | |||
| 12 | 31 | 26 | 1 | 0.55 (0.44, 0.70) |
| 24 | 16 | 11 | 4 | 0.35 (0.24, 0.50) |
| Male | 36 | |||
| 12 | 17 | 18 | 1 | 0.51 (0.37, 0.70) |
| 24 | 8 | 6 | 3 | 0.32 (0.19, 0.52) |
Displaying survival probabilities at different times by sex, adjusting for age using Cox PH estimates
rm_survtime(data=pembrolizumab,time='os_time',status='os_status', covs='age',
strata="sex",survtimes=c(12,24),survtimeunit='mo',type='PH')| Time (mo) | At Risk | Events | Censored | Survival Rate (95% CI) |
|---|---|---|---|---|
| Overall | 94 | |||
| 12 | 48 | 44 | 2 | 0.54 (0.44, 0.65) |
| 24 | 24 | 17 | 7 | 0.33 (0.25, 0.45) |
| Female | 58 | |||
| 12 | 31 | 26 | 1 | 0.56 (0.44, 0.70) |
| 24 | 16 | 11 | 4 | 0.35 (0.24, 0.50) |
| Male | 36 | |||
| 12 | 17 | 18 | 1 | 0.51 (0.37, 0.70) |
| 24 | 8 | 6 | 3 | 0.31 (0.19, 0.53) |
To combine estimates across strata
rm_survdiff(data=pembrolizumab,time='os_time',status='os_status',
covs='sex',strata='cohort',digits=1)| group | N | Observed | Expected | Median (95%CI) |
|---|---|---|---|---|
| Overall | 94 | 64 | 14.0 (9.0, 20.1) | |
| Female | 58 | 39 | 43.0 | 14.3 (9.7, 23.8) |
| Male | 36 | 25 | 21.0 | 11.2 (6.1, 25.3) |
| Log Rank Test | ChiSq = 1.9 on 1 df | |||
| stratified by cohort | p-value = 0.17 |
For competing risk analysis, use rm_cifsum() to display
cumulative incidence probabilities at specific time points. This
requires the cmprsk package and a status variable coded with different
event types.
# Using pbc data from survival package as example
data(pbc, package = "survival")
# Create competing risk status: 0=censored, 1=transplant, 2=death
pbc$status_cr <- ifelse(pbc$status == 0, 0, pbc$status)
rm_cifsum(data=pbc, time='time', status='status_cr',
group='trt', eventcode=2, cencode=0,
eventtimes=c(1000, 2000, 3000),
eventtimeunit='days')| Strata | Event/Total | 1000days (95% CI) | 2000days (95% CI) | 3000days (95% CI) |
|---|---|---|---|---|
| 1 | 65/158 | 0.15 (0.10, 0.21) | 0.30 (0.23, 0.38) | 0.44 (0.35, 0.53) |
| 2 | 60/154 | 0.20 (0.14, 0.27) | 0.29 (0.22, 0.37) | 0.38 (0.29, 0.47) |
| Gray’s Test | ChiSq | 0.1 on 1 df | ||
| p-value | 0.80 |
New in version 0.1.0 is the ability to incorporate variable labels
into summary tables (but not yet all plots). If variables contain a
label attribute this will be displayed automatically, to
disable this set nicenames=F
Variable labels will be shown in the nicenames argument
is set to TRUE (the default). Variable labels are set using
the label attribute of individual variables (assigned using
reportRmd or another package like haven).
reportRmd supports the addition, removal and export of
labels using the following functions:
set_labels will set labels for a data frame from a
lookup tableset_var_labels allows you to set individual variable
labels to a data frameclear_labels removes all labels from a data frameexport_labels extracts variable labels from a data
frame and returns a data frame of variable names and variable
labelsGet some descriptive stats for the ctDNA data that comes with the
package. The nicenames argument is TRUE by default so
underscores are replaced by spaces
| n=270 | |
|---|---|
| Study Cohort | |
| A | 50 (19) |
| B | 14 (5) |
| C | 18 (7) |
| D | 88 (33) |
| E | 100 (37) |
| Change in ctDNA since baseline | |
| Clearance | 137 (51) |
| No clearance, decrease from baseline | 44 (16) |
| No clearance, increase from baseline | 89 (33) |
| Percentage change in tumour measurement | |
| Mean (sd) | -29.7 (52.8) |
| Median (Min,Max) | -32.5 (-100.0, 197.1) |
| Missing | 8 |
If we have a lookup table of variable names and labels that we
imported from a data dictionary we can set the variable labels for the
data frame and these will be used in the rm_ functions
ctDNA_names <- data.frame(var=names(ctDNA),
label=c('Patient ID',
'Study Cohort',
'Change in ctDNA since baseline',
'Number of weeks on treatment',
'Percentage change in tumour measurement'))
ctDNA <- set_labels(ctDNA,ctDNA_names)
rm_covsum(data=ctDNA,
covs=c('cohort','ctdna_status','size_change'))| n=270 | |
|---|---|
| Study Cohort | |
| A | 50 (19) |
| B | 14 (5) |
| C | 18 (7) |
| D | 88 (33) |
| E | 100 (37) |
| Change in ctDNA since baseline | |
| Clearance | 137 (51) |
| No clearance, decrease from baseline | 44 (16) |
| No clearance, increase from baseline | 89 (33) |
| Percentage change in tumour measurement | |
| Mean (sd) | -29.7 (52.8) |
| Median (Min,Max) | -32.5 (-100.0, 197.1) |
| Missing | 8 |
Individual labels can be changed with with the
set_var_labels command
ctDNA <- set_var_labels(ctDNA,
cohort="A new cohort label")
rm_covsum(data=ctDNA,
covs=c('cohort','ctdna_status','size_change'))| n=270 | |
|---|---|
| A new cohort label | |
| A | 50 (19) |
| B | 14 (5) |
| C | 18 (7) |
| D | 88 (33) |
| E | 100 (37) |
| Change in ctDNA since baseline | |
| Clearance | 137 (51) |
| No clearance, decrease from baseline | 44 (16) |
| No clearance, increase from baseline | 89 (33) |
| Percentage change in tumour measurement | |
| Mean (sd) | -29.7 (52.8) |
| Median (Min,Max) | -32.5 (-100.0, 197.1) |
| Missing | 8 |
Extract the variable labels to a data frame
## variable label
## 1 id Patient ID
## 2 cohort A new cohort label
## 3 ctdna_status Change in ctDNA since baseline
## 4 time Number of weeks on treatment
## 5 size_change Percentage change in tumour measurement
This function will accept a ggplot plot and replace the variable names (x-axis, y-axis and legend) with the variable labels. This is useful for more professional looking plots.
library(ggplot2)
p <- ggplot(data=ctDNA,aes(x=ctdna_status,y=size_change,colour=cohort))+
geom_point()
replace_plot_labels(p)predsum() summarises how well a set of predicted
probabilities recovers a binary outcome. Supply the observed outcome,
the predicted probabilities and the cut-off used to turn those
probabilities into predicted classes.
d <- pembrolizumab[complete.cases(pembrolizumab[, c('change_ctdna_group',
'baseline_ctdna',
'age', 'l_size')]), ]
fit <- glm(change_ctdna_group ~ baseline_ctdna + age + l_size,
family = 'binomial', data = d)
d$predicted <- predict(fit, type = 'response')
predsum(true = d$change_ctdna_group, predicted = d$predicted, cutoff = 0.5)| Statistic | Value (95%CI) |
|---|---|
| Prevalence | 0.55 (0.43, 0.66) |
| Sensitivity | 0.72 (0.56, 0.85) |
| Specificity | 0.55 (0.36, 0.72) |
| PPV | 0.66 (0.50, 0.80) |
| NPV | 0.62 (0.42, 0.79) |
| Accuracy | 0.64 (0.52, 0.75) |
| AUC | 0.62 (0.49, 0.74) |
| Sample Size | 73 |
| Events | 40 |
| Positive Category | Increase from baseline |
| Cut-off | 0.5 |
The default output is the set of statistics usually reported in a clinical setting: prevalence, sensitivity, specificity, positive and negative predictive value, accuracy and AUC. The table also records the sample size, the number of events, the cut-off used, and the level of the outcome being treated as the event.
That last row is worth reading. For a factor outcome the second level
is taken as the event, so above the model is predicting Increase
from baseline. If that is not what you intended, set
positive explicitly:
predsum(true = d$change_ctdna_group, predicted = d$predicted, cutoff = 0.5,
positive = 'Decrease from baseline')The output argument selects statistics by name, and
accepts several machine-learning measures that are not shown by
default:
predsum(true = d$change_ctdna_group, predicted = d$predicted, cutoff = 0.5,
output = c('accuracy', 'brier', 'f1', 'auc'))| Statistic | Value (95%CI) |
|---|---|
| Accuracy | 0.64 (0.52, 0.75) |
| Brier | 0.24 (0.21, 0.26) |
| F1 | 0.69 (0.56, 0.79) |
| AUC | 0.62 (0.49, 0.74) |
Brier score, F1 and AUC-PR have no closed-form confidence interval,
so predsum() obtains theirs by bootstrap. This is slower
than the other statistics; nboot controls the number of
replicates (default 2000).
These plots are designed for quick inspection of many variables, not for publication. This is the plotting version of rm_uvsum. As of 0.1.1 the variable names will be replaced by variable labels if they exist.
The plotuv function can also be used without a response variable to display summary of variables
Survival curves are now ggplot2-based, the older version, ggkmcif is deprecated from version 0.1.0
Similar to rm_uvsum and rm_mvsum, forest
plots can be created from univariate or multivariable models.
forestplot2 is deprecated from version 0.1.0. Variable labels are not
yet incorporated into the forest plots.
This will default to a log scale, but can be set to linear using
logScale=FALSE
forestplotUV(response="orr", covs=c("change_ctdna_group", "sex", "age", "l_size"),
data=pembrolizumab, family='binomial')As of version 0.1.3, you can include both unadjusted and adjusted
estimates in a multivariable forest plot by setting
include_unadjusted = TRUE:
glm_fit <- glm(orr~pdl1+age,
family='binomial',
data = pembrolizumab)
forestplotMV(glm_fit, include_unadjusted = TRUE)To identify the number of a column given the Excel column header
## G AB AZ
## 7 28 52
To identify the Excel header given a columns number
## 7 28 52
## "G" "AB" "AZ"
This function will search the current script or markdown file for R
packages and record the package name, functions called, the package
version and the citation(s) for the package. By default, function calls
and packages that only appear in commented code will be ignored, but
they can be included by setting ignore_comments = FALSE
| Package name | Functions called | Package version | Package citation |
|---|---|---|---|
| reportRmd | rm_covsum, rm_compactsum, rm_uvsum, glm, rm_mvsum, Surv, rm_uv_mv, outTable, nestTable, scrolling_table, rm_survsum, rm_survtime, rm_survdiff, rm_cifsum, set_labels, set_var_labels, extract_labels, ggplot, aes, geom_point, replace_plot_labels, clear_labels, plotuv, ggsave, ggkmcif2, forestplotUV, forestplotMV, forestplotUVMV, excelCol, excelColLetters, citation | 0.1.3 | Avery L, Del Bel R, Espin-Garcia O, Lajkosz K, Ong C, Pittman T, Santiago A, Weiss J, Xu W (2026). reportRmd: Tidy Presentation of Clinical Reporting. R package version 0.1.3, https://biostatspmh.github.io/reportRmd/. |
| rmarkdown | run | 2.29 | Allaire J, Xie Y, Dervieux C, McPherson J, Luraschi J, Ushey K, Atkins A, Wickham H, Cheng J, Chang W, Iannone R (2024). rmarkdown: Dynamic Documents for R. R package version 2.29, https://github.com/rstudio/rmarkdown. Xie Y, Allaire J, Grolemund G (2018). R Markdown: The Definitive Guide. Chapman and Hall/CRC. Xie Y, Dervieux C, Riederer E (2020). R Markdown Cookbook. Chapman and Hall/CRC. |
| survival | coxph | 3.8.3 | Therneau T (2024). A Package for Survival Analysis in R. R package version 3.8-3, https://CRAN.R-project.org/package=survival. Therneau TM, Grambsch PM (2000). Modeling Survival Data: Extending the Cox Model. Springer. |
| R | 4.4.2 | R Core Team (2024). R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing, Vienna, Austria. https://www.R-project.org/. |
Two parts of the package draw random numbers, and both are seeded by default so that a report re-knitted next month produces the same table as the one already circulated.
rm_covsum() and rm_compactsum() compare
categorical variables with a chi-squared test, switching to Fisher’s
exact test when any expected cell count falls below five. On a
large or sparse table the exact test can exceed its workspace, in which
case both functions fall back to a Monte Carlo approximation and say
so:
Fisher's exact test could not be computed for site; using Monte Carlo
simulation with B = 1000 and seed = 1.B sets the number of replicates and seed
fixes the random state for the duration of the call; the session’s own
random state is restored afterwards, so seeding here does not disturb
anything else in your document. Setting seed = NULL
restores the older behaviour in which the p-value varies between
calls.
When a Monte Carlo p-value has been used,
show.tests = TRUE records the replicate count alongside the
test name, so the table itself documents how the p-value was
obtained.
Because both functions now use the same expected-count rule,
rm_covsum() and rm_compactsum() select the
same test and report the same p-value for the same data.
predsum() bootstraps the intervals for Brier score, F1
and AUC-PR. It takes the same seed argument, with the same
default and the same restoration behaviour:
The following options can be set:
Example:
rm_uvsum(response = 'baseline_ctdna',
covs=c('age','sex','l_size','pdl1','tmb'),
data=pembrolizumab)| Estimate(95%CI) | p-value | N | |
|---|---|---|---|
| Age at study entry | 0.82 (-10.13, 11.76) | 0.88 | 94 |
| Patient Sex | 94 | ||
| Female | Reference | 58 | |
| Male | 56.61 (-228.71, 341.93) | 0.69 | 36 |
| Target lesion size at baseline | 1.21 (-1.12, 3.54) | 0.31 | 94 |
| PD L1 percent | -3.50 (-8.27, 1.27) | 0.15 | 93 |
| log of TMB | 18.78 (-125.18, 162.74) | 0.80 | 94 |
options('reportRmd.digits'=1)
rm_uvsum(response = 'baseline_ctdna',
covs=c('age','sex','l_size','pdl1','tmb'),
data=pembrolizumab)| Estimate(95%CI) | p-value | N | |
|---|---|---|---|
| Age at study entry | 0.8 (-10.1, 11.8) | 0.88 | 94 |
| Patient Sex | 94 | ||
| Female | Reference | 58 | |
| Male | 56.6 (-228.7, 341.9) | 0.69 | 36 |
| Target lesion size at baseline | 1.2 (-1.1, 3.5) | 0.31 | 94 |
| PD L1 percent | -3.5 (-8.3, 1.3) | 0.15 | 93 |
| log of TMB | 18.8 (-125.2, 162.7) | 0.80 | 94 |
For pdf to be correctly generate when using survival curves it is recommended that the cairo format be used. This can be specified with the following command in the setup code chunk:
knitr::opts_chunk$set(message = FALSE, warning = FALSE,dev="cairo_pdf")
Survival status and ctDNA levels for patients receiving pembrolizumab
A data frame with 94 rows and 15 variables:
Longitudinal changes in tumour size since baseline for patients by changes in ctDNA status (clearance, decrease or increase) since baseline.
A data frame with 270 rows and 5 variables: