-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUofRStudentApplicant.Rmd
922 lines (654 loc) · 37.6 KB
/
UofRStudentApplicant.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
---
title: "Study Of Applicants Applying for Masters and PhD programs at UofR"
author: "Anik De, Babli Dey, Sharon Gilbert, Veronica Mata"
date: "2023-12-14"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
<!-- importing student application data from the csv file "application_data_2015_2022.csv" -->
```{r importing student dataset, echo=FALSE}
applicantData<-read.csv("application_data_2015_2022.csv")
```
<!-- importing all the library here -->
```{r import require library, echo=FALSE, message=FALSE}
library(ggplot2)
library(dplyr)
library(caTools)
library(tidyr)
```
## Visualizations of EDA (will include unknown data) - Masters v/s PhD:
1.What is the annual total no. of applicants, which term recorded the highest and lowest number of applicants?
```{r no.Of applicants, echo=FALSE}
noOfApp <- applicantData %>%
group_by(Entry.Term, Degree) %>%
summarise(no_of_application = n(), .groups = 'drop')
ggplot(data = noOfApp, aes(x = Entry.Term, y = no_of_application, group = Degree, color = Degree)) +
geom_line() +
geom_point() +
xlab("Term") + ylab("Number of Applicants") +
ggtitle("U of R Student Application - Number of Applicants by Program (2015 - 2022)") +
theme(plot.title = element_text(size = 12, hjust = 0.5)) +
scale_color_brewer(palette = "Set1")
```
```{r applicants by sub-program, echo=FALSE}
masters<-subset(applicantData,Degree=="Master's")
noOfAppM <- masters %>%
group_by(Entry.Term, Program..ASE.) %>%
summarise(no_of_application = n(), .groups = 'drop')
ggplot(data = noOfAppM, aes(x = Entry.Term, y = no_of_application, group = Program..ASE., color = Program..ASE.)) +
geom_line() +
geom_point() +
xlab("Term") + ylab("Number of Applicants") +
labs(color = "Program") +
ggtitle("U of R Student Application - Number of Master's Sub-Program Applicants by Program (2015 - 2022)") +
theme(plot.title = element_text(size = 8, hjust = 0.5), axis.text.x = element_text(angle = 30, hjust = 1))
```
```{r no.Of Applicants by Phd program, echo=FALSE}
phd<-subset(applicantData,Degree=="PhD")
#no.Of Applicants by Phd program
noOfAppP<-phd %>% group_by(Entry.Term,Program..ASE.) %>%
summarise(no_of_application = n(),
.groups='drop')
#plotting
ggplot(data=noOfAppP, aes(x=Entry.Term, y = no_of_application, group = Program..ASE., color = Program..ASE.)) +
geom_line() +
geom_point()+
xlab("Term Year") + ylab("No.Of Applicants") +
labs(title = "U of R Student Application - Total No.of PhD Sub Program Applicants Every Fall Term By Program (2015 - 2022)",color = "Program") +
theme(plot.title = element_text(size = 8, hjust = 0.5), axis.text.x = element_text(angle = 30, hjust = 1))
```
2.Identify the top 10 undergraduate institutes from which applicants are applying.
```{r masters top 10 undergrad institutes, echo=FALSE}
mTopIns <- masters %>% group_by(Institution.1.Name) %>% summarize(applicants=n(),
.groups = 'drop') %>%
arrange(desc(applicants)) %>%
slice_head(n = 10)
ggplot(mTopIns, aes(x = reorder(Institution.1.Name, -applicants), y = applicants)) +
geom_col(fill = "steelblue") +
labs(title = "U of R Student Application - Top 10 Institution of Master Applicants (2015 - 2022)",
x = "Institution",
y = "Number of Applicants") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
plot.title = element_text(size = 10))
```
```{r phd top 10 undergrad institutes, echo=FALSE}
pTopIns <- phd %>% group_by(Institution.1.Name) %>% summarize(applicants=n(),
.groups = 'drop') %>%
arrange(desc(applicants)) %>%
slice_head(n = 10)
ggplot(pTopIns, aes(x = reorder(Institution.1.Name, -applicants), y = applicants)) +
geom_col(fill = "skyblue") +
labs(title = "U of R Student Application - Top 10 Institution of PhD Applicants (2015 - 2022)",
x = "Institution",
y = "Number of Applicants") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 60, hjust = 1),
plot.title = element_text(size = 10))
```
3.How do the numbers of applicants vary by gender across different terms?
```{r masters applicants by gender, echo=FALSE}
# Grouping Term and Gender
mByGender <- masters %>%
group_by(Degree, Entry.Term, Sex) %>%
summarise(applicants = n(), .groups = 'drop')
# Create a grouped bar chart for No. Of Applicants for Master's by Gender and Term
ggplot(mByGender, aes(x = Entry.Term, y = applicants, fill = Sex)) +
geom_bar(stat = "identity", position = "dodge") +
labs(title = "U of R Student Application - No. Of Applicants for Master's by Gender and Term (2015 - 2022)",
x = "Term (Years)",
y = "Number of Applicants",
fill = "Gender") +
theme_minimal() +
theme(plot.title = element_text(size = 10))
```
```{r phd applicants by gender, echo=FALSE}
pByGender<- phd %>% group_by(Degree,Entry.Term,Sex) %>%
summarise(applicants = n(),
.groups='drop')
# Create a grouped bar chat for No. Of Applicants for PhD by Gender and Term
ggplot(pByGender, aes(x = Entry.Term, y = applicants, fill = Sex)) +
geom_bar(stat = "identity", position = "dodge") +
labs(title = "U of R Student Application - No. Of Applicants for PhD by Gender and Term (2015 - 2022)",
x = "Term (Years)",
y = "Number of Applicants",
fill = "Gender") +
theme_minimal() +
theme(plot.title = element_text(size = 10))
```
4.What are the top 10 countries from which applicants have applied to the university?
```{r masters top country of applicants, echo=FALSE}
# Master Applicants
appCountryM <- masters %>%
group_by(Citizenship, Entry.Term) %>%
summarise(Count = n(), .groups = "drop") %>%
arrange(desc(Count)) %>%
top_n(50, wt = Count)
# Create a stacked bar plot
ggplot(appCountryM, beside=TRUE, aes(x = reorder(Citizenship, Count), y = Count, fill = Entry.Term)) +
geom_bar(stat = "identity", position = "stack", width = 0.9) +
# Improve the appearance
theme_minimal() +
labs(title = "U of R Student Application - No. Of Master's Applicants based on Citizenship By Term (2015 - 2022)",
x = "Citizenship Status",
y = "No. Of Applicants") +
coord_flip() +
# Adjust text size and angle
theme(axis.text.y = element_text(size = 10, angle = 45),
plot.title = element_text(size = 10, hjust = 0.5), # Center the title
legend.title = element_text(size = 10),
legend.text = element_text(size = 8))
```
```{r phdtop country of applicants, echo = FALSE}
#PhD Applicants
appCountryP <- phd %>%
group_by(Citizenship, Entry.Term) %>%
summarise(Count = n(), .groups = "drop") %>%
arrange(desc(Count)) %>%
top_n(50, wt = Count)
# Create a stacked bar plot
ggplot(appCountryM, beside = TRUE, aes(x = reorder(Citizenship, Count), y = Count, fill = Entry.Term)) +
geom_bar(stat = "identity", position = "stack", width = 0.9) +
theme_minimal() +
labs(title = "U of R Student Application - No. Of PhD Applicants based on Citizenship By Term (2015 - 2022)",
x = "Citizenship Status",
y = "No. Of Applicants") +
coord_flip() +
# Adjust text size and angle
theme(axis.text.y = element_text(size = 10, angle = 45),
plot.title = element_text(size = 10, hjust = 0.5), # Center the title
legend.title = element_text(size = 10),
legend.text = element_text(size = 7.5))
```
5.Determine the total number of applicants who were placed on probation.
```{r masters applicants placed on probation, echo=FALSE}
#Masters students
mProb <- subset(masters,Ever.Placed.on.Academic.Probation==1 | Ever.Placed.on.Academic.Probation==0)
mProb$probationStatus = ifelse(mProb$Ever.Placed.on.Academic.Probation==1,"probation","not on probation")
nProbM<-mProb %>% group_by(Entry.Term,probationStatus) %>%
summarise(applicant= n(),
.groups='drop')
#no.Of Applicants by Masters program
ggplot(nProbM, aes(x=Entry.Term, y = applicant, color = probationStatus, group = probationStatus)) +
geom_line() +
geom_point()+
labs(color = "Ever Placed on Probation",x="Term Year",y="No.Of Applicants",fill="Probation Status") +
ggtitle("U of R Student Application - Total No.of Masters Applicants By Probation Status and Term (2015 - 2022)") +
theme(plot.title = element_text(size = 8), axis.text.x = element_text(angle = 30, hjust = 1))
```
```{r phd applicants placed on probation, echo=FALSE}
#PhD students
pProb <- subset(phd,Ever.Placed.on.Academic.Probation==1 | Ever.Placed.on.Academic.Probation==0)
pProb$probationStatus = ifelse(pProb$Ever.Placed.on.Academic.Probation==1,"probation","not on probation")
nProbP<-pProb %>% group_by(Entry.Term,probationStatus) %>%
summarise(applicant= n(),
.groups='drop')
#no.Of Applicants by PhD program
ggplot(nProbP, aes(x=Entry.Term, y = applicant, color = probationStatus, group = probationStatus)) +
geom_line() +
geom_point()+
labs(color = "Ever Placed on Probation",x="Term Year",y="No.Of Applicants",fill="Probation Status") +
ggtitle("U of R Student Application - Total No.of PhD Applicants By Probation Status and Term (2015 - 2022)") +
theme(plot.title = element_text(size = 8), axis.text.x = element_text(angle = 30, hjust = 1))
```
6.Determine the total number of applicants who failed a course.
```{r masters applicants failed a course, echo=FALSE}
#Masters students
mCourse <- subset(masters,Have.you.ever.failed.a.course.==1 | Have.you.ever.failed.a.course.==0)
mCourse$courseStatus = ifelse(mCourse$Have.you.ever.failed.a.course.==1,"failed","not failed")
nCourseM<-mCourse %>% group_by(Entry.Term,courseStatus) %>%
summarise(applicant= n(),
.groups='drop')
#no.Of Applicants by Masters program
ggplot(nCourseM, aes(x=Entry.Term, y = applicant, color = courseStatus, group = courseStatus)) +
geom_line() +
geom_point()+
labs(color = "Ever failed a Test",x="Term Year",y="No.Of Applicants",fill="Course Status") +
ggtitle("U of R Student Application - Total No.of Masters Applicants By Failed A course Status and Term (2015 - 2022)") +
theme(plot.title = element_text(size = 8))
```
```{r phd applicants failed a course, echo=FALSE}
#PhD students
pCourse <- subset(phd,Have.you.ever.failed.a.course.==1 | Have.you.ever.failed.a.course.==0)
pCourse$courseStatus = ifelse(pCourse$Have.you.ever.failed.a.course.==1,"failed","not failed")
nCourseP<-pCourse %>% group_by(Entry.Term,courseStatus) %>%
summarise(applicant= n(),
.groups='drop')
#no.Of Applicants by PhD program
ggplot(nCourseP, aes(x=Entry.Term, y = applicant, color = courseStatus, group = courseStatus)) +
geom_line() +
geom_point()+
labs(color = "Ever failed a Test",x="Term Year",y="No.Of Applicants",fill="Course Status") +
ggtitle("U of R Student Application - Total No.of PhD Applicants By Failed A course Status and Term (2015 - 2022)") +
theme(plot.title = element_text(size = 8))
```
## Data Cleaning: (code in rmd file)
1.Apply a filter to the dataset based on the 24 specified dimensions.
```{r filter dimensions, echo=FALSE}
#Column to Remove
column_to_remove <- c("Any.Relatives.Listed.","Spouse.Studying.Applying","Current.Student.","Type","Citizenship2","Institution.3.Degree","Institution.3.Major","Institution.3.Location","Institution.3.Level.of.Study","Institution.3.Name","Job.3.Title","Institution.2.Degree","Institution.2.Major","Institution.2.Location","Institution.2.Level.of.Study","Institution.2.Name","Job.2.Title","Job.1.Title","Sub.Category","Previously.Applied.","How.Applicant.Heard...Other")
applicantData <- applicantData[, !colnames(applicantData) %in% column_to_remove]
column_names <- colnames(applicantData)
#print(column_names)
```
2.Change column names to lowercase and use underscores or simpler terms for better interpretability.
```{r change the column names, echo=FALSE}
# Renaming column names
# Define new column names
new_column_names <- c(
"reference", "program", "degree", "entry_term",
"time_status", "decision", "sex", "birth_country",
"age", "native_language", "citizenship_status",
"citizenship", "failed_course", "academic_probation",
"inst_1_name", "inst_1_location",
"inst_1_study_level", "inst_1_degree",
"inst_1_major", "currently_employed",
"heard_about_UR", "other_schools_applying"
)
# Rename specified columns
colnames(applicantData)[colnames(applicantData) %in% c(
"Ref", "Program..ASE.", "Degree", "Entry.Term",
"Time.Status", "Decision.1", "Sex", "Birth.Country",
"Age.at.App.Submission", "Native.Language", "Citizenship",
"Citizenship1", "Have.you.ever.failed.a.course.",
"Ever.Placed.on.Academic.Probation", "Institution.1.Name",
"Institution.1.Location", "Institution.1.Level.of.Study",
"Institution.1.Degree", "Institution.1.Major",
"Currently.Employed.", "How.Applicant.Heard.About.UR",
"Other.Schools.Applying.To"
)] <- new_column_names
#handling recommender 1,2,3 columns
applicantData <- applicantData %>%
mutate(num_two_recs = (Recommender.1.Relationship != "" & Recommender.2.Relationship != "") +
(Recommender.1.Relationship != "" & Recommender.3.Relationship != "") +
(Recommender.2.Relationship != "" & Recommender.3.Relationship != ""),
num_three_recs = (Recommender.1.Relationship != "" & Recommender.2.Relationship != "" & Recommender.3.Relationship != ""))
#dropping recommender 1,2,3 columns
column_to_remove <- c("Recommender.1.Relationship","Recommender.2.Relationship","Recommender.3.Relationship")
applicantData <- applicantData[, !colnames(applicantData) %in% column_to_remove]
# Updated column names
#print(colnames(applicantData))
# printing the number of missing values present in each column
#print("Count of missing values by column")
empty_or_na_counts <- sapply(applicantData, function(x) sum(x == "" | is.na(x)))
sorted_counts <- sort(empty_or_na_counts, decreasing = TRUE)
#print(sorted_counts)
#applicantData
```
3.Segment the dataset into two parts: one for master's programs and another for Ph.D. programs.
```{r segment dataset into masters and phd program, echo=FALSE}
# Create a DataFrame for applicants with a phd degree
phd_data <- subset(applicantData, degree == 'PhD')
# Save the master's dataset to a CSV file
#write.csv(phd_data, file = 'phd_data.csv', row.names = FALSE)
# Create a DataFrame for applicants with a master's degree
masters_data <- subset(applicantData, degree == "Master's")
# Save the master's dataset to a CSV file
#write.csv(masters_data, file = 'masters_data.csv', row.names = FALSE)
```
4.For empty values, categorize them as "Unknown" for categorical data. For age, fill in with the average age corresponding to the respective program.
```{r deal with null values, echo=FALSE}
#mean age in masters
mean_age <- mean(masters_data$age , na.rm = TRUE)
masters_mean_age <- round(mean_age)
#cat("The masters mean age is:", masters_mean_age, "\n")
#mean age in phd
mean_age <- mean(phd_data$age , na.rm = TRUE)
phd_mean_age <- round(mean_age)
#cat("The phd mean age is:", phd_mean_age, "\n")
#Replacing missing age values with the rounded value in the masters_data
masters_data$age <- ifelse(is.na(masters_data$age), masters_mean_age, masters_data$age)
#Replacing missing age values with the rounded value in the phd_data
phd_data$age <- ifelse(is.na(phd_data$age), phd_mean_age, phd_data$age)
# Fill missing values in 'sex' column in masters_data with the mode
masters_data$sex[is.na(masters_data$sex) | masters_data$sex == ""] <- "unknown"
# Fill missing values in 'sex' column in phd_data with the mode
phd_data$sex[is.na(phd_data$sex) | phd_data$sex == ""] <- "unknown"
# Fill missing values in 'academic_probation' column in masters_data with the mode
masters_data$academic_probation[is.na(masters_data$academic_probation) | masters_data$academic_probation == ""] <- "unknown"
# Fill missing values in 'academic_probation' column in phd_data with the mode
phd_data$academic_probation[is.na(phd_data$academic_probation) | phd_data$academic_probation == ""] <- "unknown"
# Fill missing values in 'failed_course' column in masters_data with the mode
masters_data$failed_course [is.na(masters_data$failed_course ) | masters_data$failed_course == ""] <- "unknown"
# Fill missing values in 'failed_course' column in phd_data with the mode
phd_data$failed_course [is.na(phd_data$failed_course ) | phd_data$failed_course == ""] <- "unknown"
##HANDLING OTHER CATEGORICAL FEATURES
# Columns to replace missing values with 'unknown'
columns_to_replace <- c('time_status', 'decision', 'inst_1_name', 'inst_1_location', 'inst_1_study_level', 'inst_1_degree', 'inst_1_major')
# Replace missing values with 'unknown' in masters_data
masters_data[, columns_to_replace] <- lapply(masters_data[, columns_to_replace], function(x) ifelse(is.na(x) | x == "", "unknown", x))
# Replace missing values with 'unknown' in phd_data
phd_data[, columns_to_replace] <- lapply(phd_data[, columns_to_replace], function(x) ifelse(is.na(x) | x == "", "unknown", x))
# Replace missing values with 'unknown sources' in masters_data
masters_data$heard_about_UR <- ifelse(is.na(masters_data$heard_about_UR) | masters_data$heard_about_UR == "", "unknown", masters_data$heard_about_UR)
# Replace missing values with 'unknown sources' in phd_data
phd_data$heard_about_UR <- ifelse(is.na(phd_data$heard_about_UR) | phd_data$heard_about_UR == "", "unknown", phd_data$heard_about_UR)
# Columns to replace missing values with 'not mentioned'
columns_to_replace <- c('birth_country', 'other_schools_applying','native_language','citizenship_status','citizenship')
# Replace missing values with 'not mentioned' in masters_data
masters_data[, columns_to_replace] <- lapply(masters_data[, columns_to_replace], function(x) ifelse(is.na(x) | x == "", "unknown", x))
# Replace missing values with 'not mentioned' in phd_data
phd_data[, columns_to_replace] <- lapply(phd_data[, columns_to_replace], function(x) ifelse(is.na(x) | x == "", "unknown", x))
# Find unique values in the 'Num_Two_Recs' column
unique_values_Num_Two_Recs <- unique(masters_data$num_two_recs)
# Find unique values in the 'Num_Three_Recs' column
unique_values_Num_Three_Recs <- unique(masters_data$num_three_recs)
# Identify and replace missing values
missing_indices_Num_Two_Recs <- which(is.na(masters_data$num_two_recs))
missing_indices_Num_Three_Recs <- which(is.na(masters_data$num_three_recs))
# Replace missing values with any unique value from the respective columns
if (length(missing_indices_Num_Two_Recs) > 0) {
masters_data$num_two_recs[missing_indices_Num_Two_Recs] <- unique_values_Num_Two_Recs[1]
}
if (length(missing_indices_Num_Three_Recs) > 0) {
masters_data$num_three_recs[missing_indices_Num_Three_Recs] <- unique_values_Num_Three_Recs[1]
}
# Creating a column called accept_reject for masters and phd dataset
masters_data$decision_status<-ifelse(masters_data$decision=="Deny","deny",
ifelse(masters_data$decision=="unknown","unknown",
ifelse(masters_data$decision=="Withdraw","withdraw","accept")))
phd_data$decision_status<-ifelse(phd_data$decision=="Deny","deny",
ifelse(phd_data$decision=="unknown","unknown",
ifelse(phd_data$decision=="Withdraw","withdraw","accept")))
```
## Descriptive Analysis: Master's and PhD
1.Calculate the mean, variance, and standard deviation of age, and visualize the distribution using histograms and box plots.
```{r descriptive analysis of age Masters - mean variance and standard deviation, echo=FALSE,warning=FALSE}
# mean , var, sd of age in masters dataset
mastMeanAge<- mean(masters_data$age)
mastVarAge<- var(masters_data$age)
mastSdAge<-sd(masters_data$age)
cat("The Mean age of Masters applicant is:", mastMeanAge)
cat("\nThe Variance in age of Masters applicant is:", mastVarAge)
cat("\nThe Standard Deviation in age of Masters applicant is:",mastSdAge)
```
```{r descriptive analysis of age Masters - histogram of age, echo=FALSE,warning=FALSE}
bin <-ceiling((log2(length(masters_data$age))) + 1)
ggplot(data = masters_data, aes(x=age)) + geom_histogram(
bins = bin) + labs(x = 'age', y = 'frequency', title = "U of R Student Application - Histogram of Master's Applicant Age (2015 - 2022)" ) +
geom_vline(xintercept = mean(masters_data$age),col = "red") +
geom_vline(xintercept = median(masters_data$age), col = "blue") +
annotate("text",x = 30, y = 8000 , label = substitute(paste(tilde(x), "=",m),list(m=sprintf("%.02f",median(masters_data$age)))),color = "blue") +
annotate("text",x = 30, y = 7000, label = substitute(paste(bar(x),"=",m),list(m=sprintf("%.02f", mean(masters_data$age)))),color = "red") + theme(plot.title = element_text(size = 10))
```
```{r descriptive analysis of age Masters - box plot of age, echo=FALSE,warning=FALSE}
ggplot(masters_data, aes(y = age,x =entry_term))+geom_boxplot(outlier.size = 1.5 )+labs(title = "U of R Student Application - Box Plot of Master's Applicant Age By Term (2015 - 2022)", x = "Term By Year", y = "Age")+theme(plot.title = element_text(size = 10))
```
```{r descriptive analysis of age PhDs - mean variance and standard deviation, echo=FALSE}
# mean , var, sd of age in phd dataset
phdMeanAge<- mean(phd_data$age)
phdVarAge<- var(phd_data$age)
phdSdAge<-sd(phd_data$age)
cat("The Mean age of PhD applicant is:", phdMeanAge)
cat("\nThe Variance in age of PhD applicant is:",phdVarAge)
cat("\nThe Standard Deviation in age of PhD applicant is:",phdSdAge)
```
```{r descriptive analysis of age PhDs - histogram of age, echo=FALSE,warning=FALSE}
bin <-ceiling((log2(length(phd_data$age))) + 1)
ggplot(data = phd_data, aes(x=age)) + geom_histogram(
bins = bin) + labs(x = 'age', y = 'frequency', title = "U of R Student Application - Histogram of PhD Applicant's Age (2015 - 2022)" ) +
geom_vline(xintercept = mean(phd_data$age),col = "red") +
geom_vline(xintercept = median(phd_data$age), col = "blue") +
annotate("text",x = 30, y = 8000 , label = substitute(paste(tilde(x), "=",m),list(m=sprintf("%.02f",median(phd_data$age)))),color = "blue") +
annotate("text",x = 30, y = 7000, label = substitute(paste(bar(x),"=",m),list(m=sprintf("%.02f", mean(phd_data$age)))),color = "red") + theme(plot.title = element_text(size = 10))
```
```{r descriptive analysis of age PhDs - box plot of age, echo=FALSE,warning=FALSE}
ggplot(phd_data, aes(y = age,x=entry_term))+geom_boxplot(outlier.size = 1.5 )+labs(title = "U of R Student Application - Box Plot of PhD's Applicant Age By Term (2015 -2022)", x = "Term By Year", y = "Age")+theme(plot.title = element_text(size = 10))
```
2.Examine the acceptance rate based on gender across different terms.
```{r master acceptance rate by gender, echo=FALSE,warning=FALSE}
#masters data
m_contingency_table <- table(masters_data$sex, masters_data$entry_term, masters_data$decision_status)
m_proportions_by_gender <- prop.table(m_contingency_table, margin = 1)
m_proportions_df <- as.data.frame(as.table(m_proportions_by_gender))
m_merged_proportions <- m_proportions_df %>%
filter(Var3 == "accept", Var1 %in% c("M", "F")) %>%
arrange(Var1)
ggplot(m_merged_proportions, aes(x = Var2, y = Freq , fill=Var1)) +
geom_col(position = "fill")+ labs(title="U of R Student Application - Master's Acceptance Rate Based On Gender Across Terms (2015 - 2022)", x = "Term Year", y = "Proportion", fill="Gender") + theme(plot.title = element_text(size=8))
#print(m_merged_proportions)
```
```{r phd acceptance rate by gender, echo=FALSE,warning=FALSE }
#Phd data
p_contingency_table <- table(phd_data$sex, phd_data$entry_term, phd_data$decision_status)
p_proportions_by_gender <- prop.table(p_contingency_table, margin = 1)
p_proportions_df <- as.data.frame(as.table(p_proportions_by_gender))
p_merged_proportions <- p_proportions_df %>%
filter(Var3 == "accept", Var1 %in% c("M", "F")) %>%
arrange(Var1)
#print(p_merged_proportions)
ggplot(p_merged_proportions, aes(x = Var2, y = Freq , fill=Var1)) +
geom_col(position = "fill")+ labs(title="U of R Student Application - PhD Acceptance Rate Based On Gender Across Terms (2015 - 2022)", x = "Term Year", y = "Proportion", fill="Gender") + theme(plot.title = element_text(size=8))
```
3.Explore the acceptance rate by country in relation to different terms.
```{r acceptance rate by country, echo=FALSE,warning=FALSE}
#masters data
m_citizen_contingency_table <- table(masters_data$citizenship_status, masters_data$entry_term, masters_data$decision_status)
m_proportions_by_citizen <- prop.table(m_citizen_contingency_table, margin = 1)
m_citizen_proportions_df <- as.data.frame(as.table(m_proportions_by_citizen))
m_merged_citizen <- m_citizen_proportions_df %>%
filter(Var3 == "accept", Var1 %in% c("FN", "US", "PR", "unknown")) %>%
arrange(Var1)
#print(m_merged_citizen)
ggplot(m_merged_citizen, aes(x = Var2, y = Freq , fill=Var1)) +
geom_col(position = "fill")+ labs(title="U of R Student Application - Master's Acceptance Rate Based On Citizenship (2015 - 2022)", x = "Term Year", y = "Proportion", fill="Citizenship Status") + theme(plot.title = element_text(size=9))
#Phd data
p_citizen_contingency_table <- table(phd_data$citizenship_status, phd_data$entry_term, phd_data$decision_status)
p_proportions_by_citizen <- prop.table(p_citizen_contingency_table, margin = 1)
p_citizen_proportions_df <- as.data.frame(as.table(p_proportions_by_citizen))
p_merged_citizen <- p_citizen_proportions_df %>%
filter(Var3 == "accept") %>%
filter(Var1 %in% c("FN", "US", "PR", "unknown")) %>%
arrange(Var1)
#print(p_merged_citizen)
ggplot(p_merged_citizen, aes(x = Var2, y = Freq , fill=Var1)) +
geom_col(position = "fill")+ labs(title="U of R Student Application - PhD Acceptance Rate Based On Citizenship (2015 - 2022)", x = "Term Year", y = "Proportion", fill="Citizenship Status") + theme(plot.title = element_text(size=9))
```
4.Investigate the acceptance decision for applicants who were placed on probation.
```{r masters acceptance rate of probation applicants, echo=FALSE,warning=FALSE}
mProbAccept<- masters_data %>% filter(academic_probation==1)
mProAccG<- mProbAccept %>% group_by(decision_status,entry_term) %>% summarise(count=n(), .groups = 'drop')
ggplot(mProAccG, aes(x=entry_term , y=count,fill=decision_status)) +
geom_col() +
labs(title = "U of R Student Application - Acceptance Decision of Master's Applicants On Academic Probation (2015 -2022)", x = "Term Year", y = "No. Of Applicants", fill="Decision Status") + theme(plot.title = element_text(size=8))
```
```{r phd acceptance rate of probation applicants, echo=FALSE,warning=FALSE}
pProbAccept<- phd_data %>% filter(academic_probation==1)
pProAccG<- pProbAccept %>% group_by(decision_status,entry_term) %>% summarise(count=n(), .groups = 'drop')
ggplot(pProAccG, aes(x=entry_term , y=count,fill=decision_status)) +
geom_col() +
labs(title = "U of R Student Application - Acceptance Decision of PhD's Applicants On Academic Probation (2015 -2022)", x = "Term Year", y = "No. Of Applicants", fill="Decision Status") + theme(plot.title = element_text(size=8))
```
5.Investigate the acceptance decision for applicants who failed a course.
```{r masters acceptance rate applicants who failed a course, echo=FALSE,warning=FALSE}
mFailedc<- masters_data %>% filter(failed_course==1)
mFailedcTable <- mFailedc %>% group_by(decision_status,entry_term) %>% summarise(applicants=n(), .groups='drop')
ggplot(mFailedcTable, aes(x=entry_term , y=applicants, fill=decision_status)) +
geom_col() +
labs(title = "U of R Student Application - Acceptance Decision of Master's Applicants who failed a course (2015 - 2022)", x = "Term Year", y = "No. Of Applicants", fill="Decision Status") + theme(plot.title = element_text(size=8))
```
```{r phd acceptance rate applicants who failed a course, echo=FALSE,warning=FALSE}
pFailedc<- phd_data %>% filter(failed_course==1)
pFailedcTable <- pFailedc %>% group_by(decision_status,entry_term) %>% summarise(applicants=n(), .groups='drop')
ggplot(pFailedcTable, aes(x=entry_term , y=applicants, fill=decision_status)) +
geom_col() +
labs(title = "U of R Student Application - Acceptance Decision of Master's Applicants who failed a course (2015 -2022)", x = "Term Year", y = "No. Of Applicants", fill="Decision Status") + theme(plot.title = element_text(size=8))
```
6.Investigate the age distribution between applicants who failed a course v/s applicants who did not fail a course.
```{r age distribution failed vs not failed a course, echo=FALSE,warning=FALSE}
# Function to see distributions
create_filtered_histogram <- function(data, plot_column, filter_column, filter_value, binwidth = 0.5, fill_color = "pink", text) {
# Filter the data based on the filter_column and filter_value
filtered_data <- data %>% filter(!!sym(filter_column) == filter_value)
# Create the histogram using the filtered data
ggplot(filtered_data, aes_string(x = plot_column)) +
geom_histogram(binwidth = binwidth, fill = fill_color, color = "black") +
theme_minimal() +
labs(title = text,
x = plot_column,
y = "Frequency") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))+
theme(plot.title = element_text(size = 8))
}
# To help respond 3rd sub question of th primary question
create_filtered_histogram(masters_data, "age", "failed_course", 0, 0.5, "green","U of R Student Application - Distribution of age of Master's Applicants Never Failed a Course (2015 - 2022)")
create_filtered_histogram(masters_data, "age", "failed_course", 1, 0.5, "yellow","U of R Student Application - Distribution of age of Master's Applicants Failed a Course (2015 - 2022)")
ggplot(applicantData, aes(x = degree, y = age)) +
geom_boxplot() +
theme_minimal() +
labs(title = "U of R Student Application - Age Distribution by Degree (2015 - 2022)",
x = "Degree",
y = "Age at Application Submission") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
```
_______________________________________
## Inferential Analysis:
1.Is there a notable distinction in age variance between applicants who have experienced course failure and those who haven't, considering each degree type?
$$
\begin{aligned}
H_0&:\text{There is no difference in the variance of ages between Master's applicants who have experienced course failure}\\
&\text{and those who haven't. (i.e., the variances are equal)} \\
H_A&:\text{There is a significant difference in the variance of ages between Master's applicants}\\
&\text{who have experienced course failure and those who haven't.}
\end{aligned}
$$
```{r age variance hypothesis test, echo=FALSE,warning=FALSE}
# For Master's applicants
masters_failed <- masters_data$age[masters_data$failed_course == 1]
masters_not_failed <- masters_data$age[masters_data$failed_course == 0]
length(masters_failed)
length(masters_not_failed)
# Variance test for Master's applicants
var.test(masters_failed, masters_not_failed)
# For Ph.D. applicants
phd_failed <- phd_data$age[phd_data$failed_course == 1]
phd_not_failed <- phd_data$age[phd_data$failed_course == 0]
# Variance test for Ph.D. applicants
var.test(phd_failed, phd_not_failed)
```
\begin{equation}
\begin{split}
\text{Conclusion}: &\text{ Given that the p-value is much less than the significance level } \\
&(\alpha = 0.05), \text{ we reject the null hypothesis. This suggests that} \\
&\text{there is a statistically significant difference in the variance of the} \\
&\text{ages between Master’s applicants who have experienced course} \\
&\text{failure and those who haven’t.}
\end{split}
\end{equation}
_______________________________________
2. Is there a discernible difference in the average age between master's and Ph.D. students?
$$
\begin{aligned}
H_0&:\text{The average age of Master's students is equal to the average age of Ph.D. students. (no difference in means)}\\
H_A&:\text{The average age of Master's students is not equal to the average age of Ph.D. students.}\\
\end{aligned}
$$
```{r age variance hypothesis test by program, echo=FALSE,warning=FALSE}
# T-test to compare average age
t.test(masters_data$age, phd_data$age)
```
\begin{equation}
\begin{split}
Conclusion&: \text{The extremely small p-value (p < 2.2e-16) is much lower than our alpha level of significance } \\
&(\alpha = 0.05) \text{indicating that the difference in average ages between Master's and Ph.D. students} \\
&\text{is statistically significant. Therefore, we reject the null hypothesis, H0, which stated that we don’t} \\
&\text{have enough evidence to conclude that the average of Master’s students is equal} \\
&\text{ to the average of PhD students.}
\end{split}
\end{equation}
_______________________________________
3. Compare the acceptance rate for students who learned about the university through family/friends versus those who found it through an internet search.
$$
\begin{aligned}
H_0&:\text{Applicants who learnt about U of R through Family/Friend or}\\&\text{Internet Search is independent of Acceptance status }\\
H_A&:\text{Applicants who learnt about U of R through Family/Friend or}\\&\text{ Internet Search and Acceptance status are associated }\\
\end{aligned}
$$
```{r hypothesis test based on how they hear about U of R, echo=FALSE,warning=FALSE}
#masters data
family_friend<- subset(masters_data, heard_about_UR=="Family/Friend")
n_accept_frnd_fam<-length(family_friend$heard_about_UR[family_friend$decision_status=="accept"])
n_not_accept_frnd_fam<-length(family_friend$heard_about_UR[family_friend$decision_status=="deny"])
internet_search<- subset(masters_data, heard_about_UR=="Internet search")
n_accept_internet<-length(internet_search$heard_about_UR[internet_search$decision_status=="accept"])
n_not_internet<-length(internet_search$heard_about_UR[internet_search$decision_status=="deny"])
chiMaster<-matrix(c(n_accept_frnd_fam,n_not_accept_frnd_fam, n_accept_internet, n_not_internet), nrow = 2, byrow = TRUE)
colnames(chiMaster) <- c("Accepted", "NotAccepted")
rownames(chiMaster) <- c("FamilyFriends", "InternetSearch")
print(chiMaster)
result <- chisq.test(chiMaster, correct = F)
print(result)
#phd data
family_friend_p<- subset(phd_data, heard_about_UR=="Family/Friend")
n_accept_frnd_fam_p<-length(family_friend_p$heard_about_UR[family_friend_p$decision_status=="accept"])
n_not_accept_frnd_fam_p<-length(family_friend_p$heard_about_UR[family_friend_p$decision_status=="deny"])
internet_search_p<- subset(phd_data, heard_about_UR=="Internet search")
n_accept_internet_p<-length(internet_search_p$heard_about_UR[internet_search_p$decision_status=="accept"])
n_not_internet_p<-length(internet_search_p$heard_about_UR[internet_search_p$decision_status=="deny"])
chiPhd<-matrix(c(n_accept_frnd_fam_p,n_not_accept_frnd_fam_p, n_accept_internet_p, n_not_internet_p), nrow = 2, byrow = TRUE)
colnames(chiPhd) <- c("Accepted", "NotAccepted")
rownames(chiPhd) <- c("FamilyFriends", "InternetSearch")
print(chiPhd)
result <- chisq.test(chiPhd, correct = F)
print(result)
```
\begin{equation}
\begin{aligned}
&\alpha = 0.05 \\
\text{Master Conclusion}: &\text{ Since the p-value is less than the significance level, we reject the null hypothesis} \\
&\text{and suggest that there is an association between how students learned about the university} \\
&\text{and the acceptance rate for the Master’s Program.} \\
\\
\text{PhD Conclusion}: &\text{ Since the p-value is greater than the significance level, we accept the null hypothesis} \\
&\text{and conclude that there is no association between how students learned about the university} \\
&\text{and the acceptance rate for the PhD program.}
\end{aligned}
\end{equation}
_______________________________________
## Logistic Regression:
1. Can we use factors such as age, citizenship, gender, recommender relationships, current employment status, and program choice to predict the likelihood of a candidate being accepted?
```{r merge data, echo=FALSE,warning=FALSE}
rows_to_keep_masters <- nrow(masters_data)
rows_to_keep_phd <- nrow(phd_data)
# Randomly sample rows from df1
reduced_masters <- sample_n(masters_data, size = rows_to_keep_masters)
reduced_phd <- sample_n(phd_data, size = rows_to_keep_phd )
# Merge the reduced df1 with df2
merged_data_masters_phd <- rbind(reduced_masters, reduced_phd)
```
```{r logistic regression - preparing data, echo=FALSE}
merged_data_masters_phd <- na.omit(merged_data_masters_phd)
categorical_vars <- c("program", "degree", "entry_term", "time_status",
"sex","citizenship_status","failed_course",
"academic_probation",
"inst_1_degree","heard_about_UR")
#print(categorical_vars)
categorical_vars <- categorical_vars[categorical_vars %in% colnames(merged_data_masters_phd)]
print(categorical_vars)
merged_data_masters_phd[categorical_vars] <- lapply(merged_data_masters_phd[categorical_vars], factor)
```
```{r logistic regression - model building, echo=FALSE}
modelTrainingfeatures <- select(merged_data_masters_phd, program, degree, entry_term, time_status,
sex, citizenship_status, inst_1_degree, heard_about_UR,
age, failed_course, academic_probation, decision_status)
modelTrainingfeatures$decision_status <- ifelse(merged_data_masters_phd$decision_status == "accept", 1, 0)
#Splitting the dataset into 70% Training and 30% Testing
set.seed(123) # for reproducible results
split <- sample.split(modelTrainingfeatures$decision_status, SplitRatio = 0.7)
train <- subset(modelTrainingfeatures, split == TRUE)
test <- subset(modelTrainingfeatures, split == FALSE)
```
```{r logistic regression - prediction and accuracy, echo=FALSE}
model <- glm(decision_status ~ ., data = train, family = "binomial")
print(summary(model))
predictions <- predict(model, newdata = test, type = "response")
predicted_classes <- ifelse(predictions > 0.50, 1, 0)
# Confusion matrix for the test set
conf_matrix <- table(Predicted = predicted_classes, Actual = test$decision_status)
print(conf_matrix)
# Calculate accuracy on the test set
accuracy <- sum(diag(conf_matrix)) / sum(conf_matrix)
print(paste("Accuracy:", accuracy))
```