-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAGESEXGAD7PHQ9_formatting_and_descriptives.Rmd
1145 lines (1002 loc) · 38.7 KB
/
AGESEXGAD7PHQ9_formatting_and_descriptives.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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: Age and sex-related variability in the presentation of anxiety and depression
symptoms in the GLAD Study - formatting and descriptives.
author: "Katherine N Thompson"
date: "10/02/2020"
output:
word_document:
toc: yes
toc_depth: '2'
html_document:
df_print: paged
toc: yes
toc_depth: 2
toc_float:
collapsed: no
number_sections: no
highlight: monochrome
theme: cerulean
code_folding: show
html_notebook:
theme: cerulean
toc: yes
---
# Set up
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,
comment = NA,
prompt = FALSE,
cache = FALSE)
```
Delete everything in your global environment
```{r Clear global environment, include=FALSE}
remove(list = ls())
```
Packages
```{r Load packages, include=FALSE}
library(knitr)
library(car)
library(psych)
library(lubridate)
library(broom)
library(summarytools)
library(data.table)
library(eeptools)
library(magrittr)
library(reshape2)
library(lavaan)
library(mlogit)
library(foreign)
library(polycor)
library(REdaS)
library(scales)
library(forcats)
library(GPArotation)
library(tidyverse)
```
Retrieve the recent date
```{r Recent date, include=FALSE}
date = Sys.Date()
```
Define colours for plotting
```{r GLAD colour palette , include=FALSE}
palette = c(
"#efc00b", #female
"#b7dee8" #male
)
palette3 <- c("#78D9C5","#F5BE5E","#EEB6E9")
```
```{r source data path file}
source("../data_paths.R")
```
Read in demographics
```{r read in demographic data, include=FALSE}
data.dem.raw <- readRDS(paste0(data.raw_path, "DEM.rds"))
dim(data.dem.raw)
colnames(data.dem.raw)
data.dem.raw$birthyear <- NULL
# data.dem.raw$startdate <- NULL
data.dem.raw$enddate <- NULL
colnames(data.dem.raw)
```
```{r check start dates}
min(data.dem.raw$startdate)
max(data.dem.raw$startdate)
```
Read in self report mental health disorders
```{r Read in self report mental health disorders, include=FALSE}
data.mhd.raw <- readRDS(paste0(data.raw_path, "MHD.rds"))
dim(data.mhd.raw)
colnames(data.mhd.raw)
data.mhd.raw$sex <- NULL
data.mhd.raw$age <- NULL
data.mhd.raw$birthyear <- NULL
data.mhd.raw$startdate <- NULL
data.mhd.raw$enddate <- NULL
colnames(data.mhd.raw)
```
Read in PHQ9
```{r Read in PHQ, include=FALSE}
data.phq.raw <- readRDS(paste0(data.raw_path, "PHQ.rds"))
dim(data.phq.raw)
colnames(data.phq.raw)
data.phq.raw$sex <- NULL
data.phq.raw$age <- NULL
data.phq.raw$birthyear <- NULL
data.phq.raw$startdate <- NULL
data.phq.raw$enddate <- NULL
colnames(data.phq.raw)
```
Read in GAD7
```{r Read in GAD7, include=FALSE}
data.gad.raw <- readRDS(paste0(data.raw_path, "GAD.rds"))
dim(data.gad.raw)
colnames(data.gad.raw)
data.gad.raw$sex <- NULL
data.gad.raw$age <- NULL
data.gad.raw$birthyear <- NULL
data.gad.raw$startdate <- NULL
data.gad.raw$enddate <- NULL
colnames(data.gad.raw)
```
## Prepare item lists
```{r prepare item groups, include=FALSE}
# All the items in numeric form
ALL.items.full_numeric <- c("phq.anhedonia_numeric",
"phq.depressed_mood_numeric",
"phq.sleep_change_numeric",
"phq.little_energy_numeric",
"phq.eating_problems_numeric",
"phq.worthlessness_numeric",
"phq.concentration_problems_numeric",
"phq.motor_problems_numeric",
"phq.suicide_ideation_numeric",
"gad.feeling_anxious_numeric",
"gad.control_worrying_numeric",
"gad.worry_toomuch_numeric",
"gad.trouble_relaxing_numeric",
"gad.restless_numeric",
"gad.irritable_numeric",
"gad.feeling_afraid_numeric")
# All the items as factors
ALL.items.full <- c("phq.anhedonia",
"phq.depressed_mood",
"phq.sleep_change",
"phq.little_energy",
"phq.eating_problems",
"phq.worthlessness",
"phq.concentration_problems",
"phq.motor_problems",
"phq.suicide_ideation",
"gad.feeling_anxious",
"gad.control_worrying",
"gad.worry_toomuch",
"gad.trouble_relaxing",
"gad.restless",
"gad.irritable",
"gad.feeling_afraid")
# Create vector with items that are included in total score
GAD.items = c("gad.feeling_anxious_numeric",
"gad.control_worrying_numeric",
"gad.worry_toomuch_numeric",
"gad.trouble_relaxing_numeric",
"gad.restless_numeric",
"gad.irritable_numeric",
"gad.feeling_afraid_numeric")
# Create vector with items that are included in total score
PHQ.items = c("phq.anhedonia_numeric",
"phq.depressed_mood_numeric",
"phq.sleep_change_numeric",
"phq.little_energy_numeric",
"phq.eating_problems_numeric",
"phq.worthlessness_numeric",
"phq.concentration_problems_numeric",
"phq.motor_problems_numeric",
"phq.suicide_ideation_numeric")
# list of categorical items
cat.items <- c("phq.anhedonia.cat",
"phq.depressed_mood.cat",
"phq.sleep_change.cat",
"phq.little_energy.cat",
"phq.eating_problems.cat",
"phq.worthlessness.cat",
"phq.concentration_problems.cat",
"phq.motor_problems.cat",
"phq.suicide_ideation.cat",
"gad.feeling_anxious.cat",
"gad.control_worrying.cat",
"gad.worry_toomuch.cat",
"gad.trouble_relaxing.cat",
"gad.restless.cat",
"gad.irritable.cat",
"gad.feeling_afraid.cat")
# categorical items labeled for endorsement plot
cat.items.labelled <- c("phq.anhedonia.cat.labelled",
"phq.depressed_mood.cat.labelled",
"phq.sleep_change.cat.labelled",
"phq.little_energy.cat.labelled",
"phq.eating_problems.cat.labelled",
"phq.worthlessness.cat.labelled",
"phq.concentration_problems.cat.labelled",
"phq.motor_problems.cat.labelled",
"phq.suicide_ideation.cat.labelled",
"gad.feeling_anxious.cat.labelled",
"gad.control_worrying.cat.labelled",
"gad.worry_toomuch.cat.labelled",
"gad.trouble_relaxing.cat.labelled",
"gad.restless.cat.labelled",
"gad.irritable.cat.labelled",
"gad.feeling_afraid.cat.labelled")
# create data frame that doesn't include "worrying too much" item
ALL.items.full.withoutworry <- c("phq.anhedonia",
"phq.depressed_mood",
"phq.sleep_change",
"phq.little_energy",
"phq.eating_problems",
"phq.worthlessness",
"phq.concentration_problems",
"phq.motor_problems",
"phq.suicide_ideation",
"gad.feeling_anxious",
"gad.control_worrying",
"gad.trouble_relaxing",
"gad.restless",
"gad.irritable",
"gad.feeling_afraid")
# create data frame that doesn't include "concentration problems" item
ALL.items.full.withoutconcentration <- c("phq.anhedonia",
"phq.depressed_mood",
"phq.sleep_change",
"phq.little_energy",
"phq.eating_problems",
"phq.worthlessness",
"phq.motor_problems",
"phq.suicide_ideation",
"gad.feeling_anxious",
"gad.control_worrying",
"gad.trouble_relaxing",
"gad.restless",
"gad.irritable",
"gad.feeling_afraid")
# create data frame that doesn't include "concentration problems" and "irritability" item
ALL.items.full.withoutirritability <- c("phq.anhedonia",
"phq.depressed_mood",
"phq.sleep_change",
"phq.little_energy",
"phq.eating_problems",
"phq.worthlessness",
"phq.motor_problems",
"phq.suicide_ideation",
"gad.feeling_anxious",
"gad.control_worrying",
"gad.trouble_relaxing",
"gad.restless",
"gad.feeling_afraid")
# continuous variables for descriptives
continuous.variables <- c("PHQ.total.score",
"GAD.total.score",
"age")
```
PHQ and GAD scoring keys
Create vector with scoring key: If the item is reversed coded use -1. There needs to be the correct number of values for each item in the questionnaire.
```{r PHQ and GAD scoring keys, include=FALSE}
# PHQ
PHQ.n.items = 9 # total number of items of the questionnaire
PHQ.items.key <- c(1,1,1,1,1,1,1,1,1) # scoring key
# GAD
GAD.n.items = 7 # total number of items of the questionnaire
GAD.items.key <- c(1,1,1,1,1,1,1) # scoring key
```
# Missingness {.tabset .tabset-fade}
## PHQ Missingness NAs per person - count and percentages
```{r PHQ Missingness}
data.phq.raw$na.per.person.phq <- rowSums(is.na(data.phq.raw[,colnames(data.phq.raw) %in% PHQ.items]))
freq(data.phq.raw$na.per.person.phq)
data.phq.raw$miss_pc_total.phq <- data.phq.raw$na.per.person.phq/PHQ.n.items
freq(data.phq.raw$miss_pc_total.phq)
```
## GAD Missingness NAs per person - count and percentages
```{r GAD Missingness}
data.gad.raw$na.per.person.gad <- rowSums(is.na(data.gad.raw[,colnames(data.gad.raw) %in% GAD.items]))
freq(data.gad.raw$na.per.person.gad)
data.gad.raw$miss_pc_total.gad <- data.gad.raw$na.per.person.gad/GAD.n.items
freq(data.gad.raw$miss_pc_total.gad)
```
# Merge PHQ, GAD, demographics and mental health disorders
Create a list of the data frames to join together
```{r list of dataframes to merge}
dataframe_list <- list(
data.dem.raw,
data.mhd.raw,
data.gad.raw,
data.phq.raw
)
```
Join data frames
```{r join all datasets}
data.joined <- plyr::join_all(
dataframe_list,
by = "ID" # Alternatively you can join by several columns
)
#remove duplicate cols
data.joined <- data.joined[, !duplicated(colnames(data.joined))]
```
# **Data preparation** {.tabset .tabset-fade}
## Subset of individuals who signed up during the pandemic
Dates for the definition of prepandemic
```{r Potential dates for prepandemic definition}
# Date of the first COVID-19 case in the United Kingdom (UK)
date_first_case_uk_january_31 <- as.POSIXct("2020-01-31")
# Date for assumed higher awareness of COVID / Lockdown in Italy 4. March 2020 / first festivals cancelled
date_higher_awareness_march_1 <- as.POSIXct("2020-03-01")
# Date the UK went into lockdown
date_uk_lockdown_march_23 <- as.POSIXct("2020-03-23")
```
```{r Prepandemic definitions january_31}
data.joined <- data.joined %>%
mutate(
prepandemic_january_31_numeric =
if_else(
startdate > date_first_case_uk_january_31, # The GLAD sign up is dated before the cut off (> longer ago)
true = 0, # Participant has not signed up before the pandemic,
false = 1, # Participant has signed up before the pandemic,
missing = NA_real_
)
)
data.joined <- data.joined %>%
mutate(
prepandemic_january_31 =
recode_factor(
prepandemic_january_31_numeric,
"0" = "Sign up after 31st January",
"1" = "Sign up before 31st January"
)
)
data.joined %>%
freq(prepandemic_january_31)
```
```{r Prepandemic definitions march_1}
data.joined <- data.joined %>%
mutate(
prepandemic_march_1_numeric =
if_else(
startdate > date_higher_awareness_march_1, # The GLAD sign up is dated before the cut off (> longer ago)
true = 0, # Participant has not signed up before the pandemic,
false = 1, # Participant has signed up before the pandemic,
missing = NA_real_
)
)
data.joined <- data.joined %>%
mutate(
prepandemic_march_1 =
recode_factor(
prepandemic_march_1_numeric,
"0" = "Sign up after 1st March",
"1" = "Sign up before 1st March"
)
)
data.joined %>%
freq(prepandemic_march_1)
```
```{r Prepandemic definitions march_23}
data.joined <- data.joined %>%
mutate(
prepandemic_march_23_numeric =
if_else(
startdate > date_uk_lockdown_march_23, # The GLAD sign up is dated before the cut off (> longer ago)
true = 0, # Participant has not signed up before the pandemic,
false = 1, # Participant has signed up before the pandemic,
missing = NA_real_
)
)
data.joined <- data.joined %>%
mutate(
prepandemic_march_23 =
recode_factor(
prepandemic_march_23_numeric,
"0" = "Sign up after 23rd March",
"1" = "Sign up before 23rd March"
)
)
data.joined %>%
freq(prepandemic_march_23)
```
## Missing data
### Convert all -77, -88 and -99 / "Seen but not answered", "Don't know", and "Prefer not to answer" to NA
```{r convert all -77,-88 and -99 to NA}
#convert all numeric variables to NA
dat <- data.joined %>%
dplyr::mutate_all(., ~na_if(., -88)) %>%
dplyr::mutate_all(., ~na_if(., -99)) %>%
dplyr::mutate_all(., ~na_if(., -77))
```
### If data import is older [i.e. does not include enddate and startdate]
Change -88 (Don't know), -99 (Prefer not to answer), and -77 (Seen but not answered) to NA
```{r change missing data to NA}
dat <- data.joined %>%
select(-c("startdate")) %>% #Dropping startdate in new rds files
mutate_all(., ~na_if(., -88)) %>%
mutate_all(., ~na_if(., -99)) %>%
mutate_all(., ~na_if(., -77)) %>%
mutate_all(., ~na_if(., "Seen but not answered")) %>%
mutate_all(., ~na_if(., "Don't know")) %>%
mutate_all(., ~na_if(., "Prefer not to say"))
```
### Getting rid of empty factor levels
```{r Empty factor levels}
dat <- dat %>%
mutate_if(is.factor, ~forcats::fct_drop(., only = "Seen but not answered")) %>%
mutate_if(is.factor, ~forcats::fct_drop(., only = "Don't know")) %>%
mutate_if(is.factor, ~forcats::fct_drop(., only = "Prefer not to answer"))
```
## Identify duplicates
```{r Identify duplicates}
dat$ID.dup <- duplicated(dat$ID)
summary(as.factor(dat$ID.dup))
data.dup <- dat %>%
filter(ID.dup == TRUE)
dat <- dat %>%
filter(ID.dup == FALSE)
```
## Remove age outlier
```{r age outlier check}
# Outlier limits
age_upper_limit = 100
age_lower_limit = 16
#apply age limits
age.unc_upper <- which(dat$age > age_upper_limit)
age.unc_upper
age.unc_lower <- which(dat$age < age_lower_limit)
age.unc_lower
# Number of participants with outlier values
age.unc_outliers <- append(age.unc_upper, age.unc_lower)
length(age.unc_outliers)
# Remove outliers
dat$age <- with(dat, ifelse(age > age_upper_limit | age < age_lower_limit, NA, age))
```
## Remove those without sex, age and incomplete PHQ/GAD items
```{r remove anyone who doesnt report sex or age}
dat <- dat[complete.cases(dat[,"sex"]),]
summary(dat$ID)
dat <- dat[complete.cases(dat[,"age"]),]
summary(dat$ID)
#have removed incomplete PHQ/GAD items for factor analyses and conducting factor scores
dat <- dat[complete.cases(dat[, ALL.items.full_numeric]),]
summary(dat$ID)
```
- All participants reported their biological sex and one person had their age missing, as I had previously removed this (age of 290).
- 1,781 were dropped because they had missing PHQ or GAD items.
## Categorise age into groups
```{r define age groups}
#create categorical age groups per 10 years
dat$age.group_numeric <- case_when(dat$age >= 16 & dat$age <= 25 ~ "1",
dat$age >= 26 & dat$age <= 35 ~ "2",
dat$age >= 36 & dat$age <= 45 ~ "3",
dat$age >= 46 & dat$age <= 55 ~ "4",
dat$age >= 56 & dat$age <= 65 ~ "5",
dat$age >= 66 & dat$age <= 75 ~ "6",
dat$age >= 76 & dat$age <= 85 ~ "7",
dat$age >= 86 & dat$age <= 95 ~ "8")
#create age groups as factors
dat$age.group.factor <- recode_factor(dat$age.group_numeric,
"1" = "16 to 25 years",
"2" = "26 to 35 years",
"3" = "36 to 45 years",
"4" = "46 to 55 years",
"5" = "56 to 65 years",
"6" = "66 to 75 years",
"7" = "76 to 85 years",
"8" = "86 to 95 years")
#have a look at the data
freq(dat$age.group.factor, cumul = F)
```
## Create self-report diagnostic groups
```{r create self-report MDD or any anxiety group}
#Reported MDD or any anxiety diagnosis
dat$MDD_anxiety <- ifelse(dat$mhd.MDD_numeric == "1" |
dat$mhd.GAD_numeric == "1" |
dat$mhd.social_anxiety_numeric == "1" |
dat$mhd.specific_phobia_numeric == "1" |
dat$mhd.agoraphobia_numeric == "1" |
dat$mhd.panic_disorder_numeric == "1", 1, 0)
dat <- dat %>%
mutate(
MDD_anxiety.factor =
recode_factor(MDD_anxiety,
"1" = "MDD and any anxiety",
"0" = "No MDD and any anxiety"
))
table(dat$MDD_anxiety.factor)
```
```{r create self-report MDD only group}
#MDD only group - not reported any anxiety disorder
dat$MDD.only <- ifelse(dat$mhd.MDD_numeric == "1" &
dat$mhd.GAD_numeric == "0" &
dat$mhd.social_anxiety_numeric == "0" &
dat$mhd.specific_phobia_numeric == "0" &
dat$mhd.agoraphobia_numeric == "0" &
dat$mhd.panic_disorder_numeric == "0", 1, 0)
dat <- dat %>%
mutate(
MDD.only.factor =
recode_factor(MDD.only,
"1" = "MDD only",
"0" = "No MDD only"
))
table(dat$MDD.only.factor)
```
```{r create self-report GAD only group}
#GAD only group
dat$GAD.only <- ifelse(dat$mhd.GAD_numeric == "1" &
dat$mhd.MDD_numeric == "0" &
dat$mhd.social_anxiety_numeric == "0" &
dat$mhd.specific_phobia_numeric == "0" &
dat$mhd.agoraphobia_numeric == "0" &
dat$mhd.panic_disorder_numeric == "0", 1, 0)
dat <- dat %>%
mutate(
GAD.only.factor =
recode_factor(GAD.only,
"1" = "GAD only",
"0" = "No GAD only"
))
table(dat$GAD.only.factor)
```
```{r create self-report comorbid MDD and GAD only groups}
#Comorbid MDD and GAD
dat$MDD_GAD <- ifelse(dat$mhd.GAD_numeric == "1" &
dat$mhd.MDD_numeric == "1" &
dat$mhd.social_anxiety_numeric == "0" &
dat$mhd.specific_phobia_numeric == "0" &
dat$mhd.agoraphobia_numeric == "0" &
dat$mhd.panic_disorder_numeric == "0", 1, 0)
dat <- dat %>%
mutate(
MDD_GAD.factor =
recode_factor(MDD_GAD,
"1" = "Comorbid MDD and GAD only",
"0" = "No comorbid MDD and GAD only"
))
table(dat$MDD_GAD.factor)
```
```{r create self-report any other anxiety disorder group}
#All who have any other anxiety disorder
dat$anxiety.other.diagnosis <- ifelse(dat$mhd.social_anxiety_numeric == "1" |
dat$mhd.specific_phobia_numeric == "1" |
dat$mhd.agoraphobia_numeric == "1" |
dat$mhd.panic_disorder_numeric == "1", 1, 0)
dat <- dat %>%
mutate(
anxiety.other.diagnosis.factor =
recode_factor(anxiety.other.diagnosis,
"1" = "Other anxiety disorder",
"0" = "No other anxiety disorder"
))
table(dat$anxiety.other.diagnosis.factor)
```
```{r create self-report any other anxiety disorder only group}
#all who have any other anxiety disorder only
dat$anxiety.other.diagnosis.only <- ifelse((dat$mhd.social_anxiety_numeric == "1" |
dat$mhd.specific_phobia_numeric == "1" |
dat$mhd.agoraphobia_numeric == "1" |
dat$mhd.panic_disorder_numeric == "1" &
(dat$mhd.GAD_numeric == "0") &
dat$mhd.MDD_numeric == "0"), 1, 0)
dat <- dat %>%
mutate(
anxiety.other.diagnosis.only.factor =
recode_factor(anxiety.other.diagnosis.only,
"1" = "Other anxiety disorder without MDD and GAD",
"0" = "No other anxiety disorder without MDD and GAD"
))
table(dat$anxiety.other.diagnosis.only.factor)
```
## Create data sets with just men/women
```{r datasets for males and males}
data.female <- dat %>% filter(sex == "Female")
data.male <- dat %>% filter (sex == "Male")
```
## Create Highest Education variable
Assumes Degree > A level > NVQ > CSE/GCSE
```{r define highest education}
#create numeric version of the highest education variable
dat <- dat %>%
mutate(
highest_education_numeric =
case_when(
dem.university == "Yes" ~ 4,
dem.alevels == "Yes" ~ 3,
dem.NVQ == "Yes" ~ 2,
dem.gcse == "Yes" ~ 1,
dem.cse == "Yes" ~ 1))
#recode the numeric version into a factor
dat <- dat %>%
mutate(
highest_education =
recode_factor(highest_education_numeric,
`1` = "GCSE/CSE",
`2` = "NVQ",
`3` = "A-levels",
`4` = "University"))
freq(dat$highest_education)
```
## Categroise PHQ-9 and GAD-7 items
### PHQ
```{r making PHQ items categorical}
#categorise the PHQ items for the logistic regressions
dat$phq.depressed_mood.cat <- ifelse(dat$phq.depressed_mood_numeric > 0, 1, 0)
dat$phq.anhedonia.cat <- ifelse(dat$phq.anhedonia_numeric > 0, 1, 0)
dat$phq.sleep_change.cat <- ifelse(dat$phq.sleep_change_numeric > 0, 1, 0)
dat$phq.little_energy.cat <- ifelse(dat$phq.little_energy_numeric > 0, 1, 0)
dat$phq.eating_problems.cat <- ifelse(dat$phq.eating_problems_numeric > 0, 1, 0)
dat$phq.worthlessness.cat <- ifelse(dat$phq.worthlessness_numeric > 0, 1, 0)
dat$phq.concentration_problems.cat <- ifelse(dat$phq.concentration_problems_numeric > 0, 1, 0)
dat$phq.motor_problems.cat <- ifelse(dat$phq.motor_problems_numeric > 0, 1, 0)
dat$phq.suicide_ideation.cat <- ifelse(dat$phq.suicide_ideation_numeric > 0, 1, 0)
table(dat$phq.depressed_mood.cat)
```
### GAD
```{r making GAD items categorical}
#categorise the GAD items for the logistic regressions
dat$gad.feeling_anxious.cat <- ifelse(dat$gad.feeling_anxious_numeric > 0, 1, 0)
dat$gad.control_worrying.cat <- ifelse(dat$gad.control_worrying_numeric > 0, 1, 0)
dat$gad.worry_toomuch.cat <- ifelse(dat$gad.worry_toomuch_numeric > 0, 1, 0)
dat$gad.trouble_relaxing.cat <- ifelse(dat$gad.trouble_relaxing_numeric > 0, 1, 0)
dat$gad.restless.cat <- ifelse(dat$gad.restless_numeric > 0, 1, 0)
dat$gad.irritable.cat <- ifelse(dat$gad.irritable_numeric > 0, 1, 0)
dat$gad.feeling_afraid.cat <- ifelse(dat$gad.feeling_afraid_numeric > 0, 1, 0)
table(dat$gad.feeling_anxious.cat)
```
## Total scores
### PHQ
```{r calculate PHQ total score }
#calulate total score
PHQ.scored.items <- scoreItems(keys = PHQ.items.key,
items = dat[PHQ.items],
totals = TRUE,
missing = TRUE,
impute = 'none', #this should not matter as the data is full
min = 0,
max = 3)
#Add in column to data frame
dat$PHQ.total.score <- PHQ.scored.items$scores
table(dat$PHQ.total.score)
```
### GAD
```{r calculate GAD total score }
#calulate total score
GAD.scored.items <- scoreItems(keys = GAD.items.key,
items = dat[GAD.items],
totals = TRUE,
missing = TRUE,
impute = 'none',
min = 0,
max = 3)
#Add in column to data frame
dat$GAD.total.score <- GAD.scored.items$scores
table(dat$GAD.total.score)
```
## Create ordered factors for PHQ anf GAD items to aid labelling for endorsement plot
```{r create ordered factors for endorsement plot}
dat$phq.anhedonia.cat.labelled <- recode_factor(dat$phq.anhedonia.cat,
"0" = "Did not report symptom",
"1" = "Reported symptom")
dat$phq.depressed_mood.cat.labelled <- recode_factor(dat$phq.depressed_mood.cat,
"0" = "Did not report symptom",
"1" = "Reported symptom")
dat$phq.suicide_ideation.cat.labelled <- recode_factor(dat$phq.suicide_ideation.cat,
"0" = "Did not report symptom",
"1" = "Reported symptom")
dat$phq.concentration_problems.cat.labelled <- recode_factor(dat$phq.concentration_problems.cat,
"0" = "Did not report symptom",
"1" = "Reported symptom")
dat$phq.worthlessness.cat.labelled <- recode_factor(dat$phq.worthlessness.cat,
"0" = "Did not report symptom",
"1" = "Reported symptom")
dat$phq.little_energy.cat.labelled <- recode_factor(dat$phq.little_energy.cat,
"0" = "Did not report symptom",
"1" = "Reported symptom")
dat$phq.eating_problems.cat.labelled <- recode_factor(dat$phq.eating_problems.cat,
"0" = "Did not report symptom",
"1" = "Reported symptom")
dat$phq.sleep_change.cat.labelled <- recode_factor(dat$phq.sleep_change.cat,
"0" = "Did not report symptom",
"1" = "Reported symptom")
dat$phq.motor_problems.cat.labelled <- recode_factor(dat$phq.motor_problems.cat,
"0" = "Did not report symptom",
"1" = "Reported symptom")
dat$gad.worry_toomuch.cat.labelled <- recode_factor(dat$gad.worry_toomuch.cat,
"0" = "Did not report symptom",
"1" = "Reported symptom")
dat$gad.control_worrying.cat.labelled <- recode_factor(dat$gad.control_worrying.cat,
"0" = "Did not report symptom",
"1" = "Reported symptom")
dat$gad.feeling_anxious.cat.labelled <- recode_factor(dat$gad.feeling_anxious.cat,
"0" = "Did not report symptom",
"1" = "Reported symptom")
dat$gad.feeling_afraid.cat.labelled <- recode_factor(dat$gad.feeling_afraid.cat,
"0" = "Did not report symptom",
"1" = "Reported symptom")
dat$gad.trouble_relaxing.cat.labelled <- recode_factor(dat$gad.trouble_relaxing.cat,
"0" = "Did not report symptom",
"1" = "Reported symptom")
dat$gad.restless.cat.labelled <- recode_factor(dat$gad.restless.cat,
"0" = "Did not report symptom",
"1" = "Reported symptom")
dat$gad.irritable.cat.labelled <- recode_factor(dat$gad.irritable.cat,
"0" = "Did not report symptom",
"1" = "Reported symptom")
```
# **Sample descriptives**
## Demographics
```{r call packages for descriptives, include=FALSE}
library(janitor)
library(tidyr)
library(tidyverse)
```
```{r descriptives for age}
continuous_age_descriptives_raw <- dat %>%
group_by(sex) %>%
summarise(mean = mean(age), sd = sd(age), min = min(age), max = max(age)) %>%
pivot_longer(cols = c("mean", "sd", "min", "max")) %>%
rename(descriptive = name) %>%
pivot_wider(names_from = sex, values_from = value) %>%
mutate(Total =
c(mean(dat$age), sd(dat$age), min(dat$age), max(dat$age)),
sd_male = c(sd(data.male$age), NA_real_, NA_real_, NA_real_),
sd_female = c(sd(data.female$age), NA_real_, NA_real_, NA_real_),
sd_total = c(sd(dat$age), NA_real_, NA_real_, NA_real_)) %>%
select(
"Descriptive" = descriptive,
"Male" = Male,
"% Male" = sd_male,
"Female" = Female,
"% Female" = sd_female,
"Total" = Total,
"% Total" = sd_total)
continuous_age_descriptives <- continuous_age_descriptives_raw[-c(2), ]
```
```{r descriptives for age group}
age_group_descriptives <- dat %>% #create object to bind later on
count(sex, age.group.factor) %>%
mutate(Prop = round(n/sum(n)*100, 2)) %>%
pivot_wider(names_from = sex, values_from = c(n, Prop)) %>%
mutate(Total = n_Male + n_Female,
Prop_total = Prop_Male + Prop_Female) %>%
select(
"Descriptive" = age.group.factor,
"Male" = n_Male,
"% Male" = Prop_Male,
"Female" = n_Female,
"% Female" = Prop_Female,
"Total" = Total,
"% Total" = Prop_total)
age_group_descriptives
```
```{r descriptives for highest education}
highest_education_descriptives.raw <- dat %>% #create object to bind later on
count(sex, highest_education) %>%
mutate(Prop = round(n/sum(n)*100, 2)) %>%
pivot_wider(names_from = sex, values_from = c(n, Prop)) %>%
mutate(Total = n_Male + n_Female,
Prop_total = Prop_Male + Prop_Female) %>%
select(
"Descriptive" = highest_education,
"Male" = n_Male,
"% Male" = Prop_Male,
"Female" = n_Female,
"% Female" = Prop_Female,
"Total" = Total,
"% Total" = Prop_total)
highest_education_descriptives <- highest_education_descriptives.raw[-c(5),]
```
```{r descriptives for self-report diagnosis}
#MDD total
diagnosis_descriptives_mdd.raw <- dat %>% #create object to bind later on
count(sex, mhd.MDD) %>%
mutate(Prop = round(n/sum(n)*100, 2)) %>%
pivot_wider(names_from = sex, values_from = c(n, Prop)) %>%
mutate(Total = n_Male + n_Female,
Prop_total = Prop_Male + Prop_Female) %>%
select(
"Descriptive" = mhd.MDD,
"Male" = n_Male,
"% Male" = Prop_Male,
"Female" = n_Female,
"% Female" = Prop_Female,
"Total" = Total,
"% Total" = Prop_total)
diagnosis_descriptives_mdd <- diagnosis_descriptives_mdd.raw[-c(1,3), ]
#mdd only
diagnosis_descriptives_mdd_only.raw <- dat %>% #create object to bind later on
count(sex, MDD.only.factor) %>%
mutate(Prop = round(n/sum(n)*100, 2)) %>%
pivot_wider(names_from = sex, values_from = c(n, Prop)) %>%
mutate(Total = n_Male + n_Female,
Prop_total = Prop_Male + Prop_Female) %>%
select(
"Descriptive" = MDD.only.factor,
"Male" = n_Male,
"% Male" = Prop_Male,
"Female" = n_Female,
"% Female" = Prop_Female,
"Total" = Total,
"% Total" = Prop_total)
diagnosis_descriptives_mdd_only <- diagnosis_descriptives_mdd_only.raw[-c(2,3), ]
#GAD
diagnosis_descriptives_gad.raw <- dat %>% #create object to bind later on
count(sex, mhd.GAD) %>%
mutate(Prop = round(n/sum(n)*100, 2)) %>%
pivot_wider(names_from = sex, values_from = c(n, Prop)) %>%
mutate(Total = n_Male + n_Female,
Prop_total = Prop_Male + Prop_Female) %>%
select(
"Descriptive" = mhd.GAD,
"Male" = n_Male,
"% Male" = Prop_Male,
"Female" = n_Female,
"% Female" = Prop_Female,
"Total" = Total,
"% Total" = Prop_total)
diagnosis_descriptives_gad <- diagnosis_descriptives_gad.raw[-c(1,3), ]
#GAD only
diagnosis_descriptives_gad_only.raw <- dat %>% #create object to bind later on
count(sex, GAD.only.factor) %>%
mutate(Prop = round(n/sum(n)*100, 2)) %>%
pivot_wider(names_from = sex, values_from = c(n, Prop)) %>%
mutate(Total = n_Male + n_Female,
Prop_total = Prop_Male + Prop_Female) %>%
select(
"Descriptive" = GAD.only.factor,
"Male" = n_Male,
"% Male" = Prop_Male,
"Female" = n_Female,
"% Female" = Prop_Female,
"Total" = Total,
"% Total" = Prop_total)
diagnosis_descriptives_gad_only <- diagnosis_descriptives_gad_only.raw[-c(2,3), ]
#Other anxiety diagnoses
diagnosis_descriptives_other_anxiety.raw <- dat %>% #create object to bind later on
count(sex, anxiety.other.diagnosis.factor) %>%
mutate(Prop = round(n/sum(n)*100, 2)) %>%
pivot_wider(names_from = sex, values_from = c(n, Prop)) %>%
mutate(Total = n_Male + n_Female,
Prop_total = Prop_Male + Prop_Female) %>%
select(
"Descriptive" = anxiety.other.diagnosis.factor,
"Male" = n_Male,
"% Male" = Prop_Male,
"Female" = n_Female,
"% Female" = Prop_Female,
"Total" = Total,
"% Total" = Prop_total)
diagnosis_descriptives_other_anxiety <- diagnosis_descriptives_other_anxiety.raw[-c(2,3), ]
#Other anxiety disorder without MDD and GAD
diagnosis_descriptives_other_anxiety.only.raw <- dat %>% #create object to bind later on
count(sex, anxiety.other.diagnosis.only.factor) %>%
mutate(Prop = round(n/sum(n)*100, 2)) %>%
pivot_wider(names_from = sex, values_from = c(n, Prop)) %>%
mutate(Total = n_Male + n_Female,
Prop_total = Prop_Male + Prop_Female) %>%
select(
"Descriptive" = anxiety.other.diagnosis.only.factor,
"Male" = n_Male,
"% Male" = Prop_Male,
"Female" = n_Female,
"% Female" = Prop_Female,
"Total" = Total,
"% Total" = Prop_total)
diagnosis_descriptives_other_anxiety.only <- diagnosis_descriptives_other_anxiety.only.raw[-c(2,3), ]
#bind all rows together
diagnosis_descriptives <- rbind(diagnosis_descriptives_mdd,
diagnosis_descriptives_mdd_only,
diagnosis_descriptives_gad,
diagnosis_descriptives_gad_only,
diagnosis_descriptives_other_anxiety,
diagnosis_descriptives_other_anxiety.only)
```
```{r descriptives for ethnicity }