-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnh_medicaid_diagram_codebook.Rmd
More file actions
387 lines (297 loc) · 14.6 KB
/
nh_medicaid_diagram_codebook.Rmd
File metadata and controls
387 lines (297 loc) · 14.6 KB
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
---
title: "New Hampshire DHHS Medicaid Data Diagram and Codebook"
output:
distill::distill_article:
toc: true
toc_depth: 3
self_contained: false
---
```{r include=FALSE}
# ### call libraries
# library(easypackages)
# libraries("tidyverse","foreign","lubridate","reshape2", "ggplot2","RColorBrewer","knitr","forcats","openxlsx","statar","svDialogs","xlsx", "magrittr","stringr", "data.table","janitor","kableExtra","leaflet", "readr", "rmarkdown","rowr", "gganimate", "gifski","tidycensus","sf","htmltools","acs","tigris","mapview","rgeos", "ggrepel", "censusxy","gdata","lavaan","mclust","tmap","rmarkdown", "raster","rgeos","gmapsdistance","viridis","cowplot","lintr","leaflet.extras","censusapi","data.table","gridGraphics","readxl","haven","ggridges","extrafont","extrafontdb","datamodelr","Lahman","DiagrammeR","fs","readxl","rsvg","V8","ragg","distill","DataExplorer","csgjcr")
# Load packages, functions, and data
source("code/00_library.R")
source("code/01_functions.R")
source("code/rdas.R")
```
```{r include=FALSE,message=FALSE,warning=FALSE}
### suppress scientific notation
options(scipen=999)
### set chunk output specifications
knitr::opts_chunk$set(
echo = TRUE,
dev = "ragg_png",
cache = FALSE)
### set theme
theme_set(theme_minimal())
```
# Data Diagram
**Notes:**
* In addition to the diagnosis classification values provided in `data_dictionary`, which uses ICD-10 lookup values for diagnoses after 2015, we need to use ICD-9 lookup values for diagnoses prior to 2015. I downloaded and incorporated it into ‘14_medicaid’ cleaning syntax. ICD-9 data was downloaded from https://www.cms.gov/medicare/coordination-benefits-recovery-overview/icd-code-lists and currently lives here: JR_NH\Data\Medicaid Data
+ For ICD-9 data, there aren’t CCSR category descriptions that come with the data, but I've downloaded "CCS" category descriptions (CCS category descriptions seem to be the predecessor to CCSR categories: CCS stands for clinical classification software and CCSR is clinical classification software refined). I downloaded additional lookup values from ‘Single Level CSS’ link here: http://healthydatascience.com/ahrq_ccs_icd.html
+ If we’re hoping to use the CCS/CCSR fields for analysis, we may have to do additional manual cleaning to standardize them.
* To create `booking_id` from the data provided by DHHS, we combine `unique_person_id` and `booking_date`.
* To join `medicaid_encounters` to `medicaid_enrollment`, the `medicaid_encounters$first_dos_dt` must be >= `medicaid_enrollment$eligiblity_begin_date` and <= `medicaid_enrollment$eligiblity_end_date`
* Similarly, to join `medicaid_jail_all_counties` to `medicaid_enrollment`, `medicaid_jail_all_counties$booking_date` must be >= `medicaid_enrollment$eligibility_begin_date` and <= `medicaid_enrollment$eligibility_end_date`
**To confirm:**
* There are pure duplicates in the `medicaid_encounters`file -- how do we ensure these are okay? Double check with Uma?
* What is the exact date cut-off for ICD-9 versus ICD-10?
```{r layout="l-page",echo=FALSE,message=FALSE,warning=FALSE}
# knitr::include_graphics("img/nh_medicaid_data_diagram.png")
```
<br><br>
# Data Codebooks
**For all missing data plots**, here are the % missingness categories: "Good" <= 5% missing, "OK" <= 40% missing, "Bad" <= 80% missing, and "Remove" = 100% missing
```{r include=FALSE}
### pull in medicaid data from external hard drive
# medicaid events
medicaid_encounters <- read_csv("D:/CSG-Encounters File 201407-202106.txt") %>%
clean_names()
# medicaid enrollment
medicaid_enrollment <- read_csv("D:/Medicaid Enrollment Data For County Matched Members.txt") %>%
clean_names()
# eligibility categories descriptions
medicaid_categories <- read_excel("D:/Categories of Eligibility Description.xlsx") %>%
clean_names()
# medicaid data dictionary (icd-10)
medicaid_dictionary <- read_excel(paste0(sp_data_path, "/Data/DHHS_data_dictionary.xlsx"),
sheet = "DX_to_CCSR_Mapping",
skip = 1) %>%
clean_names()
### import medicaid_jail_all -- medicaid jail data that we'll compare to the numbers from the jail administrative files
### this file lives on the external hard drive (created and exported in `13_medicaid.R`)
medicaid_jail_all <- read_rds("D:/Analytic/medicaid_jail_all.rds")
medicaid_jail_all_counties <- medicaid_jail_all %>%
clean_names() %>%
distinct(unique_person_id,
booking_id,
.keep_all = TRUE) %>%
mutate(unique_person_booking_id = paste0(unique_person_id,
booking_id)) ### creating unique booking id with both individual and booking IDs
```
```{r include=FALSE}
### custom function to tweak color output from package (so that green is good and red is something other than good)
plot_missing_2 <-
function (data, group = list(Good = 0.05, Okay = 0.4, Poor = 0.8,
Remove = 1), geom_label_args = list(), title = NULL, ggtheme = theme_gray(),
theme_config = list(legend.position = c("bottom")))
{
pct_missing <- Missingness <- NULL
missing_value <- data.table(profile_missing(data))
group <- group[sort.list(unlist(group))]
invisible(lapply(seq_along(group), function(i) {
if (i == 1) {
missing_value[pct_missing <= group[[i]], `:=`(Missingness,
names(group)[i])]
} else {
missing_value[pct_missing > group[[i - 1]] & pct_missing <=
group[[i]], `:=`(Missingness, names(group)[i])]
}
}))
output <- ggplot(missing_value, aes_string(x = "feature",
y = "num_missing", fill = "Missingness")) + geom_bar(stat = "identity") +
scale_fill_manual("Missingness", values = c("Good"="green2","Okay"="gold","Poor"="darkorange","Remove"="firebrick2")) + coord_flip() + xlab("Features") +
ylab("Missing Rows")
geom_label_args_list <- list(mapping = aes(label = paste0(round(100 *
pct_missing, 2), "%")))
output <- output + do.call("geom_label", c(geom_label_args_list,
geom_label_args))
class(output) <- c("single", class(output))
plotDataExplorer(plot_obj = output, title = title, ggtheme = ggtheme,
theme_config = theme_config)
}
```
<br>
## Medicaid Enrollment
### Medicaid Enrollment, Data Overview
```{r layout="l-body",echo=FALSE,warning=FALSE,message=FALSE}
### run the `DataExplorer` function introduce()
medicaid_enrollment_table <- DataExplorer::introduce(medicaid_enrollment) %>%
pivot_longer(rows:memory_usage, names_to = "Measure", values_to = "Count")
kable(medicaid_enrollment_table,
format.args = list(big.mark = ","),
align=rep('c')) %>%
kable_styling(bootstrap_options = c("striped",
"hover",
"condensed",
"responsive"),
row_label_position = "l")
```
<br>
### Medicaid Enrollment, Fields Included
```{r layout="l-body",echo=FALSE,warning=FALSE,message=FALSE}
### set sharepoint path using csgjcr::csg_sp_path function
medicaid_enrollment_col_names <- as_data_frame(colnames(medicaid_enrollment)) %>%
dplyr::rename(`Columns` = value)
### output names via kable table
kable(medicaid_enrollment_col_names, format.args = list(big.mark = ","), align=rep('c')) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"), row_label_position = "l")
```
<br>
### Medicaid Enrollment, Missing Data
```{r layout="l-page",echo=FALSE,warning=FALSE,message=FALSE}
### run the `DataExplorer` function plot_missing()
plot_missing_2(medicaid_enrollment)
```
<br><br>
## Medicaid Categories File
### Medicaid Categories, Data Overview
```{r layout="l-body",echo=FALSE,warning=FALSE,message=FALSE}
### run the `DataExplorer` function introduce()
medicaid_categories_table <- DataExplorer::introduce(medicaid_categories) %>%
pivot_longer(rows:memory_usage, names_to = "Measure", values_to = "Count")
kable(medicaid_categories_table,
format.args = list(big.mark = ","),
align=rep('c')) %>%
kable_styling(bootstrap_options = c("striped",
"hover",
"condensed",
"responsive"),
row_label_position = "l")
```
<br>
### Medicaid Categories, Fields Included
```{r layout="l-body",echo=FALSE,warning=FALSE,message=FALSE}
### set sharepoint path using csgjcr::csg_sp_path function
medicaid_categories_col_names <- as_data_frame(colnames(medicaid_categories)) %>%
dplyr::rename(`Columns` = value)
### output names via kable table
kable(medicaid_categories_col_names, format.args = list(big.mark = ","), align=rep('c')) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"), row_label_position = "l")
```
<br>
### Medicaid Categories, Missing Data
```{r layout="l-page",echo=FALSE,warning=FALSE,message=FALSE}
### run the `DataExplorer` function plot_missing()
plot_missing_2(medicaid_categories)
```
<br><br>
## Medicaid Encounters File
### Medicaid Encounters, Data Overview
```{r layout="l-body",echo=FALSE,warning=FALSE,message=FALSE}
### run the `DataExplorer` function introduce()
medicaid_encounters_table <- DataExplorer::introduce(medicaid_encounters) %>%
pivot_longer(rows:memory_usage, names_to = "Measure", values_to = "Count")
kable(medicaid_encounters_table,
format.args = list(big.mark = ","),
align=rep('c')) %>%
kable_styling(bootstrap_options = c("striped",
"hover",
"condensed",
"responsive"),
row_label_position = "l")
```
<br>
### Medicaid Encounters, Fields Included
```{r layout="l-body",echo=FALSE,warning=FALSE,message=FALSE}
### set sharepoint path using csgjcr::csg_sp_path function
medicaid_encounters_col_names <- as_data_frame(colnames(medicaid_encounters)) %>%
dplyr::rename(`Columns` = value)
### output names via kable table
kable(medicaid_encounters_col_names, format.args = list(big.mark = ","), align=rep('c')) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"), row_label_position = "l")
```
<br>
### Medicaid Encounters, Missing Data
```{r layout="l-page",echo=FALSE,warning=FALSE,message=FALSE}
### run the `DataExplorer` function plot_missing()
plot_missing_2(medicaid_encounters)
```
<br><br>
## Medicaid Dictionary File
### Medicaid Dictionary, Data Overview
```{r layout="l-body",echo=FALSE,warning=FALSE,message=FALSE}
### run the `DataExplorer` function introduce()
medicaid_dictionary_table <- DataExplorer::introduce(medicaid_dictionary) %>%
pivot_longer(rows:memory_usage, names_to = "Measure", values_to = "Count")
kable(medicaid_dictionary_table,
format.args = list(big.mark = ","),
align=rep('c')) %>%
kable_styling(bootstrap_options = c("striped",
"hover",
"condensed",
"responsive"),
row_label_position = "l")
```
<br>
### Medicaid Dictionary, Fields Included
```{r layout="l-body",echo=FALSE,warning=FALSE,message=FALSE}
### set sharepoint path using csgjcr::csg_sp_path function
medicaid_dictionary_col_names <- as_data_frame(colnames(medicaid_dictionary)) %>%
dplyr::rename(`Columns` = value)
### output names via kable table
kable(medicaid_dictionary_col_names, format.args = list(big.mark = ","), align=rep('c')) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"), row_label_position = "l")
```
<br>
### Medicaid Dictionary, Missing Data
```{r layout="l-page",echo=FALSE,warning=FALSE,message=FALSE}
### run the `DataExplorer` function plot_missing_2()
plot_missing_2(medicaid_dictionary)
```
<br><br>
## Medicaid Dictionary File
### Medicaid Dictionary, Data Overview
```{r layout="l-body",echo=FALSE,warning=FALSE,message=FALSE}
### run the `DataExplorer` function introduce()
medicaid_dictionary_table <- DataExplorer::introduce(medicaid_dictionary) %>%
pivot_longer(rows:memory_usage, names_to = "Measure", values_to = "Count")
kable(medicaid_dictionary_table,
format.args = list(big.mark = ","),
align=rep('c')) %>%
kable_styling(bootstrap_options = c("striped",
"hover",
"condensed",
"responsive"),
row_label_position = "l")
```
<br>
### Medicaid Dictionary, Fields Included
```{r layout="l-body",echo=FALSE,warning=FALSE,message=FALSE}
### set sharepoint path using csgjcr::csg_sp_path function
medicaid_dictionary_col_names <- as_data_frame(colnames(medicaid_dictionary)) %>%
dplyr::rename(`Columns` = value)
### output names via kable table
kable(medicaid_dictionary_col_names, format.args = list(big.mark = ","), align=rep('c')) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"), row_label_position = "l")
```
<br>
### Medicaid Dictionary, Missing Data
```{r layout="l-page",echo=FALSE,warning=FALSE,message=FALSE}
### run the `DataExplorer` function plot_missing_2()
plot_missing_2(medicaid_dictionary)
```
<br><br>
## Medicaid Jail Data File (this is the analytic file we created from the 9 separate jail files provided by DHHS)
### Medicaid Jail File, Data Overview
```{r layout="l-body",echo=FALSE,warning=FALSE,message=FALSE}
### run the `DataExplorer` function introduce()
medicaid_jail_all_counties_table <- DataExplorer::introduce(medicaid_jail_all_counties) %>%
pivot_longer(rows:memory_usage, names_to = "Measure", values_to = "Count")
kable(medicaid_jail_all_counties_table,
format.args = list(big.mark = ","),
align=rep('c')) %>%
kable_styling(bootstrap_options = c("striped",
"hover",
"condensed",
"responsive"),
row_label_position = "l")
```
<br>
### Medicaid Jail File, Fields Included
```{r layout="l-body",echo=FALSE,warning=FALSE,message=FALSE}
### set sharepoint path using csgjcr::csg_sp_path function
medicaid_jail_all_counties_col_names <- as_data_frame(colnames(medicaid_jail_all_counties)) %>%
dplyr::rename(`Columns` = value)
### output names via kable table
kable(medicaid_jail_all_counties_col_names, format.args = list(big.mark = ","), align=rep('c')) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"), row_label_position = "l")
```
<br>
### Medicaid Jail File, Missing Data
```{r layout="l-page",echo=FALSE,warning=FALSE,message=FALSE}
### run the `DataExplorer` function plot_missing_2()
plot_missing_2(medicaid_jail_all_counties)
```
<br><br>