#Code to open the packages
library(readxl)
library(rcompanion)
library(ggplot2)
A4Q2 <- read_excel("C:/Users/onhau01/Desktop/R-Revision/A4Q2.xlsx")

#Create and View a Frequency Table
table(A4Q2$status, A4Q2$scholarship)
##                
##                   0   1
##   Domestic       39 111
##   International 118  32
students_table <- table(A4Q2$status, A4Q2$scholarship)
students_table 
##                
##                   0   1
##   Domestic       39 111
##   International 118  32
#Create a Bar Chart
barplot(students_table,
   beside = TRUE,
   col = rainbow(nrow(students_table)),
   legend = rownames(students_table),
   ylab = "Frequency")

#Pearson's Chi-squared test
chi_result <- chisq.test(students_table)

chi_result
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  students_table
## X-squared = 81.297, df = 1, p-value < 2.2e-16
#Calculating the Effect Size
rcompanion::cramerV(students_table)
## Cramer V 
##   0.5272
# A Chi-Square Test of Independence was conducted to determine if there was an association between student nationality (Domestic or International) and scholarship status.

# The results showed that there was an association between the two variables, χ²(1) = 81.30, p < .001.

# The association was large, (Cramer's V = .53).