-
Notifications
You must be signed in to change notification settings - Fork 0
/
pubhlth390e.R
170 lines (144 loc) · 4.98 KB
/
pubhlth390e.R
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
# PubHlth 390e Script for datasets
library(tidyverse)
library(nhanesA)
#Confounders 2013
demogconf2013 <- nhanes('DEMO_H') %>%
select(c('SEQN', 'RIDAGEYR', 'RIAGENDR', 'RIDRETH3', 'INDHHIN2', 'INDFMPIR'))
#head(demogconf2013)
write_csv(demogconf2013, "confounders2013.csv")
#Confounders 2015
demogconf2015 <- nhanes('DEMO_I') %>%
select(c('SEQN', 'RIDAGEYR', 'RIAGENDR', 'RIDRETH3', 'INDHHIN2', 'INDFMPIR'))
#head(demogconf2015)
write_csv(demogconf2015, "confounders2015.csv")
#Confounders 2017
demogconf2017 <- nhanes('DEMO_J') %>%
select(c('SEQN', 'RIDAGEYR', 'RIAGENDR', 'RIDRETH3', 'INDHHIN2', 'INDFMPIR'))
#head(demogconf2017)
write_csv(demogconf2017, "confounders2017.csv")
# Group 1
orgphos2013 <- nhanes('UPHOPM_H')
depress2013 <- nhanes('DPQ_H')
group1 <- merge(orgphos2013, depress2013, by = "SEQN")
write_csv(group1, "group1.csv")
# Group 1 and Confounders
g1_comp = merge(group1, demogconf2013, by = "SEQN")
write_csv(g1_comp, "g1_complete.csv")
# Group 2
nicoturi2015 <- nhanes('UCOT_I')
kidney2015 <- nhanes('KIQ_U_I')
group2 <- merge(nicoturi2015, kidney2015, by = "SEQN")
write_csv(group2, "group2.csv")
# Group 2 and Confounders
g2_comp = merge(group2, demogconf2015, by = "SEQN")
write_csv(g2_comp, "g2_complete.csv")
# Group 3
pah2015 <- nhanes('PAH_I')
heart2015 <- nhanes('CDQ_I')
group3 <- merge(pah2015, heart2015, by = "SEQN")
write_csv(group3, "group3.csv")
# Group 3 and Confounders
g3_comp = merge(group3, demogconf2015, by = "SEQN")
write_csv(g3_comp, "g3_complete.csv")
# Group 4
pah2015 <- nhanes('PAH_I')
depress2015 <- nhanes('DPQ_I')
group4 <- merge(pah2015, depress2015, by = "SEQN")
write_csv(group4, "group4.csv")
# Group 4 and Confounders
g4_comp = merge(group4, demogconf2015, by = "SEQN")
write_csv(g4_comp, "g4_complete.csv")
#Group 4 - Youssef requests
head(group4)
group4_yr <- group4 %>%
select(c('SEQN', 'URXP01'))
group4_yr$dep_score = rowSums(group4[,c(17:26)])
group4_yr = na.omit(group4_yr)
head(group4_yr)
write_csv(group4_yr, "group4_yr.csv")
# Group 4 YR and Confounders
g4yr_comp = merge(group4_yr, demogconf2015, by = "SEQN")
write_csv(g4yr_comp, "g4yr_complete.csv")
# Group 5
bpa2015 <-nhanes('EPHPP_I')
body2015 <- nhanes('BMX_I')
group5 <- merge(bpa2015, body2015, by = "SEQN")
write_csv(group5, "group5.csv")
# Group 5 and Confounders
g5_comp = merge(group5, demogconf2015, by = "SEQN")
write_csv(g5_comp, "g5_complete.csv")
# Group 6
pah2013 <- nhanes('PAH_H')
cog2013 <- nhanes('CFQ_H')
group6 <- merge(pah2013, cog2013, by = "SEQN")
write_csv(group6, "group6.csv")
# Group 6 and Confounders
g6_comp = merge(group6, demogconf2013, by = "SEQN")
write_csv(g6_comp, "g6_complete.csv")
# Group 7
smoking2017 <- nhanes('SMQ_J')
cotininebl2017 <- nhanes('COT_J')
leadbl2017 <- nhanes('PBCD_J')
asthma2017 <- nhanes('MCQ_J')
shs2017 <- nhanes('SMQSHS_J')
group7 <- merge(smoking2017, cotininebl2017, by = "SEQN") %>%
merge(leadbl2017, by = "SEQN") %>%
merge(asthma2017, by = 'SEQN') %>%
merge(shs2017, by = 'SEQN')
write_csv(group7, "group7.csv")
# Group 7 and Confounders
g7_comp = merge(group7, demogconf2017, by = "SEQN")
write_csv(g7_comp, "g7_complete.csv")
#Group 7 - Youssef requests
head(group7)
group7_yr <- group7 %>%
select(c('SEQN', 'LBXCOT', 'MCQ010'))
group7_yr = na.omit(group7_yr)
head(group7_yr)
write_csv(group7_yr, "group7_yr.csv")
# Group 4 YR and Confounders
g7yr_comp = merge(group7_yr, demogconf2017, by = "SEQN")
write_csv(g7yr_comp, "g7yr_complete.csv")
# Youssef
demo <- nhanes('DEMO_J')
pfas <- nhanes('PFAS_J')
pfasplus <- nhanes('SSPFAS_J')
liver <- nhanes('LUX_J')
alcohol <- nhanes('ALQ_J')
metals <- nhanes('PBCD_J')
hepa <- nhanes('HEPA_J')
hepc <- nhanes('HEPC_J')
enz <- nhanes('BIOPRO_J')
voc <- nhanes('VOCWB_J')
demo1 = merge(pfas, liver, by = "SEQN")
demo2 = merge(demo1,demo, by = "SEQN")
demo3 = merge(demo2,metals, by = "SEQN")
demo4 = merge(demo3,hepc, by = "SEQN")
demo5 = merge(demo4,enz, by = "SEQN")
demo6 = merge(demo5,voc, by = "SEQN")
#ademo1 = merge(pfas, liver, all = TRUE)
#ademo2 = merge(ademo1,demo, all = TRUE)
#ademo3 = merge(ademo2,metals, all = TRUE)
#ademo4 = merge(ademo3,hepc, all = TRUE)
#ademo5 = merge(ademo4,enz, all = TRUE)
#ademo6 = merge(ademo5,voc, all = TRUE)
pfas$pfos = pfas$LBXMFOS+pfas$LBXNFOS
pfas$pfoa = pfas$LBXBFOA+pfas$LBXNFOA
pfas2 = pfas[,-c(4,6,8,10,12:20)]
names(pfas2) = c("SEQN","WTSB2YR","pfda","pfhxs","nmefosa","PFNA","pfunda","pfos","pfoa")
base = merge(pfas2,demo5, by = "SEQN")
#base
#glm.pfos = glm(pfos ~ INDFMPIR, data = base, family = Gamma)
#summary(glm.pfos) %>% pander()
#ggplot(data = glm.pfos, mapping = aes(x = pfos, y = INDFMPIR)) +
# geom_point(size = 0.5, alpha = 0.5) +
# geom_smooth(method = "loess", color = "red")
#abase = merge(pfas2, ademo5, all = TRUE)
#abase
#a.glm.pfos = glm(pfos ~ INDFMPIR, data = abase, family = gaussian)
#summary(a.glm.pfos) %>% pander()
#ggplot(data = a.glm.pfos, mapping = aes(x = pfos, y = INDFMPIR)) +
# geom_point(size = 0.5, alpha = 0.5) +
# geom_smooth(method = "loess", color = "blue")
write_csv(base, "youssef.csv")
#write_csv(abase, "abase.csv")