-
Notifications
You must be signed in to change notification settings - Fork 0
/
01_create_tables.Rmd
129 lines (117 loc) · 2.67 KB
/
01_create_tables.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
---
title: "SARS-CoV-2 vs Influenza: unpack cleaned data, create basic tables"
author: "Patrick G. Lyons, MD, MSc"
date: "2022-08-26"
output:
html_document: default
---
This script unpacks cleaned SARS-CoV-2 and Influenza data, consolidates data to one row per encounter, and creates basic comparative tables.
# Load libraries
```{r libraries, include = FALSE}
library(data.table)
library(tidyverse)
library(tidytable)
library(here)
library(tableone)
```
# Load cleaned data
```{r load data}
df <- fread(here("covflu_combined_deidentified.csv"))
```
# Drop variables related to multistate models
## (Code for multistate models is in 03_multistate_models.Rmd)
```{r}
df <-
df %>%
select.(
-c(max_o2_12h, hours_in_hosp, hours_12)
)
n_distinct.(df$arb_mrn) # 4785
n_distinct.(df$arb_enc) # 4785
dim(df) # 57907, 125
```
# Collapse data to one row per encounter
```{r}
df <-
df %>%
distinct.()
n_distinct.(df$arb_mrn) # 4785 - no patients were completely dropped
n_distinct.(df$arb_enc) # 4785
dim(df) # 4785, 125 - one row for every patient encounter
```
# Create LCA characteristics tables
```{r characteristics table}
# characteristics, stratified by virus
print(
tableone::CreateTableOne(
vars = c(
"age_years",
"female",
"race_nonwhite",
"bmi",
"min_spo2",
"min_sbp",
"max_pulse",
"max_resp",
"min_anc",
"max_potassium",
"min_sodium",
"max_lactate",
"min_albumin",
"min_hco3",
"elix_chf",
"elix_arrhythmia",
"elix_chronic_pulmonary_disease",
"elix_dm_combined",
"elix_renal_failure",
"elix_metastatic_cancer",
"elix_solid_tumor_without_metastasis",
"elix_coagulopathy"
),
factorVars = c(
"female",
"race_nonwhite",
"elix_chf",
"elix_arrhythmia",
"elix_chronic_pulmonary_disease",
"elix_dm_combined",
"elix_renal_failure",
"elix_metastatic_cancer",
"elix_solid_tumor_without_metastasis",
"elix_coagulopathy"
),
strata = "virus",
data = df
),
nonnormal = c(
"age_years", "bmi", "min_spo2", "max_pulse", "max_resp",
"min_sbp", "min_sodium", "max_lactate",
"min_albumin", "min_hco3"
),
quote = TRUE,
noSpaces = TRUE
)
```
```{r outcomes table}
# outcomes, stratified by virus
print(
tableone::CreateTableOne(
vars = c(
"los_hosp_hours",
"los_icu_hours",
"dead_or_hospice",
"icu_enc_01",
"imv_enc_01",
"vfd_28"
),
factorVars = c(
"dead_or_hospice",
"icu_enc_01",
"imv_enc_01"
),
strata = "virus",
data = df
),
nonnormal = c("los_hosp_hours", "los_icu_hours", "vfd_28")
)
```