library(readxl)
library(ggpubr)
## Loading required package: ggplot2
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(effectsize)
library(effsize)

Dataset6.2 <- read_excel("C:/Users/JT/Downloads/Dataset6.2.xlsx")

Dataset6.2 %>%
  group_by(Work_Status) %>%
  summarise(
    Mean = mean(Study_Hours, na.rm = TRUE),
    Median = median(Study_Hours, na.rm = TRUE),
    SD = sd(Study_Hours, na.rm = TRUE),
    N = n()
  )
## # A tibble: 2 × 5
##   Work_Status    Mean Median    SD     N
##   <chr>         <dbl>  <dbl> <dbl> <int>
## 1 Does_Not_Work  9.62   8.54  7.45    30
## 2 Works          6.41   5.64  4.41    30
hist(Dataset6.2$Study_Hours[Dataset6.2$Work_Status == "Works"],
     main = "Histogram of Study_Hours:Working Students",
     xlab = "Study_Hours",
     ylab = "Frequency",
     col = "lightblue",
     border = "black",
     breaks = 10)

hist(Dataset6.2$Study_Hours[Dataset6.2$Work_Status == "Does_Not_Work"],
     main = "Histogram of Study_Hours:Non Working Students",
     xlab = "Study_Hours",
     ylab = "Frequency",
     col = "lightgreen",
     border = "black",
     breaks = 10)

#For the Working Students histogram, the data appears positively skewed.It is difficult to state the exact kurtosis, but it appears abnormal.
#For the Non Working Students histogram, the data appears positively skewed. The kurtosis also appears abnormal.
#We do not need to use a Mann-Whitney U test.

ggboxplot(Dataset6.2, x = "Work_Status", y = "Study_Hours",
          color = "Work_Status",
          palette = "jco",
          add = "jitter")

#The working Students boxplot appears normal. There are dots past the whiskers.
#The non working students boxplot appears abnormal. There are several dots past the whiskers. Although some are very close to the whiskers, some are arguably far away.

shapiro.test(Dataset6.2$Study_Hours[Dataset6.2$Work_Status == "Works"])
## 
##  Shapiro-Wilk normality test
## 
## data:  Dataset6.2$Study_Hours[Dataset6.2$Work_Status == "Works"]
## W = 0.94582, p-value = 0.1305
shapiro.test(Dataset6.2$Study_Hours[Dataset6.2$Work_Status == "Does_Not_Work"])
## 
##  Shapiro-Wilk normality test
## 
## data:  Dataset6.2$Study_Hours[Dataset6.2$Work_Status == "Does_Not_Work"]
## W = 0.83909, p-value = 0.0003695
#The data for Works was normal (p > .05).
#+The data for Does Not Work was abnormal (p < .05).

wilcox.test(Study_Hours ~ Work_Status, data = Dataset6.2)
## 
##  Wilcoxon rank sum exact test
## 
## data:  Study_Hours by Work_Status
## W = 569, p-value = 0.07973
## alternative hypothesis: true location shift is not equal to 0
#With this Test p > .05, (greater than .05), this means the results were not SIGNIFICANT.

#Non Working Students (M = 9.62, SD = 7.45) was not significantly different from Working Students (M = 6.41, SD = 4.41), t(58) = 2.0306, p = .04688. The effect size was medium (Cohen's d = .52).
#Non Working students ((Mdn = 8.54) was not significantly different from working students (Mdn = 5.64), U = 569, p = 0.07973.
#There is no statistically  difference in hours studying for working students and non working.