-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.Rmd
192 lines (152 loc) · 4.08 KB
/
demo.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
---
title: "Using R to derive robust insights from real-world healthcare data"
subtitle: "Workshop given at R/Pharma 2022"
output: github_document
---
```{r, include = FALSE}
# Install packages (utilizing renv)
source(here::here("setup/packages.R"))
# Load libraries
library(tidyverse)
library(pointblank)
library(survival)
library(gtsummary)
library(survminer)
# Load the robustrwd package
devtools::load_all(here::here("robustrwd"))
# Turn on messaging
be_noisy()
```
# Load data
* Delivery = 02
* ETL version = 02
```{r, results = "hide", message=FALSE}
tables_02 <- receive_delivery_02()
tables_02_etl_02 <- tables_02 %>%
etl_02()
```
# QC
## Patients
```{r, echo = FALSE}
# Run on the patients data
patients_interrogation <- tables_02_etl_02$patients %>%
create_agent(
tbl_name = "Patients",
label = "Patients data (Post ETL 02)"
) %>%
expectations_patients() %>%
interrogate()
# Look at tidy results
patients_interrogation %>%
tidy_interrogation() %>%
knitr::kable()
# Summarise into single pass / fail
patients_checks_pass <- patients_interrogation %>%
tidy_interrogation() %>%
pull(any_fail) %>%
any() %>%
`==`(FALSE)
```
## Inpatient
```{r, echo = FALSE}
inpatient_interrogation <- tables_02_etl_02$inpatient %>%
create_agent(
tbl_name = "Inpatient",
label = "Inpatient data (Post ETL 02)"
) %>%
expectations_inpatient() %>%
interrogate()
# Look at tidy results
inpatient_interrogation %>%
tidy_interrogation() %>%
knitr::kable()
# Summarise into single pass / fail
inpatient_checks_pass <- inpatient_interrogation %>%
tidy_interrogation() %>%
pull(any_fail) %>%
any() %>%
`==`(FALSE)
```
## ORPP
```{r, echo = FALSE}
orpp_tbl <- tables_02_etl_02$patients %>%
add_orpp_inpatient(inpatient_tbl = tables_02_etl_02$inpatient) %>%
add_orpp_prescription(prescription_tbl = tables_02_etl_02$prescription)
orpp_interrogation <- create_agent(orpp_tbl,
tbl_name = "ORPP cohort",
label = "Patient level table"
) %>%
expectations_orpp() %>%
interrogate()
# Print result
orpp_interrogation %>%
tidy_interrogation() %>%
knitr::kable()
# Summarise into single pass / fail
orpp_checks_pass <- orpp_interrogation %>%
tidy_interrogation() %>%
pull(any_fail) %>%
any() %>%
`==`(FALSE)
```
# Cohort
## Attrition Table
```{r, echo = FALSE}
cohort_tbl <- orpp_tbl %>%
filter(
race_cd %in% c("White", "Black"),
sex_ident_cd == 'Male',
diabetes == TRUE,
inpatient_payment_median >= 10000,
prescription_rx_cost_median > 20,
survival_years >= 18
)
attrition_table <-
create_attrition(
orpp_tbl,
"Race is white or black" = race_cd %in% c("White", "Black"),
"Has Diabetes" = diabetes == TRUE,
"Is Male" = sex_ident_cd == "Male",
"Has at least 1000 inpatient costs" = inpatient_payment_median >= 10000,
"Median prescription cost is > 50" = prescription_rx_cost_median > 20,
"18 years of age or older" = survival_years >= 18
)
```
```{r, echo = FALSE}
# Show the attrition table
attrition_table %>%
knitr::kable()
```
## Attrition Plot
```{r, echo = FALSE, fig.width = 8, fig.height = 6}
# Plot an attrition chart
attrition_table %>%
plot_attrition()
cohort_tbl <- orpp_tbl %>%
filter(
race_cd %in% c("White", "Black"),
diabetes == TRUE,
sex_ident_cd == "Male",
inpatient_payment_median >= 10000,
prescription_rx_cost_median > 20,
survival_years >= 18
)
```
# Analyses
## Survival
```{r, fig.width = 8, fig.height = 7}
# Fit the survival model
# Follow-up time is survival_years
# Status indicator is death_observed
# Stratify results by sex_cd
fit <- survfit(Surv(survival_years, death_observed) ~ race_cd,
data = cohort_tbl
)
# Create the final Kaplan-Meier curve
ggsurvplot(fit,
conf.int = TRUE,
surv.median.line = "hv") +
labs(title = "Survival of patients from birth to death",
subtitle = "Using CMS Medicare claims synthetic public use files",
caption = glue::glue("Patients = {nrow(cohort_tbl)}\nPatients checks pass = {patients_checks_pass}\nInpatient checks pass = {inpatient_checks_pass}\nORPP checks pass = {orpp_checks_pass}"))
```