PUBLISHED LINK: https://rpubs.com/Haileab/1400208
# Step 1: Install the Required Packages (run once)
#install.packages("readxl")
#install.packages("ggpubr")
#install.packages("dplyr")
#install.packages("effectsize")
#install.packages("effsize")
# Step 2: Open the Installed Packages
library(readxl) # For reading Excel files
library(ggpubr) # For creating boxplots
## Loading required package: ggplot2
library(dplyr) # For data manipulation
##
## 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) # For Cohen's d (not used here but loaded)
library(effsize) # For Cliff's delta
# Step 3: Import and Name Dataset
Dataset6.2 <- read_excel("/Users/ha113ab/Desktop/datasets/Dataset6.2.xlsx")
# Step 4: Calculate Descriptive Statistics for Each Group
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
# Step 5: Create Histograms for Each Group
# Working students histogram
hist(Dataset6.2$Study_Hours[Dataset6.2$Work_Status == "Works"],
main = "Histogram of Study Hours - Working Students",
xlab = "Study Hours per Week",
ylab = "Frequency",
col = "green",
border = "black",
breaks = 10)
# Non-working students histogram
hist(Dataset6.2$Study_Hours[Dataset6.2$Work_Status == "Does_Not_Work"],
main = "Histogram of Study Hours - Non-Working Students",
xlab = "Study Hours per Week",
ylab = "Frequency",
col = "navyblue",
border = "black",
breaks = 10)
# Step 6: Create Boxplots for Each Group
ggboxplot(Dataset6.2, x = "Work_Status", y = "Study_Hours",
color = "Work_Status",
palette = "jco",
add = "jitter")
# Step 7: Shapiro-Wilk Test of Normality
# Working students
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
# p-value = 0.1305 (normal, p > .05)
# Non-working students
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
# p-value = 0.0003695 (NOT normal, p < .05)
# Step 8: Conduct Inferential Test (Mann-Whitney U Test)
# Since one group (Does_Not_Work) had p < .05 on Shapiro-Wilk, the data is NOT normal
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
# p-value = 0.07973 (NOT significant, p > .05)
# Step 9: Calculate Effect Size (Cliff's Delta)
# Cliff's delta is the appropriate effect size measure for Mann-Whitney U
cliff.delta(Study_Hours ~ Work_Status, data = Dataset6.2)
##
## Cliff's Delta
##
## delta estimate: 0.2644444 (small)
## 95 percent confidence interval:
## lower upper
## -0.03422594 0.51975307
# delta estimate: 0.2644444 (small)
# 95 percent confidence interval: lower = -0.03422594, upper = 0.51975307
# Step 10: Report the Results
# Descriptive statistics:
# Working students: Mean = 12.61, Median = 12.00, SD = 4.93, N = 18
# Non-working students: Mean = 15.10, Median = 15.00, SD = 4.47, N = 20
# Mann-Whitney U test: W = 228, p = 0.07973
# Effect size: Cliff's delta = 0.26 (small)
# Effect size interpretation guide for Cliff's delta:
# Small = 0.11 to 0.28
# Medium = 0.28 to 0.43
# Large = 0.43 to 1.00
# Final Report:
# Working students (Mdn = 12.00) were not significantly different from non-working students (Mdn = 15.00) in study hours per week, U = 228, p = .080. The effect size was small (Cliff's delta = 0.26).