-
Notifications
You must be signed in to change notification settings - Fork 0
/
R Script to Check for Matches between Items from Different Scales.R
3683 lines (2971 loc) · 109 KB
/
R Script to Check for Matches between Items from Different Scales.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
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
#-------------------------Description of This Script----------------------------
#This script identifies the most commonly used wording of each item in each
#scale identified in data we are planning to harmonise. This script then saves
#the most commonly used wording of each item of each scale in a list (one list
#per scale). These lists are then used to run functions from the harmonydata
#package to check for matches between items from different scales (i.e., items
#with a high level of semantic similarity/correspondence). Indices of similarity
#between item pairs and identified matches between items are saved in lists,
#matrices or data frames, and are then exported as csv files.
#----------------------Preparation and Loading Packages-------------------------
#Un-comment and run the below lines of code if these packages are not already
#installed in R:
#install.packages("devtools")
#devtools::install_github("harmonydata/harmony_r")
#install.packages("dplyr")
#install.packages("readxl")
#Note: Additional packages would be required for data not in xlsx format
#Load the required R libraries/packages:
library(devtools)
library(harmonydata)
library(dplyr)
library(readxl)
harmonydata::set_url()
#----------------------Set Working Drive, Load Data-----------------------------
#Set the working drive/file location R will use to find data files. E.g.:
setwd("~/Data Harmonisation Project/Content Analysis")
#Load the data and save to a dataframe object in the R environment:
dat1 <- read_xlsx("Survey Items.xlsx") #The xlsx file is a list of survey items.
#Add an ID column to the dataframe:
dat1$id<-as.character(seq(1,nrow(dat1)))
#-----------K10: Identify Most Commonly Used Wording, Save in List--------------
#The below code identifies the most commonly used wording of each item of the K10
#in the list of survey items in the dat1 dataframe. This code is useful for
#identifying the most commonly used wording of an item in instances where
#multiple surveys/datasets to be harmonised contained the same scale, but the
#wording of each item in each scale may have varied slightly across surveys).
#Note: Because items from the K6 and K5 are identical or nearly identical to
#the corresponding items in the K10, the K6 and K5 versions of each K10 item
#will be included when identifying the most common wording of each item:
freqK101i <- dat1 %>% #Start with dataframe 'dat1'
filter(Scale == "K10" & `Item Number` == 1) %>% #Filter rows where Scale is "K10" and Item Number is 1
group_by(Items) %>% #Group by the 'Items' column
summarise(total = n()) #Count the number of rows in each group and store the results in a column called 'total' in an object called freqK101i
#Repeat the above for each item in the scale:
freqK102i<- dat1 %>%
filter((Scale=="K10" & `Item Number`==2) | (Scale=="K6" & `Item Number`==1) | (Scale=="K5" & `Item Number`==1)) %>%
group_by(Items) %>%
summarise(total=n())
freqK103i<- dat1 %>%
filter((Scale=="K10" & `Item Number`==3)) %>%
group_by(Items) %>%
summarise(total=n())
freqK104i<- dat1 %>%
filter((Scale=="K10" & `Item Number`==4) | (Scale=="K6" & `Item Number`==2) | (Scale=="K5" & `Item Number`==2)) %>%
group_by(Items) %>%
summarise(total=n())
freqK105i<- dat1 %>%
filter((Scale=="K10" & `Item Number`==5) | (Scale=="K6" & `Item Number`==3) | (Scale=="K5" & `Item Number`==3)) %>%
group_by(Items) %>%
summarise(total=n())
freqK106i<- dat1 %>%
filter((Scale=="K10" & `Item Number`==6)) %>%
group_by(Items) %>%
summarise(total=n())
freqK107i<- dat1 %>%
filter((Scale=="K10" & `Item Number`==7)) %>%
group_by(Items) %>%
summarise(total=n())
freqK108i<- dat1 %>%
filter((Scale=="K10" & `Item Number`==8) | (Scale=="K6" & `Item Number`==4) | (Scale=="K5" & `Item Number`==4)) %>%
group_by(Items) %>%
summarise(total=n())
freqK109i<- dat1 %>%
filter((Scale=="K10" & `Item Number`==9) | (Scale=="K6" & `Item Number`==5) | (Scale=="K5" & `Item Number`==5)) %>%
group_by(Items) %>%
summarise(total=n())
freqK1010i<- dat1 %>%
filter((Scale=="K10" & `Item Number`==10) | (Scale=="K6" & `Item Number`==6)) %>%
group_by(Items) %>%
summarise(total=n())
#Create a list of the most commonly used wordings of the K10 items:
K10 <- list(
instrument_name = "K10",
questions = list(
list(question_no = "K10_1", question_text="In the past four weeks, about how often did you feel tired out for no good reason?"),
list(question_no = "K10_2", question_text="In the past four weeks, about how often did you feel nervous?"),
list(question_no = "K10_3", question_text="In the past four weeks, about how often did you feel so nervous that nothing could calm you down?"),
list(question_no = "K10_4", question_text="In the past four weeks, about how often did you feel hopeless?"),
list(question_no = "K10_5", question_text="In the past four weeks, about how often did you feel restless or fidgety?"),
list(question_no = "K10_6", question_text="In the past four weeks, about how often did you feel so restless you could not sit still?"),
list(question_no = "K10_7", question_text="In the past four weeks, about how often did you feel depressed?"),
list(question_no = "K10_8", question_text="In the past four weeks, about how often did you feel that everything was an effort?"),
list(question_no = "K10_9", question_text="In the past four weeks, about how often did you feel so sad that nothing could cheer you up?"),
list(question_no = "K10_10", question_text="In the past four weeks, about how often did you feel worthless?")
)
)
#Alternatively, the below code will create a function to automatically identify
#the most commonly used wordings of K10 items, including matching items from K6
#and K5, and then store them in a list:
#First create the function:
get_most_common_item_text <- function(item_number) {
dat1 %>%
filter(
(Scale == "K10" & `Item Number` == item_number) |
(Scale == "K6" & `Item Number` == ifelse(item_number == 2, 1, # K10_2 -> K6_1
ifelse(item_number == 4, 2, # K10_4 -> K6_2
ifelse(item_number == 5, 3, # K10_5 -> K6_3
ifelse(item_number == 8, 4, # K10_8 -> K6_4
ifelse(item_number == 9, 5, # K10_9 -> K6_5
ifelse(item_number == 10, 6, #K10_10 -> K6_6
NA))))))) |
(Scale == "K5" & `Item Number` == ifelse(item_number == 2, 1, # K10_2 -> K5_1
ifelse(item_number == 4, 2, # K10_4 -> K5_2
ifelse(item_number == 5, 3, # K10_5 -> K5_3
ifelse(item_number == 8, 4, # K10_8 -> K5_4
ifelse(item_number == 9, 5, # K10_9 -> K5_5
NA))))))) %>%
group_by(Items) %>%
summarise(total = n(), .groups = 'drop') %>%
arrange(desc(total)) %>%
slice(1) %>%
pull(Items)
}
#Second create and populate a list which will store the most common wording of
#each item:
K10 <- list(
instrument_name = "K10",
questions = lapply(1:10, function(i) {
list(
question_no = paste0("K10_", i),
question_text = get_most_common_item_text(i)
)
})
)
#----------MHI-5: Identify Most Commonly Used Wording, Save in List-------------
#The below will identify the wording most commonly used for the 5 items of the
#SF-36 that make up the MHI-5.
#Note: The MHI-5 is comprised of items 24, 25, 26, 28 and 30 of the SF-36.
freqmhi501i<- dat1 %>%
filter(Scale=="SF-36" & `Item Number`==24) %>%
group_by(Items) %>%
summarise(total=n())
freqmhi502i<- dat1 %>%
filter(Scale=="SF-36" & `Item Number`==25) %>%
group_by(Items) %>%
summarise(total=n())
freqmhi503i<- dat1 %>%
filter(Scale=="SF-36" & `Item Number`==26) %>%
group_by(Items) %>%
summarise(total=n())
freqmhi504i<- dat1 %>%
filter(Scale=="SF-36" & `Item Number`==28) %>%
group_by(Items) %>%
summarise(total=n())
freqmhi505i<- dat1 %>%
filter(Scale=="SF-36" & `Item Number`==30) %>%
group_by(Items) %>%
summarise(total=n())
#Manually storing the most commonly used wordings of the MHI-5 items in a list:
mhi5 <- list(
instrument_name = "MHI-5",
questions = list(
list(question_no = "MHI5_1", question_text="These questions are about how you feel and how things have been with you during the past 4 weeks. For each question, please give the one answer that comes closest to the way you have been feeling. How much of the time during the past 4 weeks: Have you been a nervous person?"),
list(question_no = "MHI5_2", question_text="These questions are about how you feel and how things have been with you during the past 4 weeks. For each question, please give the one answer that comes closest to the way you have been feeling. How much of the time during the past 4 weeks: Have you felt so down in the dumps that nothing could cheer you up?"),
list(question_no = "MHI5_3", question_text="These questions are about how you feel and how things have been with you during the past 4 weeks. For each question, please give the one answer that comes closest to the way you have been feeling. How much of the time during the past 4 weeks: Have you felt calm and peaceful?"),
list(question_no = "MHI5_4", question_text="These questions are about how you feel and how things have been with you during the past 4 weeks. For each question, please give the one answer that comes closest to the way you have been feeling. How much of the time during the past 4 weeks: Have you felt down?"),
list(question_no = "MHI5_5", question_text="These questions are about how you feel and how things have been with you during the past 4 weeks. For each question, please give the one answer that comes closest to the way you have been feeling. How much of the time during the past 4 weeks: Have you been a happy person?")
)
)
#The below code will create a function to automatically identify the most
#commonly used wordings of MHI-5 items and then store them in a list:
#First create the function:
get_most_common_item_text <- function(item_number) {
dat1 %>%
filter(Scale == "SF-36" & `Item Number` == item_number) %>%
group_by(Items) %>%
summarise(total = n(), .groups = 'drop') %>%
arrange(desc(total)) %>%
slice(1) %>%
pull(Items)
}
#Second create and populate the list which will store the most common items:
MHI5 <- list(
instrument_name = "MHI-5",
questions = lapply(c(24,25,26,28,30), function(i) {
list(
question_no = paste0("MHI-5_", i),
question_text = get_most_common_item_text(i)
)
})
)
#--------SF-36 MCS: Identify Most Commonly Used Wording, Save in List-----------
#The below will identify the wording most commonly used for the SF-36 items
#that are focused on mental health but excluding items focused on physical
#health.
#Note: Items include 17, 18, 19, 20, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32.
freqsf3617i<- dat1 %>%
filter(Scale=="SF-36" & `Item Number`==17) %>%
group_by(Items) %>%
summarise(total=n())
freqsf3618i <- dat1 %>%
filter(Scale == "SF-36" & `Item Number` == 18) %>%
group_by(Items) %>%
summarise(total = n())
freqsf3619i <- dat1 %>%
filter(Scale == "SF-36" & `Item Number` == 19) %>%
group_by(Items) %>%
summarise(total = n())
freqsf3620i <- dat1 %>%
filter(Scale == "SF-36" & `Item Number` == 20) %>%
group_by(Items) %>%
summarise(total = n())
freqsf3623i <- dat1 %>%
filter(Scale == "SF-36" & `Item Number` == 23) %>%
group_by(Items) %>%
summarise(total = n())
freqsf3624i <- dat1 %>%
filter(Scale == "SF-36" & `Item Number` == 24) %>%
group_by(Items) %>%
summarise(total = n())
freqsf3625i <- dat1 %>%
filter(Scale == "SF-36" & `Item Number` == 25) %>%
group_by(Items) %>%
summarise(total = n())
freqsf3626i <- dat1 %>%
filter(Scale == "SF-36" & `Item Number` == 26) %>%
group_by(Items) %>%
summarise(total = n())
freqsf3627i <- dat1 %>%
filter(Scale == "SF-36" & `Item Number` == 27) %>%
group_by(Items) %>%
summarise(total = n())
freqsf3628i <- dat1 %>%
filter(Scale == "SF-36" & `Item Number` == 28) %>%
group_by(Items) %>%
summarise(total = n())
freqsf3629i <- dat1 %>%
filter(Scale == "SF-36" & `Item Number` == 29) %>%
group_by(Items) %>%
summarise(total = n())
freqsf3630i <- dat1 %>%
filter(Scale == "SF-36" & `Item Number` == 30) %>%
group_by(Items) %>%
summarise(total = n())
freqsf3631i <- dat1 %>%
filter(Scale == "SF-36" & `Item Number` == 31) %>%
group_by(Items) %>%
summarise(total = n())
freqsf3632i <- dat1 %>%
filter(Scale == "SF-36" & `Item Number` == 32) %>%
group_by(Items) %>%
summarise(total = n())
#The below code will create a function to automatically identify the most
#commonly used wordings of SF-36 mental health items and store them in a list:
#First create the function:
get_most_common_item_text <- function(item_number) {
dat1 %>%
filter(Scale == "SF-36" & `Item Number` == item_number) %>%
group_by(Items) %>%
summarise(total = n(), .groups = 'drop') %>%
arrange(desc(total)) %>%
slice(1) %>%
pull(Items)
}
#Second create and populate the list which will store the most common items:
SF36 <- list(
instrument_name = "SF-36",
questions = lapply(c(17,18,19,20,23,24,25,26,27,28,29,30,31,32), function(i) {
list(
question_no = paste0("SF36_", i),
question_text = get_most_common_item_text(i)
)
})
)
#----------SF-12: Identify Most Commonly Used Wording, Save in List-------------
#The below will identify the most commonly used wording of each SF-12 item and
#store them in individual objects for inspection to make sure the survey items
#are all coded correctly:
freqsf121i <- dat1 %>%
filter(Scale == "SF-12" & `Item Number` == 1) %>%
group_by(Items) %>%
summarise(total = n())
freqsf122i <- dat1 %>%
filter(Scale == "SF-12" & `Item Number` == 2) %>%
group_by(Items) %>%
summarise(total = n())
freqsf123i <- dat1 %>%
filter(Scale == "SF-12" & `Item Number` == 3) %>%
group_by(Items) %>%
summarise(total = n())
freqsf124i <- dat1 %>%
filter(Scale == "SF-12" & `Item Number` == 4) %>%
group_by(Items) %>%
summarise(total = n())
freqsf125i <- dat1 %>%
filter(Scale == "SF-12" & `Item Number` == 5) %>%
group_by(Items) %>%
summarise(total = n())
freqsf126i <- dat1 %>%
filter(Scale == "SF-12" & `Item Number` == 6) %>%
group_by(Items) %>%
summarise(total = n())
freqsf127i <- dat1 %>%
filter(Scale == "SF-12" & `Item Number` == 7) %>%
group_by(Items) %>%
summarise(total = n())
freqsf128i <- dat1 %>%
filter(Scale == "SF-12" & `Item Number` == 8) %>%
group_by(Items) %>%
summarise(total = n())
freqsf129i <- dat1 %>%
filter(Scale == "SF-12" & `Item Number` == 9) %>%
group_by(Items) %>%
summarise(total = n())
freqsf1210i <- dat1 %>%
filter(Scale == "SF-12" & `Item Number` == 10) %>%
group_by(Items) %>%
summarise(total = n())
freqsf1211i <- dat1 %>%
filter(Scale == "SF-12" & `Item Number` == 11) %>%
group_by(Items) %>%
summarise(total = n())
freqsf1212i <- dat1 %>%
filter(Scale == "SF-12" & `Item Number` == 12) %>%
group_by(Items) %>%
summarise(total = n())
#The below code will create a function to automatically identify the most
#commonly used wordings of SF-12 items and then store them in a list.
#Note, this code will only do this for the mental health focused items
#from the SF-12.
#First create the function:
get_most_common_item_text <- function(item_number) {
dat1 %>%
filter(Scale == "SF-12" & `Item Number` == item_number) %>%
group_by(Items) %>%
summarise(total = n(), .groups = 'drop') %>%
arrange(desc(total)) %>%
slice(1) %>%
pull(Items)
}
#Second create and populate the list which will store the most common items:
SF12 <- list(
instrument_name = "SF-12",
questions = lapply(c(6,7,9,10,11,12), function(i) {
list(
question_no = paste0("SF-12_", i),
question_text = get_most_common_item_text(i)
)
})
)
#-----------SF-8: Identify Most Commonly Used Wording, Save in List-------------
#The below will identify the most commonly used wording of each SF-8 item and
#store them in individual objects for inspection to make sure the survey items
#are all coded correctly:
freqsf81i <- dat1 %>%
filter(Scale == "SF-8" & `Item Number` == 1) %>%
group_by(Items) %>%
summarise(total = n())
freqsf82i <- dat1 %>%
filter(Scale == "SF-8" & `Item Number` == 2) %>%
group_by(Items) %>%
summarise(total = n())
freqsf83i <- dat1 %>%
filter(Scale == "SF-8" & `Item Number` == 3) %>%
group_by(Items) %>%
summarise(total = n())
freqsf84i <- dat1 %>%
filter(Scale == "SF-8" & `Item Number` == 4) %>%
group_by(Items) %>%
summarise(total = n())
freqsf85i <- dat1 %>%
filter(Scale == "SF-8" & `Item Number` == 5) %>%
group_by(Items) %>%
summarise(total = n())
freqsf86i <- dat1 %>%
filter(Scale == "SF-8" & `Item Number` == 6) %>%
group_by(Items) %>%
summarise(total = n())
freqsf87i <- dat1 %>%
filter(Scale == "SF-8" & `Item Number` == 7) %>%
group_by(Items) %>%
summarise(total = n())
freqsf88i <- dat1 %>%
filter(Scale == "SF-8" & `Item Number` == 8) %>%
group_by(Items) %>%
summarise(total = n())
#The below code will create a function to automatically identify the most
#commonly used wordings of SF-8 items and then store them in a list.
#Note, this code will only do this for the mental health focused items
#from the SF-8.
#First create the function:
get_most_common_item_text <- function(item_number) {
dat1 %>%
filter(Scale == "SF-8" & `Item Number` == item_number) %>%
group_by(Items) %>%
summarise(total = n(), .groups = 'drop') %>%
arrange(desc(total)) %>%
slice(1) %>%
pull(Items)
}
#Second create and populate the list which will store the most common items:
SF8 <- list(
instrument_name = "SF-8",
questions = lapply(5:8, function(i) {
list(
question_no = paste0("SF-8_", i),
question_text = get_most_common_item_text(i)
)
})
)
#----------GHQ-12: Identify Most Commonly Used Wording, Save in List------------
#The below will identify the most commonly used wording of each GHQ-12 item and
#store them in individual objects for inspection to make sure the survey items
#are all coded correctly:
freqghq121i<- dat1 %>%
filter(Scale=="GHQ-12" & `Item Number`==1) %>%
group_by(Items) %>%
summarise(total=n())
freqghq122i<- dat1 %>%
filter(Scale=="GHQ-12" & `Item Number`==2) %>%
group_by(Items) %>%
summarise(total=n())
freqghq123i<- dat1 %>%
filter(Scale=="GHQ-12" & `Item Number`==3) %>%
group_by(Items) %>%
summarise(total=n())
freqghq124i<- dat1 %>%
filter(Scale=="GHQ-12" & `Item Number`==4) %>%
group_by(Items) %>%
summarise(total=n())
freqghq125i<- dat1 %>%
filter(Scale=="GHQ-12" & `Item Number`==5) %>%
group_by(Items) %>%
summarise(total=n())
freqghq126i<- dat1 %>%
filter(Scale=="GHQ-12" & `Item Number`==6) %>%
group_by(Items) %>%
summarise(total=n())
freqghq127i<- dat1 %>%
filter(Scale=="GHQ-12" & `Item Number`==7) %>%
group_by(Items) %>%
summarise(total=n())
freqghq128i<- dat1 %>%
filter(Scale=="GHQ-12" & `Item Number`==8) %>%
group_by(Items) %>%
summarise(total=n())
freqghq129i<- dat1 %>%
filter(Scale=="GHQ-12" & `Item Number`==9) %>%
group_by(Items) %>%
summarise(total=n())
freqghq1210i<- dat1 %>%
filter(Scale=="GHQ-12" & `Item Number`==10) %>%
group_by(Items) %>%
summarise(total=n())
freqghq1211i<- dat1 %>%
filter(Scale=="GHQ-12" & `Item Number`==11) %>%
group_by(Items) %>%
summarise(total=n())
freqghq1212i<- dat1 %>%
filter(Scale=="GHQ-12" & `Item Number`==12) %>%
group_by(Items) %>%
summarise(total=n())
#The below code will create a function to automatically identify the most
#commonly used wordings of GHQ-12 items and then store them in a list:
#First create the function:
get_most_common_item_text <- function(item_number) {
dat1 %>%
filter(Scale == "GHQ-12" & `Item Number` == item_number) %>%
group_by(Items) %>%
summarise(total = n(), .groups = 'drop') %>%
arrange(desc(total)) %>%
slice(1) %>%
pull(Items)
}
#Second create and populate the list which will store the most common items:
GHQ12 <- list(
instrument_name = "GHQ-12",
questions = lapply(1:12, function(i) {
list(
question_no = paste0("GHQ12_", i),
question_text = get_most_common_item_text(i)
)
})
)
#-----------GAD7: Identify Most Commonly Used Wording, Save in List-------------
#The below will identify the most commonly used wording of each GAD7 item:
freqgad71i<- dat1 %>%
filter(Scale=="GAD-7" & `Item Number`==1) %>%
group_by(Items) %>%
summarise(total=n())
freqgad72i<- dat1 %>%
filter(Scale=="GAD-7" & `Item Number`==2) %>%
group_by(Items) %>%
summarise(total=n())
freqgad73i<- dat1 %>%
filter(Scale=="GAD-7" & `Item Number`==3) %>%
group_by(Items) %>%
summarise(total=n())
freqgad74i<- dat1 %>%
filter(Scale=="GAD-7" & `Item Number`==4) %>%
group_by(Items) %>%
summarise(total=n())
freqgad75i<- dat1 %>%
filter(Scale=="GAD-7" & `Item Number`==5) %>%
group_by(Items) %>%
summarise(total=n())
freqgad76i<- dat1 %>%
filter(Scale=="GAD-7" & `Item Number`==6) %>%
group_by(Items) %>%
summarise(total=n())
freqgad77i<- dat1 %>%
filter(Scale=="GAD-7" & `Item Number`==7) %>%
group_by(Items) %>%
summarise(total=n())
#The below code will create a function to automatically identify the most
#commonly used wordings of GAD-7 items and then store them in a list:
#First create the function:
get_most_common_item_text <- function(item_number) {
dat1 %>%
filter(Scale == "GAD-7" & `Item Number` == item_number) %>%
group_by(Items) %>%
summarise(total = n(), .groups = 'drop') %>%
arrange(desc(total)) %>%
slice(1) %>%
pull(Items)
}
#Second create and populate the list which will store the most common items:
GAD7 <- list(
instrument_name = "GAD-7",
questions = lapply(1:7, function(i) {
list(
question_no = paste0("GAD7_", i),
question_text = get_most_common_item_text(i)
)
})
)
#-----------PHQ9: Identify Most Commonly Used Wording, Save in List-------------
#The below will identify the most commonly used wording of each PHQ-9 item:
freqphq91i<- dat1 %>%
filter(Scale=="PHQ-9" & `Item Number`==1) %>%
group_by(Items) %>%
summarise(total=n())
freqphq92i<- dat1 %>%
filter(Scale=="PHQ-9" & `Item Number`==2) %>%
group_by(Items) %>%
summarise(total=n())
freqphq93i<- dat1 %>%
filter(Scale=="PHQ-9" & `Item Number`==3) %>%
group_by(Items) %>%
summarise(total=n())
freqphq94i<- dat1 %>%
filter(Scale=="PHQ-9" & `Item Number`==4) %>%
group_by(Items) %>%
summarise(total=n())
freqphq95i<- dat1 %>%
filter(Scale=="PHQ-9" & `Item Number`==5) %>%
group_by(Items) %>%
summarise(total=n())
freqphq96i<- dat1 %>%
filter(Scale=="PHQ-9" & `Item Number`==6) %>%
group_by(Items) %>%
summarise(total=n())
freqphq97i<- dat1 %>%
filter(Scale=="PHQ-9" & `Item Number`==7) %>%
group_by(Items) %>%
summarise(total=n())
freqphq98i<- dat1 %>%
filter(Scale=="PHQ-9" & `Item Number`==8) %>%
group_by(Items) %>%
summarise(total=n())
freqphq99i<- dat1 %>%
filter(Scale=="PHQ-9" & `Item Number`==9) %>%
group_by(Items) %>%
summarise(total=n())
freqphq910i<- dat1 %>%
filter(Scale=="PHQ-9" & `Item Number`==10) %>%
group_by(Items) %>%
summarise(total=n())
#The below code will create a function to automatically identify the most
#commonly used wordings of PHQ-9 items and then store them in a list:
#First create the function:
get_most_common_item_text <- function(item_number) {
dat1 %>%
filter(Scale == "PHQ-9" & `Item Number` == item_number) %>%
group_by(Items) %>%
summarise(total = n(), .groups = 'drop') %>%
arrange(desc(total)) %>%
slice(1) %>%
pull(Items)
}
#Second create and populate the list which will store the most common items:
PHQ9 <- list(
instrument_name = "PHQ-9",
questions = lapply(1:10, function(i) {
list(
question_no = paste0("PHQ-9_", i),
question_text = get_most_common_item_text(i)
)
})
)
#----------PHQ-9M: Identify Most Commonly Used Wording, Save in List------------
#The below will identify the most commonly used wording of each PHQ-9M
#(Modified for Teens) item and store them in individual objects for inspection
#to make sure the survey items are all coded correctly:
freqphq9m1i <- dat1 %>%
filter(Scale == "PHQ-9 Modified (PHQ-9M)" & `Item Number` == 1) %>%
group_by(Items) %>%
summarise(total = n())
freqphq9m2i <- dat1 %>%
filter(Scale == "PHQ-9 Modified (PHQ-9M)" & `Item Number` == 2) %>%
group_by(Items) %>%
summarise(total = n())
freqphq9m3i <- dat1 %>%
filter(Scale == "PHQ-9 Modified (PHQ-9M)" & `Item Number` == 3) %>%
group_by(Items) %>%
summarise(total = n())
freqphq9m4i <- dat1 %>%
filter(Scale == "PHQ-9 Modified (PHQ-9M)" & `Item Number` == 4) %>%
group_by(Items) %>%
summarise(total = n())
freqphq9m5i <- dat1 %>%
filter(Scale == "PHQ-9 Modified (PHQ-9M)" & `Item Number` == 5) %>%
group_by(Items) %>%
summarise(total = n())
freqphq9m6i <- dat1 %>%
filter(Scale == "PHQ-9 Modified (PHQ-9M)" & `Item Number` == 6) %>%
group_by(Items) %>%
summarise(total = n())
freqphq9m7i <- dat1 %>%
filter(Scale == "PHQ-9 Modified (PHQ-9M)" & `Item Number` == 7) %>%
group_by(Items) %>%
summarise(total = n())
freqphq9m8i <- dat1 %>%
filter(Scale == "PHQ-9 Modified (PHQ-9M)" & `Item Number` == 8) %>%
group_by(Items) %>%
summarise(total = n())
freqphq9m9i <- dat1 %>%
filter(Scale == "PHQ-9 Modified (PHQ-9M)" & `Item Number` == 9) %>%
group_by(Items) %>%
summarise(total = n())
freqphq9m10i <- dat1 %>%
filter(Scale == "PHQ-9 Modified (PHQ-9M)" & `Item Number` == 10) %>%
group_by(Items) %>%
summarise(total = n())
#The below code will create a function to automatically identify the most
#commonly used wordings of PHQ-9M items and then store them in a list:
#First create the function:
get_most_common_item_text <- function(item_number) {
dat1 %>%
filter(Scale == "PHQ-9 Modified (PHQ-9M)" & `Item Number` == item_number) %>%
group_by(Items) %>%
summarise(total = n(), .groups = 'drop') %>%
arrange(desc(total)) %>%
slice(1) %>%
pull(Items)
}
#Second create and populate the list which will store the most common items:
PHQ9M <- list(
instrument_name = "PHQ-9M",
questions = lapply(1:10, function(i) {
list(
question_no = paste0("PHQ-9M_", i),
question_text = get_most_common_item_text(i)
)
})
)
#-----------CES-D: Identify Most Commonly Used Wording, Save in List------------
#The below will identify the most commonly used wording of each CES-D item and
#store them in individual objects for inspection to make sure the survey items
#are all coded correctly:
freqcesd1i<- dat1 %>%
filter(Scale=="CES-D" & `Item Number`==1) %>%
group_by(Items) %>%
summarise(total=n())
freqcesd2i<- dat1 %>%
filter(Scale=="CES-D" & `Item Number`==2) %>%
group_by(Items) %>%
summarise(total=n())
freqcesd3i<- dat1 %>%
filter(Scale=="CES-D" & `Item Number`==3) %>%
group_by(Items) %>%
summarise(total=n())
freqcesd4i<- dat1 %>%
filter(Scale=="CES-D" & `Item Number`==4) %>%
group_by(Items) %>%
summarise(total=n())
freqcesd5i<- dat1 %>%
filter(Scale=="CES-D" & `Item Number`==5) %>%
group_by(Items) %>%
summarise(total=n())
freqcesd6i<- dat1 %>%
filter(Scale=="CES-D" & `Item Number`==6) %>%
group_by(Items) %>%
summarise(total=n())
freqcesd7i<- dat1 %>%
filter(Scale=="CES-D" & `Item Number`==7) %>%
group_by(Items) %>%
summarise(total=n())
freqcesd8i<- dat1 %>%
filter(Scale=="CES-D" & `Item Number`==8) %>%
group_by(Items) %>%
summarise(total=n())
freqcesd9i<- dat1 %>%
filter(Scale=="CES-D" & `Item Number`==9) %>%
group_by(Items) %>%
summarise(total=n())
freqcesd10i<- dat1 %>%
filter(Scale=="CES-D" & `Item Number`==10) %>%
group_by(Items) %>%
summarise(total=n())
freqcesd11i<- dat1 %>%
filter(Scale=="CES-D" & `Item Number`==11) %>%
group_by(Items) %>%
summarise(total=n())
freqcesd12i<- dat1 %>%
filter(Scale=="CES-D" & `Item Number`==12) %>%
group_by(Items) %>%
summarise(total=n())
freqcesd13i<- dat1 %>%
filter(Scale=="CES-D" & `Item Number`==13) %>%
group_by(Items) %>%
summarise(total=n())
freqcesd14i<- dat1 %>%
filter(Scale=="CES-D" & `Item Number`==14) %>%
group_by(Items) %>%
summarise(total=n())
freqcesd15i<- dat1 %>%
filter(Scale=="CES-D" & `Item Number`==15) %>%
group_by(Items) %>%
summarise(total=n())
freqcesd16i<- dat1 %>%
filter(Scale=="CES-D" & `Item Number`==16) %>%
group_by(Items) %>%
summarise(total=n())
freqcesd17i<- dat1 %>%
filter(Scale=="CES-D" & `Item Number`==17) %>%
group_by(Items) %>%
summarise(total=n())
freqcesd18i<- dat1 %>%
filter(Scale=="CES-D" & `Item Number`==18) %>%
group_by(Items) %>%
summarise(total=n())
freqcesd19i<- dat1 %>%
filter(Scale=="CES-D" & `Item Number`==19) %>%
group_by(Items) %>%
summarise(total=n())
freqcesd20i<- dat1 %>%
filter(Scale=="CES-D" & `Item Number`==20) %>%
group_by(Items) %>%
summarise(total=n())
#The below code will create a function to automatically identify the most
#commonly used wordings of CES-D items and then store them in a list:
#First create the function:
get_most_common_item_text <- function(item_number) {
dat1 %>%
filter(Scale == "CES-D" & `Item Number` == item_number) %>%
group_by(Items) %>%
summarise(total = n(), .groups = 'drop') %>%
arrange(desc(total)) %>%
slice(1) %>%
pull(Items)
}
#Second create and populate the list which will store the most common items:
CESD <- list(
instrument_name = "CES-D",
questions = lapply(1:20, function(i) {
list(
question_no = paste0("CESD_", i),
question_text = get_most_common_item_text(i)
)
})
)
#------------GADS: Identify Most Commonly Used Wording, Save in List------------
#The below will identify the most commonly used wording of each GADS item and
#store them in individual objects:
freqgads1i<- dat1 %>%
filter(Scale=="GADS" & `Item Number`==1) %>%
group_by(Items) %>%
summarise(total=n())
freqgads2i<- dat1 %>%
filter(Scale=="GADS" & `Item Number`==2) %>%
group_by(Items) %>%
summarise(total=n())
freqgads3i<- dat1 %>%
filter(Scale=="GADS" & `Item Number`==3) %>%
group_by(Items) %>%
summarise(total=n())
freqgads4i<- dat1 %>%
filter(Scale=="GADS" & `Item Number`==4) %>%
group_by(Items) %>%
summarise(total=n())
freqgads5i<- dat1 %>%
filter(Scale=="GADS" & `Item Number`==5) %>%
group_by(Items) %>%
summarise(total=n())
freqgads6i<- dat1 %>%
filter(Scale=="GADS" & `Item Number`==6) %>%
group_by(Items) %>%
summarise(total=n())
freqgads7i<- dat1 %>%
filter(Scale=="GADS" & `Item Number`==7) %>%
group_by(Items) %>%
summarise(total=n())
freqgads8i<- dat1 %>%
filter(Scale=="GADS" & `Item Number`==8) %>%
group_by(Items) %>%
summarise(total=n())
freqgads9i<- dat1 %>%
filter(Scale=="GADS" & `Item Number`==9) %>%
group_by(Items) %>%
summarise(total=n())
#The below code will create a function to automatically identify the most
#commonly used wordings of GADS items and then store them in a list:
#First create the function:
get_most_common_item_text <- function(item_number) {
dat1 %>%
filter(Scale == "GADS" & `Item Number` == item_number) %>%
group_by(Items) %>%
summarise(total = n(), .groups = 'drop') %>%
arrange(desc(total)) %>%
slice(1) %>%
pull(Items)
}
#Second create and populate the list which will store the most common items:
GADS <- list(
instrument_name = "GADS",
questions = lapply(1:9, function(i) {
list(