-
Notifications
You must be signed in to change notification settings - Fork 0
/
prep_table1_demographics.Rmd
392 lines (345 loc) · 15.2 KB
/
prep_table1_demographics.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
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
388
389
390
391
---
title: "Trait for Analyses"
author: "Jordan Barone"
date: "5/25/2021"
output: html_document
---
*these are just examples with some common trait variables! None of these are required for Table 1 or any descriptives*
##view data
```{r get descriptives, warning=FALSE}
#describe() to get N's for each variable
describe(clearALL_select, fast = TRUE, data = vars>1000)
```
#count and factor variables
```{r}
#summary stats for age
clearALL_select %>% summarise(meanage=mean(age, na.rm=TRUE),
sdage=sd(age, na.rm = TRUE),
minage=min(age, na.rm = TRUE),
maxage=max(age, na.rm = TRUE))
#example to count n participants in a race group
clearALL_select %>% count(race==1)
#table of participants by race
racesum <- clearALL_select %>% group_by(race) %>%
summarise(n=n())
racesum$race <- factor(racesum$race, levels= c(1, 2, 3, 4, 7, 8, NA), labels = c("Caucasian",
"African American",
"Asian",
"American Indian",
"More than one race",
"Decline to Answer"))
kable(racesum)
#ethnicity
ethnicitysum <- clearALL_select %>%
group_by(ethnicity, race) %>%
summarize (n=n())
ethnicitysum$race <- factor(ethnicitysum$race, levels= c(1, 2, 3, 4, 7, 8, NA), labels = c("Caucasian",
"African American",
"Asian",
"American Indian",
"More than one race",
"Decline to Answer"))
ethnicitysum$ethnicity <- factor(ethnicitysum$ethnicity, levels = c(1, 2, 3),
labels = c("Hispanic", "Non-Hispanic", "Decline to Answer"))
kable(ethnicitysum)
```
#various tables of factor labels
```{r}
#table of mean attempts
attemptssum <- clearALL_select %>% summarise(n=n(),
meanattempts=mean(numfullatt, na.rm=TRUE),
meaninterrupted=mean(numintatt, na.rm = TRUE),
meanaborted=mean(numabatt, na.rm = TRUE))
kable(attemptssum, digits = 3)
#table counting how many have ANY attempt vs none
attemptYN <- clearALL_select %>%
mutate(allattempts=rowSums(select(., ends_with("att")), na.rm = TRUE),
SBs = ifelse(allattempts>=1, "At Least One Attempt","No Hx of Attempt")) %>%
group_by(SBs) %>% summarize(n=n())
#tables categorizing diagnoses
SUDyn <- clearALL_select %>% mutate(anySUD=ifelse(lifetimedx_hxSUDalc!=0 |
lifetimedx_hxSUDinh!=0 |
lifetimedx_hxSUDMJ!=0 |
lifetimedx_hxSUDopioid!=0 |
lifetimedx_hxSUDother!=0 |
lifetimedx_hxSUDothhall!=0 |
lifetimedx_hxSUDsha!=0 |
lifetimedx_hxSUDstim!=0 |
lifetimedx_hxSUDPCP!=0, "Hx of SUD", "No SUD")) %>%
select(., starts_with("lifetimedx_hxSUD"), anySUD) %>%
group_by(anySUD) %>% summarize(n=n())
kable(anySUD)
EDyn <- clearALL_select %>% mutate(anyED=ifelse(lifetimedx_hxAN!=0 |
lifetimedx_hxBN!=0 |
lifetimedx_hxBED!=0 |
lifetimedx_hxothereat!=0,
"Hx of ED", "No ED")) %>% select(.,
lifetimedx_hxAN,
lifetimedx_hxBN,
lifetimedx_hxBED,
lifetimedx_hxothereat,
anyED) %>%
group_by(anyED) %>% summarize(n=n())
kable(EDyn)
hxTrauma <- clearALL_select %>% mutate(anyTrauma=ifelse(lifetimedx_hxPTSD!=0 |
lifetimedx_hxothertrauma!=0 |
traumainterview_sexab==1 |
traumainterview_physab==1 |
traumainterview_childphysab==1 |
traumainterview_childsexab==1 |
traumainterview_childothertrauma==1,
"Hx of Trauma", "No Hx of Trauma")) %>%
group_by(anyTrauma) %>% summarize(n=n())
kable(hxTrauma)
# how many participants have a current depressive disorder?
clearALL_select %>% group_by(currentdx_MDD, currentdx_PDD) %>% summarise(n=n())
#how many participants have current GAD?
clearALL_select %>% group_by(currentdx_GAD) %>% summarise(n=n())
```
#### Playing with tableone package
```{r}
library(tableone)
#create list of continuous variables we want in demographic table
contVars <- c("age", "ageatmenarche", "agefirstMDE", "numpregnancies", "number_children",
"numfullatt", "numintatt", "numabatt", "numhosp"
)
#save race, education, ethnicity, marital status, and sexual orientation with factor labels (these are the variables that have more than 1 level)
clearALL_select$maritalstatusf <- factor(clearALL_select$maritalstatus, levels = c(1,2,3,4,5),
labels = c("Currently Married",
"Widowed",
"Never Married",
"Separated or Divorced",
"Living with Partner"))
clearALL_select$educationf <- factor(clearALL_select$education, levels = c(1,2,3,4,5,6,7,8),
labels = c("0-4 grades",
"5-8 grades",
"some high school",
"graduated from high school",
"trade school or business college",
"some college (inc. completion of jr college)",
"grad. from 4-yr college",
"post-grad work at a university"))
clearALL_select$sexorientationf <- factor(clearALL_select$sexorientation, levels = c(1,2,3,4),
labels = c("Homosexual(lesbian,gay)",
"Bisexual",
"Heterosexual",
"Other"))
#create list of categorical variables we want in demographic table
catVars <-c("race", "ethnicity", "education", "maritalstatus",
"sexorientation","genderorient", "everpregyn",
"lifetimedx_hxbipolar2",
"lifetimedx_hxMDD",
"lifetimedx_hxlifetimedx_hxhxPDD",
"lifetimedx_hxothDD",
"lifetimedx_hxSUDalc",
"lifetimedx_hxSUDsha",
"lifetimedx_hxSUDMJ",
"lifetimedx_hxSUDstim",
"lifetimedx_hxSUDopioid",
"lifetimedx_hxpanicDO",
"lifetimedx_hxagora",
"lifetimedx_hxSAD",
"lifetimedx_hxphobia",
"lifetimedx_hxGAD",
"lifetimedx_hxotheranx",
"lifetimedx_hxOCD",
"lifetimedx_hxAN",
"lifetimedx_hxBN",
"lifetimedx_hxBED",
"lifetimedx_hxothereat",
"lifetimedx_hxPTSD",
"lifetimedx_hxothertrauma",
"lifetimedx_hxotherDx",
"currentdx_MDD",
"currentdx_PDD",
"currentdx_PMDD",
"currentdx_othDD",
"currentdx_SUDalc",
"currentdx_SUDsha",
"currentdx_SUDmj",
"currentdx_SUDopioid",
"currentdx_PanicDO",
"currentdx_Agoraphobia",
"currentdx_SAD",
"currentdx_Phobi",
"currentdx_GAD",
"currentdx_OtherAnx",
"currentdx_OCD",
"currentdx_AN",
"currentdx_BN",
"currentdx_otheat",
"currentdx_ADHD",
"currentdx_PTSD",
"currentdx_Othertrauma",
"traumainterview_physab",
"traumainterview_childsexab",
"traumainterview_childothertrauma",
"traumainterview_physab.1",
"traumainterview_sexab"
)
#create full list of variables for table1
allVars <- clearALL_select %>% select(c("age", "ageatmenarche", "agefirstMDE", "numpregnancies",
"number_children","numfullatt", "numintatt", "numabatt", "numhosp",
"race", "ethnicity", "education", "maritalstatus",
"sexorientation","genderorient", "everpregyn",
"lifetimedx_hxbipolar2",
"lifetimedx_hxMDD",
"lifetimedx_hxlifetimedx_hxhxPDD",
"lifetimedx_hxothDD",
"lifetimedx_hxSUDalc",
"lifetimedx_hxSUDsha",
"lifetimedx_hxSUDMJ",
"lifetimedx_hxSUDstim",
"lifetimedx_hxSUDopioid",
"lifetimedx_hxpanicDO",
"lifetimedx_hxagora",
"lifetimedx_hxSAD",
"lifetimedx_hxphobia",
"lifetimedx_hxGAD",
"lifetimedx_hxotheranx",
"lifetimedx_hxOCD",
"lifetimedx_hxAN",
"lifetimedx_hxBN",
"lifetimedx_hxBED",
"lifetimedx_hxothereat",
"lifetimedx_hxPTSD",
"lifetimedx_hxothertrauma",
"lifetimedx_hxotherDx",
"currentdx_MDD",
"currentdx_PDD",
"currentdx_PMDD",
"currentdx_othDD",
"currentdx_SUDalc",
"currentdx_SUDsha",
"currentdx_SUDmj",
"currentdx_SUDopioid",
"currentdx_PanicDO",
"currentdx_Agoraphobia",
"currentdx_SAD",
"currentdx_Phobi",
"currentdx_GAD",
"currentdx_OtherAnx",
"currentdx_OCD",
"currentdx_AN",
"currentdx_BN",
"currentdx_otheat",
"currentdx_ADHD",
"currentdx_PTSD",
"currentdx_Othertrauma",
"traumainterview_physab",
"traumainterview_childsexab",
"traumainterview_childothertrauma",
"traumainterview_physab.1",
"traumainterview_sexab"))
#labeledvars <- ClearALL %>% select(c(educationf, sexorientationf, maritalstatusf))
#CreateTableOne(data = ClearALL, vars = labeledvars)
clearALL_select %>% group_by(maritalstatusf) %>% summarize(n=n())
clearALL_select %>% group_by(sexorientationf) %>% summarize(n=n())
clearALL_select %>% group_by(educationf) %>% summarize(n=n())
```
# viewing the TableOne package
```{r}
#full tableOne
fulltbl1 <- CreateTableOne(data = allVars, factorVars = catVars)
summary(fulltbl1$CatTable)
summary(fulltbl1$ContTable)
```
### plot common trait variables
```{r echo=FALSE}
studysample.labs <- c("CLEAR1 (NC)", "CLEAR2 (Chicago)")
names(studysample.labs) <- c("1", "2")
#age histogram
clearALL_select %>% ggplot(aes(x=age, fill=as_factor(studysample)))+
geom_histogram(binwidth = 5, position = "dodge")
#age, by study
clearALL_select %>% ggplot(aes(x=age, fill=as_factor(studysample)))+
geom_histogram(binwidth = 5, position = "dodge")+
facet_grid(.~studysample,labeller = labeller(studysample=studysample.labs))+
xlab("Age")
#race, by clear1 and clear2
clearALL_select %>% ggplot(aes(x=as_factor(race),
fill=as_factor(race)))+
geom_bar()+
theme(axis.text.x = element_text(angle = 45, hjust = 1),
legend.position = "none")+
facet_grid(.~studysample, labeller = labeller(studysample=studysample.labs))+
xlab("Race")+
labs(caption = "Race Breakdown by Study")
#race, total
clearALL_select %>% ggplot(aes(x=as_factor(race),
fill=as_factor(race)))+
geom_bar()+
theme(axis.text.x.bottom = element_text(angle = 45, hjust = 1),
legend.position = "none")+
xlab("Race")
#Marital status by study
clearALL_select %>% ggplot(aes(x=as_factor(maritalstatus),
group=as_factor(studysample),
fill=as_factor(maritalstatus)))+
geom_bar()+
facet_grid(.~studysample, labeller = labeller(studysample = studysample.labs))+
theme(axis.text.x.bottom = element_text(angle = 45, hjust = 1),
legend.position = "none")+
xlab("Marital Status")
#marital status, total
clearALL_select %>% ggplot(aes(x=as_factor(maritalstatus),
fill=as_factor(maritalstatus)))+
geom_bar()+
theme(axis.text.x.bottom = element_text(angle = 45, hjust = 1),
legend.position = "none")+
xlab("Marital Status")
#sexual orientation by study
clearALL_select %>% ggplot(aes(x=as_factor(sexorientation),
group=as_factor(studysample),
fill=as_factor(sexorientation)))+
geom_bar()+
facet_grid(.~studysample, labeller = labeller(studysample = studysample.labs))+
theme(axis.text.x.bottom = element_text(angle = 45, hjust = 1),
legend.position = "none")+
xlab("Sexual Orientation")
#sexual orientation, total
clearALL_select %>% ggplot(aes(x=as_factor(sexorientation),
fill=as_factor(sexorientation)))+
geom_bar()+
theme(axis.text.x.bottom = element_text(angle = 45, hjust = 1),
legend.position = "none")+
xlab("Sexual Orientation")
#education by study
clearALL_select %>% ggplot(aes(x=as_factor(education),
group=as_factor(studysample),
fill=as_factor(education)))+
geom_bar()+
facet_grid(.~studysample, labeller = labeller(studysample = studysample.labs))+
theme(axis.text.x.bottom = element_text(angle = 45, hjust = 1),
legend.position = "none")+
xlab("Education")
#education, total
clearALL_select %>% ggplot(aes(x=as_factor(education), fill=as_factor(education)))+
geom_bar()+
theme(axis.text.x.bottom = element_text(angle = 45, hjust = 1),
legend.position = "none")+
xlab("Education")
#hx of trauma
clearALL_select %>% mutate(anyTrauma=ifelse(lifetimedx_hxPTSD!=0 |
lifetimedx_hxothertrauma!=0 |
traumainterview_sexab==1 |
traumainterview_physab==1 |
traumainterview_childphysab==1 |
traumainterview_childsexab==1 |
traumainterview_childothertrauma==1,
"Hx of Trauma", "No Hx of Trauma")) %>%
ggplot(aes(x=anyTrauma, fill=anyTrauma))+
geom_histogram(stat = "count")
clearALL_select %>% mutate(anySUD=ifelse(lifetimedx_hxSUDalc!=0 |
lifetimedx_hxSUDinh!=0 |
lifetimedx_hxSUDMJ!=0 |
lifetimedx_hxSUDopioid!=0 |
lifetimedx_hxSUDother!=0 |
lifetimedx_hxSUDothhall!=0 |
lifetimedx_hxSUDsha!=0 |
lifetimedx_hxSUDstim!=0 |
lifetimedx_hxSUDPCP!=0, "Hx of SUD", "No SUD")) %>%
select(., starts_with("lifetimedx_hxSUD"), anySUD) %>%
ggplot(aes(x=anySUD, fill=anySUD))+
geom_histogram(stat = "count")
```