-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.Rmd
242 lines (154 loc) · 5.95 KB
/
index.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
---
title: "gtsummary"
subtitle: "Creating publication-ready analytical tables"
author: "Margie Hannum <br/><br/>Memorial Sloan Kettering Cancer Center<br/><br/>"
date: "February 26, 2020"
output:
xaringan::moon_reader:
css: [ninjutsu, default, rladies, rladies-fonts, "my-theme.css"]
lib_dir: libs
seal: false
nature:
ratio: 16:9
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
---
```{r setup, include=FALSE}
# xaringan::inf_mr()
options(htmltools.dir.version = FALSE)
knitr::opts_chunk$set(echo = TRUE, eval = TRUE)
library(tidyverse)
library(rlang)
library(knitr)
library(gtsummary)
library(gt)
set.seed(78987)
theme_set(mskRvis::theme_biostat())
```
class: inverse, left, middle
# **gtsummary**: Creating publication-ready analytical tables
.large[
**Margie Hannum**
Research Biostatistician, Department of Epidemiology & Biostatistics
Memorial Sloan Kettering Cancer Center
**RLadies NYC**
February 26, 2020
]
.medium[.footnote[Twitter: @Margaret-Hannum Github: @margarethannum ]]
---
# Motivation: reproducible, presentation-ready tables
<img src="images/tang_retrospective_bonemarrow_demographic.png" width=60%>
.footnote[<a href="https://www.nature.com/articles/s41409-019-0441-4">Tang et. al, *Bone Marrow Transplantation* (February 2019)</a>]
???
- In our department we make table 1 and summarize regression models all the time. We all had our own siloed way to do this, some people had personal packages and some people just had scripts to do what they wanted.
- As a department we wanted a unified way to make these tables, nothing out there did exactly what we wanted, with the level of customizability that we wanted.
-Create reproducible summary and analytic tables that are ready to present. Create demographic tables, summarize regression models, and report analysis results.
-Other packages out there to create similar tables are opinionated without being very customizable
-What if a collaborator wants 2 decimal places? 3? Mean (Range) for some variables and Median (IQR) for others? Bolding significant p-values?
A special kind of confidence interval formula instead of the default?
- Often end up doing formatting after-the-fact which is not reproducible! Or, people have their own siloed code to make tables a particular way that they like (also not reproducible and shareable, unless they also make a package)
---
# Motivation: reproducible, presentation-ready tables
<img src="images/tang_retrospective_bonemarrow_mva.png" width=60%>
.footnote[<a href="https://www.nature.com/articles/s41409-019-0441-4">Tang et. al, *Bone Marrow Transplantation* (February 2019)</a>]
---
# {gtsummary} Overview
.large[
.pull-left[
* Package will create your tabular summaries, with sensible defaults that are highly customizable
- Summarize data frames/tibbles
- Summarize regression models
- Customize tables
- Report statistics from {gtsummary} tables inline in R Markdown
* Leverages {broom}, {labelled}, {tidyselect}, and {gt} packages to get the job done!
* CRAN version 1.2.6 released 2020-02-13
]
]
.pull-right[
<img src="images/gtsummary_logo.png" width=100%>
]
---
# Background: {gt}
.large[
.pull-left[
* New package from RStudio
* Package for printing highly customized tables
* Goal is to unify code for creating tables in HTML, Word (via RTF), and PDF
* Check it out! https://gt.rstudio.com/
]
.pull-right[
<img src="images/gt_logo.png" width=90%>
]
]
???
-Gauge room for who uses kable/gt
-When Dan started developing gtsummary last year it was originally designed for our tables to be printed using knitr::kable(). But mid-last-year Rich Iannone from RStudio started developing a table construction package called {gt}, and even though it’s still in development (and not on CRAN), since it’s from the RStudio world we anticipate it will have full support and eventually be widely adopted, so he switched our package to take full advantage of the functionality {gt} offers. Still can use our package and print with kable, more on that later.
---
# Background: {gt}
<img src="images/gt_parts_of_a_table.png" width=70%>
.pull-left[.footnote[Image source: https://gt.rstudio.com/]]
???
the gt documentation is great!
all functions grouped by the part of a table they modify
---
# Background: {gt}
<img src="images/gt_workflow_diagram.png" width=100%>
.pull-left[.footnote[Image source: https://gt.rstudio.com/]]
???
* Workflow: input data frame or tibble, create gt object (list with data and formatting elements), output gt table as HTML (previewed in the Viewer).
---
# {gtsummary} Print Engines - gt or kable?
.large[
.pull-left[
## gt
♥ Highly Customizable
♥ All output includes informative footnotes, indents levels
♥ HTML Output
⚠ PDF Output still in dev
⚠ MS Word Output via RTF still in dev, requires re-sizing of tables by hand
]
.pull-right[
## kable
⚠ Less Customizable
⚠ Footnotes and spanning headers stripped from all output. No indents.
♥ HTML Output
♥ PDF Output
♥ MS Word Output
]
**We built {gtsummary} as a companion to {gt} and highly recommend it!**
]
???
.footnote[All examples shown use {gt} print engine]
---
# **trial** data set overview
.pull-left[
```{r}
head(trial, 3) #<<
```
<p align="center"><img src="images/gt_trial_info.png" width=60%>
]
.medium[
.pull-right[
* Throughout this presentation examples will use the `trial` data set, included with {gtsummary}.
* Data set contains baseline characteristics of 200 patients who received Drug A or Drug B. Includes outcome of tumor response to the treatment.
* Variables have label attributes assigned using the `labelled` package.
* For simplicity in this presentation, subset data to a few variables of interest:
```{r, results = FALSE}
sm_trial <- trial %>% #<<
select(trt, age, response, grade) #<<
```
]
]
---
```{r child='02-tbl_summary.Rmd'}
```
---
```{r child='03-tbl_regression.Rmd'}
```
---
```{r child='05-customization.Rmd'}
```
---
```{r child='06-conclusion.Rmd'}
```