-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6_Table_1.Rmd
177 lines (135 loc) · 4.59 KB
/
6_Table_1.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
---
title: "Table 1 for paper"
author: "Leon Di Stefano"
date: "`r Sys.Date()`"
output: html_document
params:
fit_name: "main_fit"
outcome_min: 28
outcome_max: 35
---
## Table 1 for paper
```{r}
knitr::opts_chunk$set(echo = TRUE)
require(here)
here::i_am(file.path("hcq_pooling_analysis", "6_Table_1.Rmd"))
source(here("hcq_pooling_analysis", "common.R"))
require(table1)
out_stub <- paste(params$outcome_min, params$outcome_max, sep = '-')
output_dir <- here("hcq_pooling_analysis", "output", out_stub)
output_model_dir <- file.path(output_dir, params$fit_name)
```
Need to
- Compute comorbidity sum (used in the model)
- Choose the correct azithro variables (also corticosteroids)
- Figure out exactly which variables to include
- Format their names nicely
- ✓ Simplify the continuous statistics to "median (q1 to q3)" + missingness
Function to use medians and IQRs:
```{r}
render_continuous_custom <- function (x, ...)
{
with(stats.apply.rounding(
stats.default(x),
digits = 1,
digits.pct = 0,
rounding.fn = round_pad # Decimal places rather than significant digits
), c("",
`mean (SD)` = sprintf("%s (%s)", MEAN, SD),
`median (IQR)` = sprintf("%s (%s to %s)",
MEDIAN, Q1, Q3)))
}
render_categorical_custom <- function(x) {
c("", sapply(stats.default(x), function(y) with(y,
sprintf("%d (%0.f)", FREQ, PCT))))
}
render_missing_custom <- function (x, ...)
{
with(stats.apply.rounding(stats.default(is.na(x), ...), digits.pct = 0, rounding.fn = round_pad)$Yes,
c(missing = sprintf("%s (%s%%)", FREQ, PCT)))
}
```
Need to load `data_tbl` to get the comorbidity count variable used in the model:
```{r}
baseline_formatted <- read_rds(file.path(output_dir, "patients.rds"))
data_tbl <- read_rds(file.path(output_dir, "data_tbl.rds"))
```
```{r}
nrow(baseline_formatted); nrow(data_tbl)
ncol(baseline_formatted); ncol(data_tbl)
```
```{r}
combined_tbl <-
left_join(
data_tbl %>% select(comorbidity_count, patient_id, niaid_outcome),
baseline_formatted %>% select(-niaid_outcome),
by = "patient_id")
dim(combined_tbl)
```
Create azithro variable:
```{r}
combined_tbl <-
combined_tbl %>%
mutate(
azithro_use = case_when(
azithro & on_azithromycin ~ "assigned, took",
(!azithro) & on_azithromycin ~ "not assigned, took (on or before d28)",
(!azithro) & (!on_azithromycin) ~ "not assigned, did not take",
azithro & (!on_azithromycin) ~ "assigned, did not take (on or before d28)",
),
covid_scale_baseline_fct = niaid_baseline_fct,
covid_scale_baseline_numeric = as.numeric(niaid_baseline), # original Stata encoding is correct
on_corticosteroids = as.logical(on_corticosteroids),
first_dose_at_enrollment = frstdose_days_after_enrdt == 0,
outcome_missing = is.na(niaid_outcome))
```
Set labels:
```{r}
label(combined_tbl$sex_fct) <- "Sex"
label(combined_tbl$race_simplified_fct) <- "Race (simplified)"
label(combined_tbl$ethnic_fct) <- "Ethnicity"
label(combined_tbl$age_5y) <- "Age (5 year bins)"
label(combined_tbl$bmi) <- "BMI"
label(combined_tbl$covid_scale_baseline_fct) <- "Baseline NCOSS"
label(combined_tbl$covid_scale_baseline_numeric) <- "Baseline NCOSS (numeric)"
label(combined_tbl$sym_onst_days_bfr_enrdt) <- "Days between symptom onset and enrollment"
label(combined_tbl$siteid) <- "Site"
label(combined_tbl$treat) <- "Treatment group"
label(combined_tbl$comorbidity_count) <- "Baseline comorbidity count"
label(combined_tbl$azithro_use) <- "Azithromycin use"
label(combined_tbl$on_corticosteroids) <- "Concurrent corticosteroid use (on or before d28)"
label(combined_tbl$first_dose_at_enrollment) <- "First dose recieved on day of enrollment"
label(combined_tbl$outcome_missing) <- "Missing outcome (NCOSS between d28-d35)"
```
```{r}
table_1 <-
table1(~ sex_fct +
race_simplified_fct + ethnic_fct +
age_5y +
bmi +
covid_scale_baseline_fct +
covid_scale_baseline_numeric +
sym_onst_days_bfr_enrdt +
comorbidity_count +
azithro_use +
on_corticosteroids +
first_dose_at_enrollment +
outcome_missing
| siteid * treat,
data = combined_tbl,
render.continuous = render_continuous_custom,
render.categorical = render_categorical_custom,
render.missing = render_missing_custom,
topclass = "Rtable1-grid Rtable1-center")
table_1
```
```{r}
require(kableExtra)
table1::t1kable(table_1)
```
```{r}
sessionInfo()
```
```{r}
Sys.time()
```