HOMEWORK 2

Ivana Milivojevic

correlation and association between categorical variables

RQ2: Are high school students who had extra-curricular activities are also more likely to take higher education?

mydata<-read.table("./student-mat.csv", header = TRUE, sep= "," , dec=";")
head (mydata[c("higher","activities")],)
##   higher activities
## 1    yes         no
## 2    yes         no
## 3    yes         no
## 4    yes        yes
## 5    yes         no
## 6    yes        yes

This set of data has 395 observations and 33 variables it was retrieved from a website: https://www.kaggle.com/datasets/uciml/student-alcohol-consumption?resource=download where is present under the name Student Alcohol Consumption

It was made based on the survey of students in math and portuguese language courses in secondary school. It contains social, gender and study information about students. In this specific example for the Research question we used only two variables that are relevant for our research:

variable 1: higher- yes, no

student wants to take higher education

variable 2: activities- yes, no

student had extra-curricular activities

UNIT OF OBSERVATION: high school student

mydata$ID <-seq_along(mydata$school)

mydata$activitiesF <- factor(mydata$activities,
                            levels = c("yes","no"),
                            labels = c("yes ECA", "no ECA"))
mydata$higherF <- factor(mydata$higher,
                        levels = c("yes","no"),
                        labels = c("yes HE", "no HE"))

head(mydata[c("ID","activitiesF","higherF")],)
##   ID activitiesF higherF
## 1  1      no ECA  yes HE
## 2  2      no ECA  yes HE
## 3  3      no ECA  yes HE
## 4  4     yes ECA  yes HE
## 5  5      no ECA  yes HE
## 6  6     yes ECA  yes HE
summary(mydata[,c("activitiesF","higherF")])
##   activitiesF    higherF   
##  yes ECA:201   yes HE:375  
##  no ECA :194   no HE : 20

Out of 395 students 201 had extra-curricular activities and the rest 194 did not. Out of 395 students only 20 students did not take higher education, the rest 375 students did.

For answering the research question, we need Chi-square test since we have two categorical variables. Regarding the assumptions, observations are independent since each student answered the questionnarie only once. For the second assumption we will show later that is not violated.

chi_square <-chisq.test(mydata$activitiesF,mydata$higherF,
                        correct = TRUE)
chi_square
## 
##  Pearson's Chi-squared test with Yates' continuity correction
## 
## data:  mydata$activitiesF and mydata$higherF
## X-squared = 2.8495, df = 1, p-value = 0.0914

Our hypothesis says:

H0: We do not have association between two categorical variables

H1: We have association between two categorical variables

My p value is 0.0914 which is higher than 5% hence we reject the null hypothesis.

addmargins(chi_square$observed)
##                   mydata$higherF
## mydata$activitiesF yes HE no HE Sum
##            yes ECA    195     6 201
##            no ECA     180    14 194
##            Sum        375    20 395
addmargins(round(chi_square$expected,2))
##                   mydata$higherF
## mydata$activitiesF yes HE no HE Sum
##            yes ECA 190.82 10.18 201
##            no ECA  184.18  9.82 194
##            Sum     375.00 20.00 395

Regarding expected values we can see that our assumption is not violated since all of them are above 5.

addmargins(round(prop.table(chi_square$observed), 3))
##                   mydata$higherF
## mydata$activitiesF yes HE no HE   Sum
##            yes ECA  0.494 0.015 0.509
##            no ECA   0.456 0.035 0.491
##            Sum      0.950 0.050 1.000

49.4% of all high school students had extra-curricular activities and wants to take higher education.

addmargins(round(prop.table(chi_square$observed ,1), 3), 2)
##                   mydata$higherF
## mydata$activitiesF yes HE no HE   Sum
##            yes ECA  0.970 0.030 1.000
##            no ECA   0.928 0.072 1.000

92.8% of high school students that did not have extra-curricular activities want to take higher education.

addmargins(round(prop.table(chi_square$observed, 2), 3), 1)
##                   mydata$higherF
## mydata$activitiesF yes HE no HE
##            yes ECA   0.52  0.30
##            no ECA    0.48  0.70
##            Sum       1.00  1.00

70% of of high school students that do not want to take higher education also did not have extra-curricular activities.

round(chi_square$residuals, 2)
##                   mydata$higherF
## mydata$activitiesF yes HE no HE
##            yes ECA   0.30 -1.31
##            no ECA   -0.31  1.33

Since the highest standard residual value is still lower than 1.96 (1.33<1.96) we can conclude that this deviation is statistically significant at alfa= 0,05 ; which is not statistically significant for further explanation.

#install.packages("effectsize")
library(effectsize)
effectsize::cramers_v(mydata$activitiesF, mydata$higherF)
## Cramer's V (adj.) |       95% CI
## --------------------------------
## 0.08              | [0.00, 1.00]
## 
## - One-sided CIs: upper bound fixed at [1.00].
interpret_cramers_v(0.08)
## [1] "very small"
## (Rules: funder2019)

Answer to the RQ2: We cannot claim statistically that there is any association between having or not having extra-curricular activities and wanting or not wanting to take higher education (p>0.05). Moreover the effect size is very small which points out that we cannot statistically claim that high school students who had extra-curricular activities are also more likely to take higher education.