Nina Arh

Data and research questions

I chose a dataset that comprises survey results from 99 computer science students.

Source of data: Kaggle

(Url: https://www.kaggle.com/datasets/mdismielhossenabir/psychosocial-dimensions-of-student-life)

Research question 1: Are hours of sleep in a day and number of friends correlated?

Research question 2: Does taking notes in class vary depending on the gender?

#importing data
Students <- read_csv("~/Desktop/IMB/Multivariate /HW/CSE_student_performances.csv")
## Rows: 99 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────────────────────────────────────────────
## Delimiter: ","
## chr (7): Gender, AcademicPerformance, TakingNoteInClass, DepressionStatus, FaceChallangesToCompleteAcademicTask, Lik...
## dbl (3): Age, SleepPerDayHours, NumberOfFriend
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#only taking relevant variables
Students<- Students[, c(2, 3, 4, 5, 7, 8, 9, 10)]

#creating new variable ID
Students$ID <- 1:nrow(Students)
Students <- Students[, c("ID", names(Students)[-length(Students)])]

head(Students)
## # A tibble: 6 × 9
##      ID Gender AcademicPerformance TakingNoteInClass DepressionStatus LikePresentation SleepPerDayHours NumberOfFriend
##   <int> <chr>  <chr>               <chr>             <chr>            <chr>                       <dbl>          <dbl>
## 1     1 Male   Average             No                Sometimes        Yes                            12             NA
## 2     2 Male   Excellent           Sometimes         Yes              Yes                             8             80
## 3     3 Male   Average             No                Sometimes        No                              8             10
## 4     4 Female Good                Yes               Sometimes        No                              5             15
## 5     5 Female Average             Yes               Yes              Yes                             5              2
## 6     6 Male   Good                Sometimes         Sometimes        Yes                             8             12
## # ℹ 1 more variable: LikeNewThings <chr>

Unit of observation: one student

Sample size: 99

Number of variables: 9

Explanation of variables:

rows_with_missing_values <- which(is.na(Students$NumberOfFriend))
print(rows_with_missing_values)
## [1]  1 25 33 57
Students1 <- Students[complete.cases(Students$NumberOfFriend), ]
summary(Students1[c(7,8)])
##  SleepPerDayHours NumberOfFriend  
##  Min.   : 4.0     Min.   :  0.00  
##  1st Qu.: 5.0     1st Qu.:  3.00  
##  Median : 7.0     Median :  6.00  
##  Mean   : 6.6     Mean   : 16.19  
##  3rd Qu.: 8.0     3rd Qu.: 15.00  
##  Max.   :10.0     Max.   :100.00

On average people sleep 6.6 hours a day with the maximum being 10 hours and the minimum 4 hours.

People have on average 16.19 friends with 25% having only 3 friends or less and 75% having 15 friends or less.

50% of all people in the data sleep more than 7 hour and the other 50% more than 7 hours.

Correlation

Research question 1: Are hours of sleep in a day and number of friends correlated?

scatterplot(Students1$SleepPerDayHours, Students1$NumberOfFriend, 
     xlab = "SleepPerDayHours",
     ylab = "NumberOfFriends",
     boxplots = FALSE,
     smooth = FALSE)

shapiro.test(Students1$SleepPerDayHours)
## 
##  Shapiro-Wilk normality test
## 
## data:  Students1$SleepPerDayHours
## W = 0.89707, p-value = 1.749e-06

The hypothesis for Shapiro-Wilk test for SleepPerDayHours:

BSD we reject H0- normality for this group at p-value < 0.001.

shapiro.test(Students1$NumberOfFriend)
## 
##  Shapiro-Wilk normality test
## 
## data:  Students1$NumberOfFriend
## W = 0.59981, p-value = 1.061e-14

The hypothesis for Shapiro-Wilk test for NumberOfFriends:

BSD we reject H0- normality at p-value < 0.001.

Because we cannot say that variables are normally distributed, we need to use Spearman correlation coefficient.

cor(Students1$SleepPerDayHours, Students1$NumberOfFriend, 
      method = "spearman")
## [1] 0.2140937

There is a positive weak relationship between number of hours of sleep a day and number of friends.

cor.test(Students1$SleepPerDayHours, Students1$NumberOfFriend, 
      method = "spearman",
      exact = FALSE)
## 
##  Spearman's rank correlation rho
## 
## data:  Students1$SleepPerDayHours and Students1$NumberOfFriend
## S = 112290, p-value = 0.03722
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
##       rho 
## 0.2140937

The hypothesis for Spearman’s rank correlation test:

We reject the H0 at p-value = 0.04 and conduct that Rho differs from 0 at statistical significance.

Answer to RQ1: There is correlation between the number of hours of sleep in a day and number of friends (p=0.04). The correlation is positive weak.

Association

Research question 2: Does taking notes in class vary depending on the gender?

Pearson CHi2 test, assumptions:

  1. Data needs to come from two independent populations: the sample is independent because we divide students into two groups based on gender and each has either taken notes, taken notes sometimes, or not taken notes.

  2. All expected frequencies are greater than 5.

  3. In larger contingency tables (more than 2x2), up to 20% of expected frequencies can be between 1 and 5, but this will reduce the power of the test.

We can see in the table below, where expected frequencies are shown, that one of the values is under 5 (4.32 - Female, Does not take notes). Our table is 2x3 so the 3rd assumption applies. Since this still falls in the 20% of frequencies that can be between one and 5, we can still use the parametric test.

#variables into factors
Students1$Gender<- factor(Students1$Gender,
                              levels = c("Male", "Female"),
                              labels = c("Male", "Female"))

Students1$LikeNewThings<- factor(Students1$TakingNoteInClass,
                              levels = c("Yes", "No", "Sometimes"),
                              labels = c("Yes", "No","Sometimes"))
results <- chisq.test(Students1$Gender,Students1$TakingNoteInClass, 
                      correct = FALSE)
## Warning in chisq.test(Students1$Gender, Students1$TakingNoteInClass, correct = FALSE): Chi-squared approximation may be
## incorrect
results
## 
##  Pearson's Chi-squared test
## 
## data:  Students1$Gender and Students1$TakingNoteInClass
## X-squared = 24.964, df = 2, p-value = 3.795e-06

Hypothesis for Pearson Chi2 test:

BSD we can reject H0 at p<0.001 and conclude that there is association between gender and taking notes in class.

# table of observed frequencies
addmargins(results$observed)
##                 Students1$TakingNoteInClass
## Students1$Gender No Sometimes Yes Sum
##           Male   10        22  22  54
##           Female  0         4  37  41
##           Sum    10        26  59  95

Explanation of number 59,22 and 37: Out of 95 people in the data, 59 of them take notes in class, of which 37 are female and 22 are male.

# table of expected frequencies
addmargins(round(results$expected, 2))
##                 Students1$TakingNoteInClass
## Students1$Gender    No Sometimes   Yes Sum
##           Male    5.68     14.78 33.54  54
##           Female  4.32     11.22 25.46  41
##           Sum    10.00     26.00 59.00  95
round(results$res, 2)
##                 Students1$TakingNoteInClass
## Students1$Gender    No Sometimes   Yes
##           Male    1.81      1.88 -1.99
##           Female -2.08     -2.16  2.29

Discrepancy is significant for categories Female-No, Female-Sometimes, Female-Yes and Male-Yes, all at alpha = 5%.

Based on standardized residuals we can say that gender had an effect on taking notes in class (alpha=0.05).

addmargins(round(prop.table(results$observed), 3))
##                 Students1$TakingNoteInClass
## Students1$Gender    No Sometimes   Yes   Sum
##           Male   0.105     0.232 0.232 0.569
##           Female 0.000     0.042 0.389 0.431
##           Sum    0.105     0.274 0.621 1.000

0.274 = 26/95: We can way that 27,4% out of 95 students sometimes take notes in class.

0.042 = 4/95: We can say that 4,2% out of 95 students are females and sometimes take notes in class.

0.232 = 22/95: We can say that 23,2% out of 95 students are males and sometimes take notes in class

addmargins(round(prop.table(results$observed, 1), 3), 2) 
##                 Students1$TakingNoteInClass
## Students1$Gender    No Sometimes   Yes   Sum
##           Male   0.185     0.407 0.407 0.999
##           Female 0.000     0.098 0.902 1.000

0.098= 4/41

0.902= 37/41

We can say that out of all the students that are females, 90,2% of them take notes in class, 9,8% take notes sometimes and 0% of them do not take notes.

addmargins(round(prop.table(results$observed, 2), 3), 1) 
##                 Students1$TakingNoteInClass
## Students1$Gender    No Sometimes   Yes
##           Male   1.000     0.846 0.373
##           Female 0.000     0.154 0.627
##           Sum    1.000     1.000 1.000

1.0= 10/10

We can say that out of all students in the data who don’t take notes in class, 100% are male.

library(effectsize)
## 
## Attaching package: 'effectsize'
## The following object is masked from 'package:psych':
## 
##     phi
effectsize::cramers_v(Students1$Gender,Students1$TakingNoteInClass)
## Cramer's V (adj.) |       95% CI
## --------------------------------
## 0.49              | [0.30, 1.00]
## 
## - One-sided CIs: upper bound fixed at [1.00].
interpret_cramers_v(0.49)
## [1] "very large"
## (Rules: funder2019)

We can conclude that the effect size of association between the two categorical variables at alpha=5% is very large.