-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_management.Rmd
312 lines (186 loc) · 11.9 KB
/
data_management.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
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
---
title: "final_project_adv_1"
output: word_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(Hmisc)
library(tidyr)
library(corrplot)
library(BayesFactor)
library (BSDA)
library(MASS)
library(agricolae)
```
#Standard Biochemistry Profile
#https://wwwn.cdc.gov/nchs/nhanes/search/datapage.aspx?Component=Laboratory&CycleBeginYear=2017
#https://wwwn.cdc.gov/Nchs/Nhanes/2017-2018/DPQ_J.htm
#https://wwwn.cdc.gov/Nchs/Nhanes/2017-2018/BIOPRO_J.htm
#https://wwwn.cdc.gov/Nchs/Nhanes/2017-2018/MCQ_J.htm
#https://wwwn.cdc.gov/Nchs/Nhanes/2017-2018/HUQ_J.htm
The Data that is used for the project is taken from National Health and Nutrition Examination Survey's (NHANES) 2017-2018 Laboratory Data (Standard Biochemistry Profile) and Questionnaire Data (Mental Health - Depression Screener & Medical Conditions).
###2017-18
```{r}
bio_chem_full <- sasxport.get("BIOPRO_J_2017_18.XPT")
mental_health_data_1 <- mental_health_data <- sasxport.get("DPQ_J_2017_18.XPT")
hospital_utilization <- sasxport.get("HUQ_J_2017_18.XPT")
bio_chem_2017_18 <- merge(bio_chem_full, mental_health_data)
##combined data set, subsets of this data set will be use in this project to different type of statistical analysis
bio_chem_2017_18 <- merge(bio_chem_2017_18, hospital_utilization)
bio_chem_2017_18<- bio_chem_2017_18[,c("lbxsatsi", "lbxsal","lbxscr", "lbxsgl" , "lbxsch" ,"lbxsir" ,"lbxstr", "lbxsapsi","lbxsassi","lbxsc3si","lbxsbu","lbxsclsi","lbxsck","lbxsgb","lbxsgtsi","lbxsldsi","lbxsossi","lbxsph","lbxsksi","lbxsnasi","lbxstb","lbxsca","lbxstp","lbxsua","dpq010","dpq020","dpq030","dpq040","dpq050","dpq060","dpq070","dpq090","huq090")]
```
###2015-16
```{r}
bio_chem_full <- sasxport.get("BIOPRO_J_2015_16.XPT")
mental_health_data_2 <- mental_health_data <- sasxport.get("DPQ_J_2015_16.XPT")
hospital_utilization <- sasxport.get("HUQ_J_2015_16.XPT")
bio_chem_2015_16 <- merge(bio_chem_full, mental_health_data)
##combined data set, subsets of this data set will be use in this project to different type of statistical analysis
bio_chem_2015_16 <- merge(bio_chem_2015_16, hospital_utilization)
bio_chem_2015_16<- bio_chem_2015_16[,c("lbxsatsi", "lbxsal","lbxscr", "lbxsgl" , "lbxsch" ,"lbxsir" ,"lbxstr", "lbxsapsi","lbxsassi","lbxsc3si","lbxsbu","lbxsclsi","lbxsck","lbxsgb","lbxsgtsi","lbxsldsi","lbxsossi","lbxsph","lbxsksi","lbxsnasi","lbxstb","lbxsca","lbxstp","lbxsua","dpq010","dpq020","dpq030","dpq040","dpq050","dpq060","dpq070","dpq090","huq090")]
```
###2013-14
```{r}
bio_chem_full <- sasxport.get("BIOPRO_J_2013_14.XPT")
mental_health_data_3 <- mental_health_data <- sasxport.get("DPQ_J_2013_14.XPT")
hospital_utilization <- sasxport.get("HUQ_J_2013_14.XPT")
bio_chem_2013_14 <- merge(bio_chem_full, mental_health_data)
##combined data set, subsets of this data set will be use in this project to different type of statistical analysis
bio_chem_2013_14 <- merge(bio_chem_2013_14, hospital_utilization)
bio_chem_2013_14<- bio_chem_2013_14[,c("lbxsatsi", "lbxsal","lbxscr", "lbxsgl" , "lbxsch" ,"lbxsir" ,"lbxstr", "lbxsapsi","lbxsassi","lbxsc3si","lbxsbu","lbxsclsi","lbxsck","lbxsgb","lbxsgtsi","lbxsldsi","lbxsossi","lbxsph","lbxsksi","lbxsnasi","lbxstb","lbxsca","lbxstp","lbxsua","dpq010","dpq020","dpq030","dpq040","dpq050","dpq060","dpq070","dpq090","huq090")]
```
###2011-12
```{r}
bio_chem_full <- sasxport.get("BIOPRO_J_2011_12.XPT")
mental_health_data_4 <- mental_health_data <- sasxport.get("DPQ_J_2011_12.XPT")
hospital_utilization <- sasxport.get("HUQ_J_2011_12.XPT")
bio_chem_2011_12 <- merge(bio_chem_full, mental_health_data)
##combined data set, subsets of this data set will be use in this project to different type of statistical analysis
bio_chem_2011_12 <- merge(bio_chem_2011_12, hospital_utilization)
bio_chem_2011_12<- bio_chem_2011_12[,c("lbxsatsi", "lbxsal","lbxscr", "lbxsgl" , "lbxsch" ,"lbxsir" ,"lbxstr", "lbxsapsi","lbxsassi","lbxsc3si","lbxsbu","lbxsclsi","lbxsck","lbxsgb","lbxsgtsi","lbxsldsi","lbxsossi","lbxsph","lbxsksi","lbxsnasi","lbxstb","lbxsca","lbxstp","lbxsua","dpq010","dpq020","dpq030","dpq040","dpq050","dpq060","dpq070","dpq090","huq090")]
```
```{r}
bio_chem <- rbind(bio_chem_2017_18,bio_chem_2015_16)
bio_chem <- rbind(bio_chem,bio_chem_2013_14)
bio_chem <- rbind(bio_chem,bio_chem_2011_12)
bio_chem <- bio_chem %>% drop_na()
#yes hospital
#minor
nrow(subset(bio_chem, (huq090 == 1 & dpq020 == 1 )))
nrow(subset(bio_chem, (dpq020 == 1 )))
#major
nrow(subset(bio_chem, (huq090 == 1 & (dpq020 == 2)| (dpq020 == 3) )))
nrow(subset(bio_chem, (dpq020 == 2)| (dpq020 == 3) ))
#missing
# nrow(subset(bio_chem, (dpq020 == 7)| (dpq020 == 9)| (dpq020 == ".") ))
```
The BIOPRO_J dataset has 41 variables initially. After removing all refrigerated serums and keeping only one type of measurement for a type of variable, I get 18 variables that represents body chemicals. I also added variables from mental health data (DPQ_J) that asks about 'Have little interest in doing things'(dpq010), 'Feeling down, depressed, or hopeless'(dpq020), and 'Trouble sleeping or sleeping too much' (dpq030). Also, rows that have NA values are dropped.
```{r}
bio_chem_trimmed<- bio_chem[,c("lbxsatsi","lbxsal","lbxscr", "lbxsgl" , "lbxsch" ,"lbxsir" ,"lbxstr", "lbxsapsi","lbxsassi","lbxsc3si","lbxsbu","lbxsclsi","lbxsck","lbxsgb","lbxsgtsi","lbxsldsi","lbxsossi","lbxsph","lbxsksi","lbxsnasi","lbxstb","lbxsca","lbxstp","lbxsua","dpq010","dpq020","dpq030","dpq040","dpq050","dpq060","dpq070","dpq090","huq090")]
bio_chem_trimmed <- bio_chem_trimmed %>% drop_na()
bio_chem_trimmed <- subset(bio_chem_trimmed, dpq010 != ".")
bio_chem_trimmed <- subset(bio_chem_trimmed, dpq010 != "7")
bio_chem_trimmed <- subset(bio_chem_trimmed, dpq010 != "9")
bio_chem_trimmed <- subset(bio_chem_trimmed, dpq020 != ".")
bio_chem_trimmed <- subset(bio_chem_trimmed, dpq020 != "7")
bio_chem_trimmed <- subset(bio_chem_trimmed, dpq020 != "9")
bio_chem_trimmed <- subset(bio_chem_trimmed, dpq030 != ".")
bio_chem_trimmed <- subset(bio_chem_trimmed, dpq030 != "7")
bio_chem_trimmed <- subset(bio_chem_trimmed, dpq030 != "9")
bio_chem_trimmed <- subset(bio_chem_trimmed, dpq040 != ".")
bio_chem_trimmed <- subset(bio_chem_trimmed, dpq040 != "7")
bio_chem_trimmed <- subset(bio_chem_trimmed, dpq040 != "9")
bio_chem_trimmed <- subset(bio_chem_trimmed, dpq050 != ".")
bio_chem_trimmed <- subset(bio_chem_trimmed, dpq050 != "7")
bio_chem_trimmed <- subset(bio_chem_trimmed, dpq050 != "9")
bio_chem_trimmed <- subset(bio_chem_trimmed, dpq060 != ".")
bio_chem_trimmed <- subset(bio_chem_trimmed, dpq060 != "7")
bio_chem_trimmed <- subset(bio_chem_trimmed, dpq060 != "9")
bio_chem_trimmed <- subset(bio_chem_trimmed, dpq070 != ".")
bio_chem_trimmed <- subset(bio_chem_trimmed, dpq070 != "7")
bio_chem_trimmed <- subset(bio_chem_trimmed, dpq070 != "9")
bio_chem_trimmed <- subset(bio_chem_trimmed, dpq090 != ".")
bio_chem_trimmed <- subset(bio_chem_trimmed, dpq090 != "7")
bio_chem_trimmed <- subset(bio_chem_trimmed, dpq090 != "9")
bio_chem_trimmed <- subset(bio_chem_trimmed, huq090 != ".")
bio_chem_trimmed <- subset(bio_chem_trimmed, huq090 != "7")
bio_chem_trimmed <- subset(bio_chem_trimmed, huq090 != "9")
bio_chem_trimmed$dpq010[bio_chem_trimmed$dpq010 != 0] <- 1
bio_chem_trimmed$dpq030[bio_chem_trimmed$dpq030 != 0] <- 1
bio_chem_trimmed$dpq040[bio_chem_trimmed$dpq040 != 0] <- 1
bio_chem_trimmed$dpq050[bio_chem_trimmed$dpq050 != 0] <- 1
bio_chem_trimmed$dpq060[bio_chem_trimmed$dpq060 != 0] <- 1
bio_chem_trimmed$dpq070[bio_chem_trimmed$dpq070 != 0] <- 1
bio_chem_trimmed$dpq090[bio_chem_trimmed$dpq090 != 0] <- 1
bio_chem_trimmed$huq090[bio_chem_trimmed$huq090 == 2] <- 0
bio_chem_trimmed <- bio_chem_trimmed %>% drop_na()
head(bio_chem_trimmed)
#,"dpq010","dpq020","dpq030","dpq040","dpq050","dpq060","dpq070","dpq080","dpq090","dpq100"
```
```{r}
# model_dpq020 <- lm( dpq020 ~ 0+lbxsatsi+lbxsapsi+lbxsassi+lbxsc3si+lbxsbu+lbxsclsi+lbxsck+lbxsgb+lbxsgtsi+lbxsldsi+lbxsossi+lbxsph+lbxsksi+lbxsnasi+lbxstb+lbxsca+lbxstp+lbxsua+dpq010+dpq030+dpq040+dpq050+dpq060+dpq070+dpq090+huq090,data=bio_chem_trimmed)
# summary(model_dpq020)
# stepAIC(model_dpq020, direction='both', k = log(nrow(bio_chem_trimmed)))
```
```{r}
bio_chem_trimmed_all <- bio_chem_trimmed
bio_chem_trimmed_all$dpq020[bio_chem_trimmed_all$dpq020 != 0] <- 1
bio_chem_trimmed_all <- bio_chem_trimmed_all[c("lbxsatsi", "lbxsal","lbxscr", "lbxsgl" , "lbxsch" ,"lbxsir" ,"lbxstr", "lbxsapsi","lbxsassi","lbxsc3si","lbxsbu","lbxsclsi","lbxsck","lbxsgb","lbxsgtsi","lbxsldsi","lbxsossi","lbxsph","lbxsksi","lbxsnasi","lbxstb","lbxsca","lbxstp","lbxsua","dpq020")]
head(bio_chem_trimmed_all)
write.csv(bio_chem_trimmed_all,"bio_chem_trimmed_chem_mental.csv")
```
```{r}
library(synthpop)
nrow(subset(bio_chem_trimmed_all, dpq020 == "1"))
nrow(subset(bio_chem_trimmed_all, dpq020 == "0"))
df_pos <- subset(bio_chem_trimmed_all, dpq020 == "1")
h_dat <- syn(df_pos, k = 9900, method = "parametric", seed = 1)
write.syn(h_dat,file = "df_train_pos_syn.csv", filetype = "csv")
#synthtic data will be added manually in every case
```
```{r}
df_train_pos_syn <- read.csv("bio_chem_trimmed_chem_mental_synthetic.csv", header=TRUE)
#df_train_pos_syn <- df_train_pos_syn[-1]
#bio_chem_trimmed_all <-df_train_pos_syn
```
##minor
```{r}
bio_chem_trimmed_normal <- bio_chem_trimmed
bio_chem_trimmed_normal <- subset(bio_chem_trimmed_normal, dpq020 != ".")
bio_chem_trimmed_normal <- subset(bio_chem_trimmed_normal, dpq020 != "7")
bio_chem_trimmed_normal <- subset(bio_chem_trimmed_normal, dpq020 != "9")
bio_chem_trimmed_normal <- subset(bio_chem_trimmed_normal, dpq020 != "2")
bio_chem_trimmed_normal <- subset(bio_chem_trimmed_normal, dpq020 != "3")
bio_chem_trimmed_normal$dpq020[bio_chem_trimmed_normal$dpq020 != 0] <- 1
bio_chem_trimmed_normal <- bio_chem_trimmed_normal %>% drop_na()
head(bio_chem_trimmed_normal)
bio_chem_trimmed_normal <- bio_chem_trimmed_normal[c("lbxsatsi", "lbxsal","lbxscr", "lbxsgl" , "lbxsch" ,"lbxsir" ,"lbxstr", "lbxsapsi","lbxsassi","lbxsc3si","lbxsbu","lbxsclsi","lbxsck","lbxsgb","lbxsgtsi","lbxsldsi","lbxsossi","lbxsph","lbxsksi","lbxsnasi","lbxstb","lbxsca","lbxstp","lbxsua","dpq020")]
write.csv(bio_chem_trimmed_normal,"bio_chem_trimmed_chem_mental_normal.csv")
```
```{r}
nrow(subset(bio_chem_trimmed_normal, dpq020 == "1"))
nrow(subset(bio_chem_trimmed_normal, dpq020 == "0"))
df_pos <- subset(bio_chem_trimmed_normal, dpq020 == "1")
h_dat <- syn(df_pos, k = 11000, method = "parametric", seed = 1)
write.syn(h_dat,file = "df_train_pos_syn_normal.csv", filetype = "csv")
```
##major
```{r}
bio_chem_trimmed_heavyl <- bio_chem_trimmed
bio_chem_trimmed_heavyl <- subset(bio_chem_trimmed_heavyl, dpq020 != ".")
bio_chem_trimmed_heavyl <- subset(bio_chem_trimmed_heavyl, dpq020 != "7")
bio_chem_trimmed_heavyl <- subset(bio_chem_trimmed_heavyl, dpq020 != "9")
bio_chem_trimmed_heavyl <- subset(bio_chem_trimmed_heavyl, dpq020 != "1")
bio_chem_trimmed_heavyl$dpq020[bio_chem_trimmed_heavyl$dpq020 != 0] <- 1
bio_chem_trimmed_heavyl <- bio_chem_trimmed_heavyl %>% drop_na()
bio_chem_trimmed_heavyl <- bio_chem_trimmed_heavyl[c("lbxsatsi", "lbxsal","lbxscr", "lbxsgl" , "lbxsch" ,"lbxsir" ,"lbxstr", "lbxsapsi","lbxsassi","lbxsc3si","lbxsbu","lbxsclsi","lbxsck","lbxsgb","lbxsgtsi","lbxsldsi","lbxsossi","lbxsph","lbxsksi","lbxsnasi","lbxstb","lbxsca","lbxstp","lbxsua","dpq020")]
head(bio_chem_trimmed_heavyl)
write.csv(bio_chem_trimmed_heavyl,"bio_chem_trimmed_chem_mental_heavy.csv")
```
```{r}
nrow(subset(bio_chem_trimmed_heavyl, dpq020 == "1"))
nrow(subset(bio_chem_trimmed_heavyl, dpq020 == "0"))
df_pos <- subset(bio_chem_trimmed_heavyl, dpq020 == "1")
h_dat <- syn(df_pos, k = 12500, method = "parametric", seed = 1)
write.syn(h_dat,file = "df_train_pos_syn_heavy.csv", filetype = "csv")
```