-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01_TexasSTAR_analysis.rmarkdown
More file actions
3298 lines (2805 loc) · 161 KB
/
01_TexasSTAR_analysis.rmarkdown
File metadata and controls
3298 lines (2805 loc) · 161 KB
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: "TexasSTAR_analysis"
author: "Daniel Brock"
date: "2024-08-04"
output: html_document
---
# 0. Setup
```{r setup, include=FALSE}
# Importing requiring Packages
library(plyr)
library(tidyverse)
library(ggbreak)
library(readxl)
library(writexl)
library(finalfit)
library(chisq.posthoc.test)
library(rstatix)
library(emmeans)
library(performance)
library(ggeffects)
library(gtsummary)
library(flextable)
library(psych)
library(RColorBrewer)
library(car)
library(ggpubr)
library(scales)
library(patchwork)
library(ggpubr)
library(DHARMa)
library(MASS)
library(qs2)
library(ggforce)
library(ggforestplot)
library(wesanderson)
# Setting the working director
cwd <- getwd()
setwd(cwd)
```
# 1. Importing datasets
```{r}
# Applicant-level information
df <- read.csv(file = "data/STAR_Responses_2017_2023.csv", na.strings = "N/A")
df$degrees <- paste0(df$Degree, "-", df$Other.Degrees)
df$degrees <- plyr::mapvalues(x = df$degrees, from = c("DO-", "MD-"), to = c("DO", "MD"))
# Programs applied to and interviewed at per applicant
programs <- read.csv(file = "data/STAR_Programs_2017_2023.csv")
```
# 2. Data wrangling
```{r}
df_clean <- df %>% mutate(
# Making specialty a factor
Specialty = Specialty %>%
factor(levels = sort(unique(Specialty))),
# Making public schools a factor
Public_School = Public_School %>%
factor(levels = c("No", "Yes")),
# Making Ivy status a factor
IvyP = IvyP %>%
factor(levels = c("No", "Yes")) %>%
ff_label("Ivy League"),
# Making match status a factor
Matched = Matched %>%
plyr::mapvalues(from = c("N", "Y"), to = c("No", "Yes")) %>%
factor(levels = c("No", "Yes")),
# Making home state a factor
Home.State = Home.State %>%
factor(levels = sort(unique(Home.State))),
# Making home region a factor
Home.Region = Home.Region %>%
plyr::mapvalues(from = "", to = NA) %>%
plyr::mapvalues(from = c("CGSA", "NEGSA", "SGSA", "WGSA"), to = c("Central", "Northeast", "South", "West")) %>%
factor(levels = c("Northeast", "Central", "South", "West")),
# Making step1 ranges a factor
Step.1 = Step.1 %>%
factor(levels = c("190-194", "195-199", "200-204", "205-209", "210-214", "215-219", "220-224", "225-229", "230-234", "235-239", "240-244", "245-249", "250-254", "255-259", "260-264", "265-269", "270 or higher")) %>%
ff_label("Step 1 Score"),
# Making step2 ranges a factor
Step.2.CK = Step.2.CK %>%
factor(levels = c("200-204", "205-209", "210-214", "215-219", "220-224", "225-229", "230-234", "235-239", "240-244", "245-249", "250-254", "255-259", "260-264", "265-269", "270 or higher")) %>%
ff_label("Step 2 Score"),
# Binning STEP2 CK Release Dates
Release...Step.2.CK = Release...Step.2.CK %>% plyr::mapvalues(from = "", to = NA),
Step.2.CK.release =
dplyr::case_when(
Release...Step.2.CK %in% c("Mid September", "Late September", "Early October", "Mid October") ~ "Early",
Release...Step.2.CK %in% c("Late October", "Early November", "Mid November") ~ "Mid",
Release...Step.2.CK %in% c("Late November", "Early December", "Mid December", "Late December", "Early January", "Mid January", "Late January", "After Rank List Submission") ~ "Late"
) %>% factor(levels = c("Early", "Mid", "Late")),
# Changing Cumulative Quartile into integers
Cumulative.Quartile = Cumulative.Quartile %>%
plyr::mapvalues(from = c("1st", "2nd", "3rd", "4th"), to = c(1, 2, 3, 4)),
# Making honors a factor
Honors.A.This.Specialty = Honors.A.This.Specialty %>%
plyr::mapvalues(from = "", to = NA) %>%
factor(levels = c("No", "Yes")) %>%
ff_label("Honors in Specialty of Choice"),
# Making AOA status a factor
AOA.Sigma = AOA.Sigma %>%
factor(levels = c("No", "Yes", "No School Chapter")) %>%
ff_label("AOA"),
# Making gold humanism a factor
GHHS = GHHS %>%
factor(levels = c("No", "Yes", "No School Chapter")) %>%
ff_label("Gold Humanism Honors Society"),
# Making couples matching a factor
Couples.Match = Couples.Match %>%
factor(levels = c("No", "Yes")),
# Making degree a factor - save for later...
# Making taking a research year a factor
Research.Year = Research.Year %>%
factor(levels = c("No", "Yes")),
# Making taking a leave of absence year a factor
Absence.Year = Absence.Year %>%
factor(levels = c("No", "Yes")),
# Making required to remediate a factor
Required.to.Remediate = Required.to.Remediate %>%
factor(levels = c("No", "Yes")),
# Making pass attempt for step1 a factor
Pass.Attempt...Step.1 = Pass.Attempt...Step.1 %>%
plyr::mapvalues(from = c(""), to = c(NA)) %>%
factor(levels = c("1st", "2nd", "3rd")) %>%
ff_label("Step1 Pass Attempt"),
# Making pass attempt for step2ck a factor
Pass.Attempt...Step.1 = Pass.Attempt...Step.2.CK %>%
plyr::mapvalues(from = c(""), to = c(NA)) %>%
factor(levels = c("1st", "2nd", "3rd")) %>%
ff_label("Step2CK Pass Attempt"),
# Making pass attempt for step2cs a factor
Pass.Attempt...Step.1 = Pass.Attempt...Step.2.CS %>%
plyr::mapvalues(from = c(""), to = c(NA)) %>%
factor(levels = c("1st", "2nd", "3rd")) %>%
ff_label("Step2CS Pass Attempt"),
# Making the majority of interview offers a factor
Majority.of.Interview.Offers = Majority.of.Interview.Offers %>%
factor(levels = c("Late September (before MSPE release)", "Promptly after Oct 1 (MSPE release)", "Early October", "Mid October", "Late October", "Early November", "Mid November", "Late November", "Early December", "Mid December")),
# Making the majority of interviews attended a factor
Majority.of.Interviews.Attended = Majority.of.Interviews.Attended %>%
factor(levels = c("October", "November", "December", "January", "February")),
# Making interview cost a factor
Interview.Cost = Interview.Cost %>%
plyr::mapvalues(from =
c("< $500", "<$500", "$500-$999", "$1000-$1499", "$1500-$1999", "$2000-$2499", "$2500-$2999", "$3000-$3499", "$3500-$3999", "$4000-$4499", "$4500-$4999", "$5000-$5499", "$5500-$5999", "$6000-$6499", "$6500-$6999", "$7000-$7499", "$7500-$7999", "$8000-$8499", "$8500-$8999", "$9000-$9499", "$9500-$9999", "$10000-$10499", "$10500-$10999", "$11000-$11499", "$11500-$11599", "$12000 and above"),
to =
c("<$1000", "<$1000", "<$1000", "$1000-$1999", "$1000-$1999", "$2000-$2999", "$2000-$2999", "$3000-$3999", "$3000-$3999", "$4000-$4999", "$4000-$4999", "$5000-$5999", "$5000-$5999", "$6000-$6999", "$6000-$6999", "$7000-$7999", "$7000-$7999", "$8000-$8999", "$8000-$8999", "$9000-$9999", "$9000-$9999", "$10000-$10999", "$10000-$10999", "$11000-$11999", "$11000-$11999", ">$12000")) %>%
factor(levels = c("<$1000", "$1000-$1999", "$2000-$2999", "$3000-$3999", "$4000-$4999", "$5000-$5999", "$6000-$6999", "$7000-$7999", "$8000-$8999", "$9000-$9999", "$10000-$10999", "$11000-$11999", ">$12000")),
# Making Application fees a factor
Application.Fees = Application.Fees %>%
plyr::mapvalues(from = c("$3500 and above"), to = c(">$3500")) %>%
factor(levels = c("<$500", "$500-$999", "$1000-$1499", "$1500-$1999", "$2000-$2499", "$2500-$2999", "$3000-$3499", ">$3500")),
# Making virtual interview costs a factor
Virtual.Interview.Cost = Virtual.Interview.Cost %>%
plyr::mapvalues(from = c("< $50", "> $300"), to = c("<$50", ">$300")) %>%
factor(levels = c("<$50", "$50-$100", "$101-$150", "$151-$200", "$201-$250", "$251-$300", ">$300")),
# Making other costs a factor
Other.Costs = Other.Costs %>%
plyr::mapvalues(from =
c("< $500", "<$500", "$500-$999", "$1000-$1499", "$1500-$1999", "$2000-$2499", "$2500-$2999", "$3000-$3499", "$3500-$3999", "$4000-$4499", "$4500-$4999", "$5000-$5499", "$5500-$5999", "$6000-$6499", "$6500-$6999", "$7000-$7499", "$7500-$7999", "$8000-$8499", "$8500-$8999", "$9000-$9499", "$9500-$9999", "$10000 and above"),
to =
c("<$1000", "<$1000", "<$1000", "$1000-$1999", "$1000-$1999", "$2000-$2999", "$2000-$2999", "$3000-$3999", "$3000-$3999", "$4000-$4999", "$4000-$4999", "$5000-$5999", "$5000-$5999", "$6000-$6999", "$6000-$6999", "$7000-$7999", "$7000-$7999", "$8000-$8999", "$8000-$8999", "$9000-$9999", "$9000-$9999", ">$10000")) %>%
factor(levels = c("<$1000", "$1000-$1999", "$2000-$2999", "$3000-$3999", "$4000-$4999", "$5000-$5999", "$6000-$6999", "$7000-$7999", "$8000-$8999", "$9000-$9999", ">$10000")),
# Making Total costs a factor
Total.Costs = Total.Costs %>%
plyr::mapvalues(from =
c("< $500", "<$500", "$500-$999", "$1000-$1499", "$1500-$1999", "$2000-$2499", "$2500-$2999", "$3000-$3499", "$3500-$3999", "$4000-$4499", "$4500-$4999", "$5000-$5499", "$5500-$5999", "$6000-$6499", "$6500-$6999", "$7000-$7499", "$7500-$7999", "$8000-$8499", "$8500-$8999", "$9000-$9499", "$9500-$9999", "$10000-$10499", "$10500-$10999", "$11000-$11499", "$11500-$11999", "$12000-$12499", "$12500-$12999", "$13000-$13499", "$13500-$13999", "$14000-$14499", "$14500-$14999", "$15000-$15499", "$15500-$15999", "$16000-$16499", "$16500-$16999", "$17000-$17499", "$17500-$17999", "$18000-$18499", "$18500-$18999", "$19000-$19499", "$19500-$19999", "$20000-$20499", "$20500-$20999", "$21000-$21499", "$21500-$21999", "$22000-$22499", "$22500-$22999", "$23000-$23499", "$23500-$23999", "$24000-$24499", "$24500-$24999", "$25000 and above"),
to =
c("<$1000", "<$1000", "<$1000", "$1000-$1999", "$1000-$1999", "$2000-$2999", "$2000-$2999", "$3000-$3999", "$3000-$3999", "$4000-$4999", "$4000-$4999", "$5000-$5999", "$5000-$5999", "$6000-$6999", "$6000-$6999", "$7000-$7999", "$7000-$7999", "$8000-$8999", "$8000-$8999", "$9000-$9999", "$9000-$9999", "$10000-$10999", "$10000-$10999", "$11000-$11999", "$11000-$11999", "$12000-$12999", "$12000-$12999", "$13000-$13999", "$13000-$13999", "$14000-$14999", "$14000-$14999", "$15000-$15999", "$15000-$15999", "$16000-$16999", "$16000-$16999", "$17000-$17999", "$17000-$17999", "$18000-$18999", "$18000-$18999", "$19000-$19999", "$19000-$19999", "$20000-$20999", "$20000-$20999", "$21000-$21999", "$21000-$21999", "$22000-$22999", "$22000-$22999", "$23000-$23999", "$23000-$23999", "$24000-$24999", "$24000-$24999", ">$25000")) %>%
factor(levels = c("<$1000", "$1000-$1999", "$2000-$2999", "$3000-$3999", "$4000-$4999", "$5000-$5999", "$6000-$6999", "$7000-$7999", "$8000-$8999", "$9000-$9999", "$10000-$10999", "$11000-$11999", "$12000-$12999", "$13000-$13999", "$14000-$14999", "$15000-$15999", "$16000-$16999", "$17000-$17999", "$18000-$18999", "$19000-$19999", "$20000-$20999", "$21000-$21999", "$22000-$22999", "$23000-$23999", "$24000-$24999", ">$25000")),
# Making Virtual Environment a factor
Virtual.Environment = Virtual.Environment %>%
factor(levels = c("Strongly Agree", "Agree", "Undecided", "Disagree", "Strongly Disagree")),
# Making ERAS supplemental a factor
ERAS.Supplemental = ERAS.Supplemental %>%
factor(levels = c("Strongly Agree", "Agree", "Undecided", "Disagree", "Strongly Disagree")),
# Making Demographic Willingness a factor
Demographic.Willingness = Demographic.Willingness %>%
plyr::mapvalues(from = c("N", "Y"), to = c("No", "Yes")) %>%
factor(levels = c("No", "Yes")),
# Making age group a factor
Age.Group = Age.Group %>%
plyr::mapvalues(from = c("< 25", ">39"), to = c("<25", ">40")) %>%
factor(levels = c("<25", "25-27", "28-30", "31-33", "34-36", "37-39", ">40")),
# making sexual orientation a factor
Sexual.Orientation = Sexual.Orientation %>%
factor(levels = c("Male", "Female", "Intersex", "Prefer not to answer")) %>%
ff_label("Gender"),
# Making race/ethncity a factor
Race.Ethnicity = Race.Ethnicity %>%
plyr::mapvalues(from = c("N", "Y"), to = c("No", "Yes")) %>%
factor(levels = c("No", "Yes")) %>%
ff_label("Underrepresented in Medicine"),
# Making first generation college a factor
First.Generation.College = First.Generation.College %>%
plyr::mapvalues(from = c("N", "Y"), to = c("No", "Yes")) %>%
factor(levels = c("No", "Yes")),
# Making food & housing insecurity a factor
Food.Housing.Insecurity = Food.Housing.Insecurity %>%
plyr::mapvalues(from = c("N", "Y"), to = c("No", "Yes")) %>%
factor(levels = c("No", "Yes"))
)
# Interview success rate (%)
df_clean$interview_percent <- (df_clean$InterviewOffer_Total / df_clean$Applied_Total) * 100
```
# 3. Demographics
## 3.1 Table 1 basic demographic statistics
```{r}
# Dependent and explanatory variables
dependent = "degrees"
explanatory = c("Specialty", "Public_School", "IvyP", "Applied_Total", "InterviewOffer_Total", "Matched", "Step.1", "Step.2.CK", "Cumulative.Quartile", "Quartile.Rank", "X..Honored.Clerkships", "Honors.A.This.Specialty", "AOA.Sigma", "GHHS", "Couples.Match", "X..Research.Experiences", "X..Abstracts..Pres..Posters", "X..Peer.Rev.Publications", "X..Volunteer.Experiences", "X..Leadership.Positions", "Required.to.Remediate", "Pass.Attempt...Step.1", "Pass.Attempt...Step.2.CK", "Pass.Attempt...Step.2.CS", "Majority.of.Interview.Offers", "Majority.of.Interviews.Attended", "X..Interviews.Attended", "Interview.Cost", "Application.Fees", "Virtual.Interview.Cost", "Other.Costs", "Virtual.Environment", "ERAS.Supplemental", "Demographic.Willingness", "Age.Group", "Sexual.Orientation", "Race.Ethnicity", "First.Generation.College", "Food.Housing.Insecurity")
table1 <- df_clean[df_clean$degrees %in% c("MD", "MD-PhD", "MD-MPH", "MD-MBA", "MD-MSc"), ] #filtering for MD students whose group > 1000 for now
table1 <- table1 %>%
summary_factorlist(
dependent = dependent, explanatory = explanatory,
add_col_totals = TRUE, include_col_totals_percent = TRUE, p = TRUE, cont = "median",
p_cat = "chisq"
#cont = "median", p = TRUE, p_cat = "chisq", digits = 2, na_include = TRUE,
)
# Optional export to excel
#write_xlsx(table1, path = paste0(cwd, "/tables/table1.xlsx"))
```
## 3.2 Demographic Analysis
```{r}
# Finalfit table for demographic factors
pred_factors <- c("Age.Group", "Sexual.Orientation", "Race.Ethnicity", "Food.Housing.Insecurity", "First.Generation.College", "Home.Region", "Public_School", "IvyP")
dual_degrees <- c("MD-PhD", "MD-MPH", "MD-MBA", "MD-MSc")
df_list <- list()
for (predictor in pred_factors) {
print(predictor)
demographics_table <- df_clean %>% dplyr::filter(degrees %in% c("MD", dual_degrees)) %>%
summary_factorlist(dependent = "degrees", explanatory = c(predictor),
add_col_totals = TRUE, include_col_totals_percent = TRUE,
p = TRUE, cont = "median", p_cat = "chisq")
demographics_table$demographic <- predictor
df_list[[predictor]] <- demographics_table
}
demo_df <- dplyr::bind_rows(df_list)
# Exporting to excel
#write_xlsx(x = demo_df, path = "tables/demographics.xlsx")
```
```{r}
# Fisher and pairwise stuff
# Age groups
df_list <- list()
for (degree in dual_degrees) {
dt <- df_clean %>% dplyr::filter(degrees %in% c("MD", degree)) %>% dplyr::filter(!is.na(Age.Group))
dt <- table(dt$Age.Group, dt$degrees) %>% as.data.frame.matrix()
dt <- dt[ , c(2, 1)]
print(degree)
print(fisher.test(dt, simulate.p.value = T))
#print(chisq.test(dt))
fisher.posthoc <- row_wise_fisher_test(dt, p.adjust.method = "fdr", detailed = T)
fisher.posthoc$degree <- degree
fisher.posthoc$predictor <- "Age"
df_list[[degree]] <- fisher.posthoc
}
demo_age <- dplyr::bind_rows(df_list)
# Sexual Orientation
df_list <- list()
for (degree in dual_degrees) {
dt <- df_clean %>% dplyr::filter(degrees %in% c("MD", degree)) %>% dplyr::filter(Sexual.Orientation %in% c("Male", "Female"))
dt$Sexual.Orientation <- factor(x = dt$Sexual.Orientation, levels = c("Male", "Female"))
dt <- table(dt$Sexual.Orientation, dt$degrees) %>% as.data.frame.matrix()
dt2 <- dt[ , c(2, 1)]
print(degree)
print(fisher.test(dt, simulate.p.value = T))
fisher.posthoc <- row_wise_fisher_test(dt2, p.adjust.method = "fdr", detailed = T)
fisher.posthoc$degree <- degree
fisher.posthoc$predictor <- "Sex"
df_list[[degree]] <- fisher.posthoc
}
demo_sex <- dplyr::bind_rows(df_list)
# Race/Ethnicity
df_list <- list()
for (degree in dual_degrees) {
dt <- df_clean %>% dplyr::filter(degrees %in% c("MD", degree)) %>% dplyr::filter(!is.na(Race.Ethnicity))
dt <- table(dt$Race.Ethnicity, dt$degrees) %>% as.data.frame.matrix()
dt2 <- dt[ , c(2, 1)]
print(degree)
print(fisher.test(dt, simulate.p.value = T))
fisher.posthoc <- row_wise_fisher_test(dt2, p.adjust.method = "fdr", detailed = T)
fisher.posthoc$degree <- degree
fisher.posthoc$predictor <- "URM Status"
df_list[[degree]] <- fisher.posthoc
}
demo_urm <- dplyr::bind_rows(df_list)
# Food / Housing Insecurity
df_list <- list()
for (degree in dual_degrees) {
dt <- df_clean %>% dplyr::filter(degrees %in% c("MD", degree)) %>% dplyr::filter(!is.na(Food.Housing.Insecurity))
dt <- table(dt$Food.Housing.Insecurity, dt$degrees) %>% as.data.frame.matrix()
dt2 <- dt[ , c(2, 1)]
print(degree)
print(fisher.test(dt, simulate.p.value = T))
fisher.posthoc <- row_wise_fisher_test(dt2, p.adjust.method = "fdr", detailed = T)
fisher.posthoc$degree <- degree
fisher.posthoc$predictor <- "Food/Housing Insecurity"
df_list[[degree]] <- fisher.posthoc
}
demo_food_housing <- dplyr::bind_rows(df_list)
# First Generation
df_list <- list()
for (degree in dual_degrees) {
dt <- df_clean %>% dplyr::filter(degrees %in% c("MD", degree)) %>% dplyr::filter(!is.na(First.Generation.College))
dt <- table(dt$First.Generation.College, dt$degrees) %>% as.data.frame.matrix()
dt2 <- dt[ , c(2, 1)]
print(degree)
print(fisher.test(dt, simulate.p.value = T))
fisher.posthoc <- row_wise_fisher_test(dt2, p.adjust.method = "fdr", detailed = T)
fisher.posthoc$degree <- degree
fisher.posthoc$predictor <- "First Generation"
df_list[[degree]] <- fisher.posthoc
}
demo_first_gen <- dplyr::bind_rows(df_list)
# Home Region
df_list <- list()
for (degree in dual_degrees) {
dt <- df_clean %>% dplyr::filter(degrees %in% c("MD", degree)) %>% dplyr::filter(!is.na(Home.Region))
dt <- table(dt$Home.Region, dt$degrees) %>% as.data.frame.matrix()
dt <- dt[ , c(2, 1)]
fisher.test(dt, simulate.p.value = T)
fisher.posthoc <- row_wise_fisher_test(dt, p.adjust.method = "fdr", detailed = T)
fisher.posthoc$degree <- degree
fisher.posthoc$predictor <- "Home Region"
df_list[[degree]] <- fisher.posthoc
}
demo_home_region <- dplyr::bind_rows(df_list)
# Public School
df_list <- list()
for (degree in dual_degrees) {
dt <- df_clean %>% dplyr::filter(degrees %in% c("MD", degree)) %>% dplyr::filter(!is.na(Public_School))
dt <- table(dt$Public_School, dt$degrees) %>% as.data.frame.matrix()
dt2 <- dt[ , c(2, 1)]
print(degree)
print(fisher.test(dt, simulate.p.value = T))
fisher.posthoc <- row_wise_fisher_test(dt2, p.adjust.method = "fdr", detailed = T)
fisher.posthoc$degree <- degree
fisher.posthoc$predictor <- "Public School"
df_list[[degree]] <- fisher.posthoc
}
demo_public_school <- dplyr::bind_rows(df_list)
# Ivy
df_list <- list()
for (degree in dual_degrees) {
dt <- df_clean %>% dplyr::filter(degrees %in% c("MD", degree)) %>% dplyr::filter(!is.na(IvyP))
dt <- table(dt$IvyP, dt$degrees) %>% as.data.frame.matrix()
dt2 <- dt[ , c(2, 1)]
print(degree)
print(fisher.test(dt, simulate.p.value = T))
fisher.posthoc <- row_wise_fisher_test(dt2, p.adjust.method = "fdr", detailed = T)
fisher.posthoc$degree <- degree
fisher.posthoc$predictor <- "Ivy"
df_list[[degree]] <- fisher.posthoc
}
demo_ivy <- dplyr::bind_rows(df_list)
# Merging all demographic fisher tests into a single dataframe
demo_df_fish <- dplyr::bind_rows(list(demo_age, demo_sex, demo_urm, demo_food_housing, demo_first_gen, demo_home_region, demo_public_school, demo_ivy))
# Exporting to excel
#write_xlsx(x = demo_df_fish, path = "tables/demographics_fisher.xlsx")
```
# 4. Activities and Test Scores
## 4.1 STEP Scores
```{r}
# STEP1 Scores
step1_scores <- c("190-194", "195-199", "200-204", "205-209", "210-214", "215-219", "220-224", "225-229", "230-234", "235-239", "240-244", "245-249", "250-254", "255-259", "260-264", "265-269", "270 or higher")
step1_centered <- c(192, 197, 202, 207, 212, 217, 222, 227, 232, 237, 242, 247, 252, 257, 262, 267, 271)
df_clean$Step.1_chr <- as.character(df_clean$Step.1)
df_clean$step1_centered <- plyr::mapvalues(x = df_clean$Step.1_chr, from = step1_scores, to = step1_centered) %>% as.integer()
# STEP2 Scores
step2_scores <- c("200-204", "205-209", "210-214", "215-219", "220-224", "225-229", "230-234", "235-239", "240-244", "245-249", "250-254", "255-259", "260-264", "265-269", "270 or higher")
step2_centered <- c(202, 207, 212, 217, 222, 227, 232, 237, 242, 247, 252, 257, 262, 267, 271)
df_clean$Step.2.CK_chr <- as.character(df_clean$Step.2.CK)
df_clean$step2_centered <- plyr::mapvalues(x = df_clean$Step.2.CK_chr, from = step2_scores, to = step2_centered) %>% as.integer()
# Calculating STEP2 Scores relative to STEP1
df_clean$STEP_relative <- df_clean$step2_centered - df_clean$step1_centered
# Tidying for plotting - STEP1
degree_list <- c("MD", "MD-PhD", "MD-MPH", "MD-MBA", "MD-MSc")
step1_counts <- df_clean %>%
dplyr::filter(degrees %in% degree_list) %>% dplyr::filter(!is.na(step1_centered)) %>%
dplyr::group_by(degrees, step1_centered) %>%
dplyr::summarise(step1_counts = n())
step1_totals <- df_clean %>%
dplyr::filter(degrees %in% degree_list) %>% dplyr::filter(!is.na(step1_centered)) %>%
dplyr::group_by(degrees) %>%
dplyr::summarise(step1_totals = n())
step1_counts <- merge(step1_counts, step1_totals, by = "degrees")
step1_counts$percents <- (step1_counts$step1_counts / step1_counts$step1_totals) * 100
# Tidying for plotting - STEP2
step2_counts <- df_clean %>%
dplyr::filter(degrees %in% degree_list) %>% dplyr::filter(!is.na(step2_centered)) %>%
dplyr::group_by(degrees, step2_centered) %>%
dplyr::summarise(step2_counts = n())
step2_totals <- df_clean %>%
dplyr::filter(degrees %in% degree_list) %>% dplyr::filter(!is.na(step2_centered)) %>%
dplyr::group_by(degrees) %>%
dplyr::summarise(step2_totals = n())
step2_counts <- merge(step2_counts, step2_totals, by = "degrees")
step2_counts$percents <- (step2_counts$step2_counts / step2_counts$step2_totals) * 100
```
```{r}
# Plotting for clarity - STEP1
step1_distribution <- step1_counts %>% ggplot(aes(x = step1_centered, y = percents, color = degrees)) +
geom_point() +
geom_line() +
labs(x = "STEP1 Centered Score", y = "Percent of Total (%)", color = "Degrees", title = "STEP1 Score Distribution") +
theme_classic() +
theme(plot.title = element_text(hjust = 0.5))
# Plotting for clarity - STEP2
step2_distribution <- step2_counts %>% ggplot(aes(x = step2_centered, y = percents, color = degrees)) +
geom_point() +
geom_line() +
labs(x = "STEP2 Centered Score", y = "Percent of Total (%)", color = "Degrees", title = "STEP2 Score Distribution") +
theme_classic() +
theme(plot.title = element_text(hjust = 0.5))
# Patchwork to put graphs together
step_distribution <- step1_distribution | step2_distribution
print(step_distribution)
# STEP2 relative to STEP1 score difference
step_delta_plot <- df_clean %>% dplyr::filter(degrees %in% degree_list) %>%
ggplot(aes(x = degrees, y = STEP_relative, fill = degrees)) +
geom_boxplot(outlier.shape = NA) +
labs(x = "Degrees", y = "STEP2 Score Delta (STEP2 - STEP1)", fill = "Degrees", title = "STEP2 - STEP1 Score Deltas") +
theme_classic() +
theme(plot.title = element_text(hjust = 0.5))
print(step_delta_plot)
# exporting figures
#ggsave(plot = step_distribution, filename = "figures/step_scores_plot.pdf", width = 4000, height = 1500, dpi = 300, units = "px")
#ggsave(plot = step_delta_plot, filename = "figures/step_delta_plot.pdf", width = 1800, height = 1400, dpi = 300, units = "px")
```
```{r}
# Statistical Tests for STEP1
step1_counts <- df_clean %>%
dplyr::filter(degrees %in% degree_list) %>% dplyr::filter(!is.na(step1_centered))
kruskal_res <- kruskal.test(step1_centered ~ degrees, data = step1_counts) #kruskal test for non-normal median comparisons
pairwise_kruskal <- pairwise.wilcox.test(step1_counts$step1_centered, step1_counts$degrees, p.adjust.method = "fdr")
print(kruskal_res)
print(pairwise_kruskal)
anova_res <- aov(step1_centered ~ degrees, data = step1_counts) #ANOVA for normal mean comparisons
pairwise_anova_step1 <- TukeyHSD(anova_res)
pairwise_anova_step1 <- as.data.frame(pairwise_anova_step1$degrees) %>% tibble::rownames_to_column(var = "comp")
pairwise_anova_step1$exam <- "STEP1"
summary(anova_res)
# Statistical Tests for STEP2
step2_counts <- df_clean %>%
dplyr::filter(degrees %in% degree_list) %>% dplyr::filter(!is.na(step2_centered))
kruskal_res <- kruskal.test(step2_centered ~ degrees, data = step2_counts) #kruskal test for non-normal median comparisons
pairwise_kruskal <- pairwise.wilcox.test(step2_counts$step2_centered, step2_counts$degrees, p.adjust.method = "fdr")
print(kruskal_res)
print(pairwise_kruskal)
anova_res <- aov(step2_centered ~ degrees, data = step2_counts) #ANOVA for normal mean comparisons
pairwise_anova_step2 <- TukeyHSD(anova_res)
pairwise_anova_step2 <- as.data.frame(pairwise_anova_step2$degrees) %>% tibble::rownames_to_column(var = "comp")
pairwise_anova_step2$exam <- "STEP2"
summary(anova_res)
# Statistical Tests for STEP Delta
step_delta <- df_clean %>%
dplyr::filter(degrees %in% degree_list) %>% dplyr::filter(!is.na(STEP_relative))
step_delta_summary <- step_delta %>% dplyr::group_by(degrees) %>%
dplyr::summarise(
mean_step_diff = mean(STEP_relative),
sd_step_diff = sd(STEP_relative)
)
kruskal_res <- kruskal.test(STEP_relative ~ degrees, data = step_delta) #kruskal test for non-normal median comparisons
pairwise_kruskal <- pairwise.wilcox.test(step_delta$STEP_relative, step_delta$degrees, p.adjust.method = "fdr")
print(kruskal_res)
print(pairwise_kruskal)
anova_res <- aov(STEP_relative ~ degrees, data = step_delta) #ANOVA for normal mean comparisons
pairwise_anova_delta <- TukeyHSD(anova_res)
pairwise_anova_delta <- as.data.frame(pairwise_anova_delta$degrees) %>% tibble::rownames_to_column(var = "comp")
pairwise_anova_delta$exam <- "STEP Delta"
summary(anova_res)
# Statistical Tests for time of STEP2 CK release
df_list <- list()
dual_degrees <- c("MD-PhD", "MD-MPH", "MD-MBA", "MD-MSc")
for (degree in dual_degrees) {
dt <- df_clean %>%
dplyr::filter(degrees %in% c("MD", degree)) %>%
dplyr::filter(!is.na(Step.2.CK.release))
dt <- table(dt$Step.2.CK.release, dt$degrees) %>% as.data.frame.matrix()
dt2 <- dt[ , c(2, 1)]
print(degree)
print(fisher.test(dt, simulate.p.value = T))
fisher.posthoc <- row_wise_fisher_test(dt2, p.adjust.method = "fdr", detailed = T)
fisher.posthoc$degree <- degree
fisher.posthoc$predictor <- "STEP2 Release"
df_list[[degree]] <- fisher.posthoc
}
# Merging and exporting to excel
step_stats <- dplyr::bind_rows(list(pairwise_anova_step1, pairwise_anova_step2, pairwise_anova_delta))
demo_step2_release <- dplyr::bind_rows(df_list)
# Exporting STEP stats tables
#write_xlsx(x = step_stats, path = "tables/STEP_anova_stats.xlsx")
#write_xlsx(x = demo_step2_release, path = "tables/STEP2_release_stats.xlsx")
```
```{r}
# Table for STEP1 - median or mean?
step1_table <- step1_counts %>% summary_factorlist(
dependent = "degrees", explanatory = c("step1_centered"), cont = "mean", p = T,
add_col_totals = TRUE, include_col_totals_percent = TRUE
)
# Table for STEP2
step2_table <- step2_counts %>% summary_factorlist(
dependent = "degrees", explanatory = c("step2_centered"), cont = "mean", p = T,
add_col_totals = TRUE, include_col_totals_percent = TRUE
)
# Table for Delta STEP (STEP2 - STEP1)
step_diff_table <- df_clean %>% dplyr::filter(degrees %in% degree_list) %>%
summary_factorlist(
dependent = "degrees", explanatory = c("STEP_relative"), cont = "mean", p = T,
add_col_totals = TRUE, include_col_totals_percent = TRUE
)
# Table for STEP2 CK Release data
step2_release_table <- df_clean %>% dplyr::filter(degrees %in% degree_list) %>%
summary_factorlist(
dependent = "degrees", explanatory = c("Step.2.CK.release"), p_cat = "chisq", p = T,
add_col_totals = TRUE, include_col_totals_percent = TRUE
)
# Merging into a STEP table to export
step_table <- dplyr::bind_rows(step1_table, step2_table, step_diff_table, step2_release_table)
# Exporting as excel
#write_xlsx(x = step_table, path = "tables/STEP_metrics_table_mean.xlsx")
```
## 4.2 Class Quartiles
```{r}
# Function to calculate stats and pairwise comparisons for class quartiles
quartile_calculator <- function(comparison, dual_degree) {
quartile_df <- df_clean %>%
dplyr::filter(degrees %in% c("MD", dual_degree)) %>%
dplyr::filter(!is.na(comparison))
quartile_df <- table(quartile_df$degrees, quartile_df[[comparison]]) %>% as.data.frame.matrix() %>% t()
quartile_df <- quartile_df[ , c(2, 1)]
print(quartile_df)
chi_res <- chisq.test(quartile_df)
print(chi_res)
chi_posthoc <- chisq.posthoc.test(quartile_df, method = "fdr")
fisher.posthoc <- row_wise_fisher_test(quartile_df, p.adjust.method = "fdr", detailed = T)
fisher.posthoc$degrees <- dual_degree
return(fisher.posthoc)
}
```
```{r}
# Cumulative quartile
quartile_mdphd <- quartile_calculator(comparison = "Cumulative.Quartile", dual_degree = "MD-PhD")
quartile_mdmph <- quartile_calculator(comparison = "Cumulative.Quartile", dual_degree = "MD-MPH")
quartile_mdmba <- quartile_calculator(comparison = "Cumulative.Quartile", dual_degree = "MD-MBA")
quartile_mdmsc <- quartile_calculator(comparison = "Cumulative.Quartile", dual_degree = "MD-MSc")
cumulative_quartile <- dplyr::bind_rows(list(quartile_mdphd, quartile_mdmph, quartile_mdmba, quartile_mdmsc))
cumulative_quartile$quartile_metric <- "Cumulative Quartile"
# Quartile Rank
rankq_mdphd <- quartile_calculator(comparison = "Quartile.Rank", dual_degree = "MD-PhD")
rankq_mdmph <- quartile_calculator(comparison = "Quartile.Rank", dual_degree = "MD-MPH")
rankq_mdmba <- quartile_calculator(comparison = "Quartile.Rank", dual_degree = "MD-MBA")
rankq_mdmsc <- quartile_calculator(comparison = "Quartile.Rank", dual_degree = "MD-MSc")
rank_quartile <- dplyr::bind_rows(list(rankq_mdphd, rankq_mdmph, rankq_mdmba, rankq_mdmsc))
rank_quartile$quartile_metric <- "Quartile Rank"
# Merging
quartile_df <- dplyr::bind_rows(list(cumulative_quartile, rank_quartile))
# Exporting to excel
#write_xlsx(x = quartile_df, path = "tables/quartiles.xlsx")
```
## 4.3 Honors and Experiences
```{r}
honors_function <- function(comparison, plot_title) {
# Cleaning the data for plotting
degree_list <- c("MD", "MD-PhD", "MD-MPH", "MD-MBA", "MD-MSc")
honors_df <- df_clean %>%
dplyr::filter(degrees %in% degree_list) %>%
dplyr::filter(!is.na(comparison))
# Plotting
p <- honors_df %>% dplyr::filter(degrees %in% degree_list) %>%
ggplot(aes(x = honors_df[[comparison]], fill = degrees)) +
geom_histogram(center = 0, binwidth = 1, color = "black") +
facet_wrap(~degrees, ncol = 5, scales = "free_y") +
scale_y_continuous(expand = c(0, 0)) +
labs(x = plot_title, y = "Counts", title = plot_title) +
theme_classic() +
theme(strip.background = element_blank(),
plot.title = element_text(hjust = 0.5))
print(p)
# Statistical testing with non-parametric kruskal and post hoc
kruskal_res <- kruskal.test(honors_df[[comparison]], honors_df$degrees)
pairwise_kruskal <- pairwise.wilcox.test(honors_df[[comparison]], honors_df$degrees, p.adjust.method = "fdr")
print(kruskal_res)
print(pairwise_kruskal)
ret_list <- list("plot" = p, "stats" = pairwise_kruskal)
return(ret_list)
}
```
```{r}
# Plotting and Stats for Number of Research Experiences
research_experiences <- honors_function(comparison = "X..Research.Experiences", plot_title = "Number of Reseach Experiences")
# Plotting and Stats for Number of Abstracts, Presentations, and Posters
abstracts_posters <- honors_function(comparison = "X..Abstracts..Pres..Posters", plot_title = "Number of Abstracts/Presentations/Posters")
# Plotting and Stats for Number of Peer reviewed publications
publications <- honors_function(comparison = "X..Peer.Rev.Publications", plot_title = "Number of Publications")
# Plotting and Stats for Number of Volunteer Experiences
volunteering <- honors_function(comparison = "X..Volunteer.Experiences", plot_title = "Number of Volunteering Experiences")
# Plotting and Stats for Number of Leadership experiences
leadership <- honors_function(comparison = "X..Leadership.Positions", plot_title = "Number of Leadership Positions")
# Plotting and Stats for Number of Honored Clerkships
honors_clerkships <- honors_function(comparison = "X..Honored.Clerkships", plot_title = "Number of Honors in Clerkships")
```
```{r}
# Exporting activities plots
#ggsave(plot = honors_clerkships$plot, filename = "figures/honors_clerkships.png", width = 4000, height = 1300, dpi = 300, units = "px")
#ggsave(plot = research_experiences$plot, filename = "figures/research_experiences.png", width = 4000, height = 1300, dpi = 300, units = "px")
#ggsave(plot = abstracts_posters$plot, filename = "figures/abstracts_posters.png", width = 4000, height = 1300, dpi = 300, units = "px")
#ggsave(plot = publications$plot, filename = "figures/publications_plot.png", width = 4000, height = 1300, dpi = 300, units = "px")
#ggsave(plot = volunteering$plot, filename = "figures/volunteering_plot.png", width = 4000, height = 1300, dpi = 300, units = "px")
#ggsave(plot = leadership$plot, filename = "figures/leadership_plot.png", width = 4000, height = 1300, dpi = 300, units = "px")
# Combining activity plots
combined_activities_plot <- research_experiences$plot / abstracts_posters$plot / publications$plot / volunteering$plot / leadership$plot / honors_clerkships$plot & plot_annotation(tag_levels = 'A')
#ggsave(plot = combined_activities_plot, filename = "figures/combined_activities_plot.pdf", width = 4000, height = 5500, dpi = 300, units = "px")
```
```{r}
# Function to extract stats and format the results of the pairwise wilcox test to a dataframe
stat_extracter <- function(activity_list, activity) {
df_stats <- activity_list$stats$p.value %>% as.data.frame()
df_stats <- df_stats %>% tibble::rownames_to_column(var = "degree")
df_stats$activity <- activity
return(df_stats)
}
# Exporting Stats
research_experiences_stats <- stat_extracter(activity_list = research_experiences, activity = "number of research experiences")
abstracts_posters_stats <- stat_extracter(activity_list = abstracts_posters, activity = "number of abstracts, presentations, and posters")
publications_stats <- stat_extracter(activity_list = publications, activity = "number of publications")
volunteering_stats <- stat_extracter(activity_list = volunteering, activity = "number of volunteering experiences")
leadership_stats <- stat_extracter(activity_list = leadership, activity = "number of leadership experiences")
honors_clerkships_stats <- stat_extracter(activity_list = honors_clerkships, activity = "number of honors clerkships")
# Merging and exporting to excel
activity_df <- dplyr::bind_rows(list(research_experiences_stats, abstracts_posters_stats, publications_stats, volunteering_stats, leadership_stats, honors_clerkships_stats))
#write_xlsx(x = activity_df, path = "tables/activities_stats.xlsx")
# FinalFit Table to excel - median or mean?
activities <- c("X..Research.Experiences", "X..Abstracts..Pres..Posters", "X..Peer.Rev.Publications", "X..Volunteer.Experiences", "X..Leadership.Positions", "X..Honored.Clerkships")
degree_list <- c("MD", "MD-PhD", "MD-MPH", "MD-MBA", "MD-MSc")
activity_list <- list()
for (act in activities) {
activities_table <- df_clean %>% dplyr::filter(degrees %in% degree_list) %>%
summary_factorlist(
dependent = "degrees", explanatory = c(act), cont = "mean", p = T,
add_col_totals = TRUE, include_col_totals_percent = TRUE
)
activities_table$activity <- act
activity_list[[act]] <- activities_table
}
# Merging and Exporting to excel
activity_table_df <- dplyr::bind_rows(activity_list)
#write_xlsx(x = activity_table_df, path = "tables/activities_finalfit_mean.xlsx")
```
```{r}
# Honors in specialty of choice and couples match (yes/no)
honors_spec <- df_clean %>% dplyr::filter(degrees %in% degree_list) %>%
summary_factorlist(
dependent = "degrees", explanatory = c("Honors.A.This.Specialty", "Couples.Match"),
p_cat = "chisq", p = T,
add_col_totals = TRUE, include_col_totals_percent = TRUE
)
# Stats - honors in specialty of choice
honors_list <- list()
dt <- df_clean %>% dplyr::filter(degrees %in% degree_list)
dt <- table(dt$degrees, dt$Honors.A.This.Specialty) %>% as.data.frame.matrix()
print(fisher.test(dt, simulate.p.value = T))
pairwise_fish <- pairwise_fisher_test(dt, p.adjust.method = "fdr", detailed = T)
pairwise_fish$activity <- "honors in specialty"
honors_list[["specialty_honors"]] = pairwise_fish
# Stats - couples match
dt <- df_clean %>% dplyr::filter(degrees %in% degree_list)
dt <- table(dt$degrees, dt$Couples.Match) %>% as.data.frame.matrix()
print(fisher.test(dt, simulate.p.value = T))
pairwise_fish <- pairwise_fisher_test(dt, p.adjust.method = "fdr", detailed = T)
pairwise_fish$activity <- "couples match"
honors_list[["couples_match"]] = pairwise_fish
honors_df <- dplyr::bind_rows(honors_list)
# Exporting dataframes to excel
#write_xlsx(x = honors_spec, path = "tables/specialty_honors_couples_match.xlsx")
#write_xlsx(x = honors_df, path = "tables/specialty_honors_couples_match_pairwise.xlsx")
```
## 4.4 Gap Years
```{r}
# Research Years by degree path
degree_list <- c("MD", "MD-PhD", "MD-MPH", "MD-MBA", "MD-MSc")
gap_years <- df_clean[df_clean == ""] <- NA
gap_years <- df_clean %>%
dplyr::filter(degrees %in% degree_list) %>%
dplyr::filter(!is.na(Research.Year))
gap_years <- table(gap_years$degrees, gap_years$Research.Year) %>% as.data.frame.matrix()
# Posthoc analysis
fisher.posthoc.research <- pairwise_fisher_test(gap_years, p.adjust.method = "fdr", detailed = T)
fisher.posthoc.research$gap_year <- "research year"
# Year of absence by degree path
degree_list <- c("MD", "MD-PhD", "MD-MPH", "MD-MBA", "MD-MSc")
gap_years <- df_clean[df_clean == ""] <- NA
gap_years <- df_clean %>%
dplyr::filter(degrees %in% degree_list) %>%
dplyr::filter(!is.na(Absence.Year))
gap_years <- table(gap_years$degrees, gap_years$Absence.Year) %>% as.data.frame.matrix()
# Posthoc analysis
fisher.posthoc.absence <- pairwise_fisher_test(gap_years, p.adjust.method = "fdr", detailed = T)
fisher.posthoc.absence$gap_year <- "year of absence"
# Merging
fisher.posthoc <- dplyr::bind_rows(fisher.posthoc.research, fisher.posthoc.absence)
fisher.posthoc$gap_year <- factor(fisher.posthoc$gap_year, levels = c("research year", "year of absence"))
# Finalfit table
gap_year_degree <- df_clean %>% dplyr::filter(degrees %in% degree_list) %>%
summary_factorlist(
dependent = "degrees", explanatory = c("Research.Year", "Absence.Year"),
p_cat = "chisq", p = T,
add_col_totals = TRUE, include_col_totals_percent = TRUE
)
# exports to excel
#write_xlsx(x = fisher.posthoc, path = "tables/gap_year_degree_stats.xlsx")
#write_xlsx(x = gap_year_degree, path = "tables/gap_year_degree.xlsx")
```
```{r}
# Research Years by specialty - plot this on a forest plot!
degree_list <- c("MD", "MD-PhD", "MD-MPH", "MD-MBA", "MD-MSc")
gap_years <- df_clean[df_clean == ""] <- NA
gap_years <- df_clean %>%
dplyr::filter(degrees %in% degree_list) %>%
dplyr::filter(!is.na(Research.Year))
gap_years <- table(gap_years$Specialty, gap_years$Research.Year) %>% as.data.frame.matrix()
gap_years <- gap_years[gap_years$No >= 5 & gap_years$Yes >= 5, ]
gap_years <- gap_years[ , c(2, 1)]
# Posthoc analysis
fisher.posthoc.research <- row_wise_fisher_test(gap_years, p.adjust.method = "fdr", detailed = T)
fisher.posthoc.research <- fisher.posthoc.research %>% dplyr::mutate(
likelihood = dplyr::case_when(
conf.low > 1 & p.adj < 0.05 ~ "Higher",
conf.high < 1 & p.adj < 0.05 ~ "Lower",
p.adj > 0.05 ~ "No Change"
)
)
fisher.posthoc.research$likelihood <- factor(x = fisher.posthoc.research$likelihood, levels = c("Higher", "No Change", "Lower"))
fisher.posthoc.research$gap_year <- "research year"
# Absence Years by specialty - plot this on a forest plot!
gap_years <- df_clean[df_clean == ""] <- NA
gap_years <- df_clean %>%
dplyr::filter(degrees %in% degree_list) %>%
dplyr::filter(!is.na(Absence.Year))
gap_years <- table(gap_years$Specialty, gap_years$Absence.Year) %>% as.data.frame.matrix()
gap_years <- gap_years[gap_years$No >= 5 & gap_years$Yes >= 5, ]
gap_years <- gap_years[ , c(2, 1)]
# Posthoc analysis
fisher.posthoc.absence <- row_wise_fisher_test(gap_years, p.adjust.method = "fdr", detailed = T)
fisher.posthoc.absence <- fisher.posthoc.absence %>% dplyr::mutate(
likelihood = dplyr::case_when(
conf.low > 1 & p.adj < 0.05 ~ "Higher",
conf.high < 1 & p.adj < 0.05 ~ "Lower",
p.adj > 0.05 ~ "No Change"
)
)
fisher.posthoc.absence$likelihood <- factor(x = fisher.posthoc.absence$likelihood, levels = c("Higher", "No Change", "Lower"))
fisher.posthoc.absence$gap_year <- "year of absence"
# Merging for forest plot
fisher.posthoc <- dplyr::bind_rows(fisher.posthoc.research, fisher.posthoc.absence)
fisher.posthoc$gap_year <- factor(fisher.posthoc$gap_year, levels = c("research year", "year of absence"))
# Finalfit table
gap_year_specialty <- df_clean %>% dplyr::filter(degrees %in% degree_list) %>%
summary_factorlist(
dependent = "Specialty", explanatory = c("Research.Year", "Absence.Year"),
p_cat = "chisq", p = F,
add_col_totals = TRUE, include_col_totals_percent = TRUE
)
# exports to excel
#write_xlsx(x = fisher.posthoc, path = "tables/gap_year_specialty_stats.xlsx")
#write_xlsx(x = gap_year_specialty, path = "tables/gap_year_specialty.xlsx")
```
```{r}
# Making a forest plot
forest_plot <- fisher.posthoc %>%
ggplot(aes(x = estimate, xmin = conf.low, xmax = conf.high, y = reorder(group, estimate), color = likelihood)) +
geom_point() +
geom_errorbarh(height = 0.2) +
geom_text(aes(label = p.adj, x = 8), hjust = 0, size = 3) +
geom_vline(aes(xintercept = 1), color = "black", linetype = "dashed") +
facet_wrap(~gap_year, ncol = 2) +
scale_x_continuous(n.breaks = 10, limits = c(0, 10)) + #2.8
scale_color_manual(values = c("#eb2323", "#525252", "#2e66ff")) +
labs(x = "Odds Ratio [95% CI]", y = "Specialty", title = "Odds of Taking a Research Year per Specialty", color = "Odds") +
theme_classic() +
theme(plot.title = element_text(hjust = 0.5, size = 14),
strip.background = element_blank(),
strip.text = element_text(size = 12))
print(forest_plot)
# Saving the plot
#ggsave(plot = forest_plot, filename = "figures/gap_years.png", width = 3500, height = 2500, dpi = 300, units = "px")
```
## 4.5 Honors Societies
```{r}
# aoa status
dual_degrees <- c("MD-PhD", "MD-MPH", "MD-MBA", "MD-MSc")
aoa_list <- list()
for (degree_path in dual_degrees) {
aoa <- df_clean %>% dplyr::filter(degrees %in% c("MD", degree_path))
aoa <- table(aoa$AOA.Sigma, aoa$degrees) %>% as.data.frame.matrix()
aoa <- aoa[ , c(2, 1)]
pairwise.fisher <- row_wise_fisher_test(aoa, p.adjust.method = "fdr", detailed = T)
pairwise.fisher$honors_society <- "AOA"
pairwise.fisher$dual_degree <- degree_path
aoa_list[[degree_path]] <- pairwise.fisher
}
aoa_df <- dplyr::bind_rows(aoa_list)
# gold humanism status
dual_degrees <- c("MD-PhD", "MD-MPH", "MD-MBA", "MD-MSc")
ghhs_list <- list()
for (degree_path in dual_degrees) {
ghhs <- df_clean %>% dplyr::filter(degrees %in% c("MD", degree_path))
ghhs <- table(ghhs$GHHS, ghhs$degrees) %>% as.data.frame.matrix()
ghhs <- ghhs[ , c(2, 1)]
pairwise.fisher <- row_wise_fisher_test(ghhs, p.adjust.method = "fdr", detailed = T)
pairwise.fisher$honors_society <- "Gold Humanism"
pairwise.fisher$dual_degree <- degree_path
ghhs_list[[degree_path]] <- pairwise.fisher
}
ghhs_df <- dplyr::bind_rows(ghhs_list)
# Merging
honors_df <- dplyr::bind_rows(list(aoa_df, ghhs_df))
# Finalfit table
honors_ff <- df_clean %>%
dplyr::filter(degrees %in% c("MD", "MD-PhD", "MD-MPH", "MD-MBA", "MD-MSc")) %>%
summary_factorlist(
dependent = "degrees", explanatory = c("AOA.Sigma", "GHHS"),
p = T, p_cat = "chisq",
add_col_totals = TRUE, include_col_totals_percent = TRUE
)
# Exporting to excel
#write_xlsx(x = honors_df, path = "tables/honors_societies_stats.xlsx")
#write_xlsx(x = honors_ff, path = "tables/honors_societies_table.xlsx")
```
# 5. Interview Outcomes
## 5.1 Interviews (unadjusted)
```{r}
# Interview info
cols_to_keep <- c("Applied_Total", "InterviewOffer_Total", "Majority.of.Interview.Offers", "Majority.of.Interviews.Attended", "X..Interviews.Attended", "Matched", "degrees")
overall_interview_df <- df_clean[, cols_to_keep] %>% dplyr::filter(degrees %in% c("MD", "MD-PhD", "MD-MPH", "MD-MBA", "MD-MSc"))
# Calculating percent interview offer over total applications
overall_interview_df$interview_percent <- (overall_interview_df$InterviewOffer_Total / overall_interview_df$Applied_Total) * 100
overall_interview_df$degrees <- factor(x = overall_interview_df$degrees, levels = c("MD", "MD-PhD", "MD-MPH", "MD-MBA", "MD-MSc"))
interview_success <- overall_interview_df %>% dplyr::group_by(degrees) %>%
dplyr::summarise(
median_interview_percent = median(interview_percent),
q5 = quantile(interview_percent, 0.05),
q25 = quantile(interview_percent, 0.25),
q75 = quantile(interview_percent, 0.75),
q95 = quantile(interview_percent, 0.95)
)
# Numerical Variables for interviews
interview_int_df <- tidyr::pivot_longer(data = overall_interview_df[, c(1, 2, 5, 7)], cols = c("Applied_Total", "InterviewOffer_Total", "X..Interviews.Attended"), names_to = "interview_metric", values_to = "values")