#open the packages
library(readxl)
library(rcompanion)
library(ggplot2)

#import dataset
A4Q2 <- read_excel("C:/Users/User/OneDrive - Saint Louis University/AA 5221/Assignment 4/A4Q2.xlsx")
View(A4Q2)
#create frequency table
table(A4Q2$status, A4Q2$scholarship)
##                
##                   0   1
##   Domestic       39 111
##   International 118  32
#name frequency table
Scholarship_Status <- table(A4Q2$status, A4Q2$scholarship)
Scholarship_Status
##                
##                   0   1
##   Domestic       39 111
##   International 118  32
#Create a bar chart
barplot(Scholarship_Status,
        beside = TRUE,
        col = rainbow(nrow(Scholarship_Status)),
        legend = rownames(Scholarship_Status))

#conduct the chi-square test
chi_result <- chisq.test(Scholarship_Status)
chi_result
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  Scholarship_Status
## X-squared = 81.297, df = 1, p-value < 2.2e-16
#Determine statistical significance
  #It is statistically significant

#calculate effect size
rcompanion::cramerV(Scholarship_Status)
## Cramer V 
##   0.5272
#Report the result
# A Chi-Square Test of Independence was conducted to determine if there was association between scholarship status and student nationality
# The results showed that there was an association between the scholarship status and nationality, χ²(df) = 81.30, p = < .001.
# The association was large, (Cramer's V = .53).