library(readxl)
library(ggpubr)
## Loading required package: ggplot2
library(effectsize)
library(rstatix)
## 
## Attaching package: 'rstatix'
## The following objects are masked from 'package:effectsize':
## 
##     cohens_d, eta_squared
## The following object is masked from 'package:stats':
## 
##     filter
Dataset6.4 <- read_excel("C:/Users/Admin/Downloads/Dataset6.4.xlsx")

Before <- Dataset6.4$Stress_Pre
After <- Dataset6.4$Stress_Post
Differences <- After - Before

mean(Before, na.rm = TRUE)
## [1] 51.53601
median(Before, na.rm = TRUE)
## [1] 47.24008
sd(Before, na.rm = TRUE)
## [1] 17.21906
mean(After, na.rm = TRUE)
## [1] 41.4913
median(After, na.rm = TRUE)
## [1] 40.84836
sd(After, na.rm = TRUE)
## [1] 18.88901
hist(Differences,
     main = "Histogram of Difference Stress Level",
     xlab = "Value",
     ylab = "Frequency",
     col = "blue",
     border = "black",
     breaks = 20)

#For the difference Stress Level histogram, the data appears negatively skewed (left-skewed). The kurtosis appears abnormal (not a clean bell shape).

boxplot(Differences,
        main = "Distribution of Stress Level Differences (After - Before)",
        ylab = "Difference in Stress Level",
        col = "blue",
        border = "darkblue")

#There are 2 dots outside of the boxplot. However, one of them is quite far away from the whiskers, so the data is not normal. The Wilcoxon-Sign Rank test is recommended.

shapiro.test(Differences)
## 
##  Shapiro-Wilk normality test
## 
## data:  Differences
## W = 0.87495, p-value = 0.0008963
#The p-value was below .05, which means we should proceed with the Wilcoxon Sign Rank.

wilcox.test(Before, After, paired = TRUE)
## 
##  Wilcoxon signed rank exact test
## 
## data:  Before and After
## V = 620, p-value = 2.503e-09
## alternative hypothesis: true location shift is not equal to 0
effectsize:: cohens_d(Before, After, paired = TRUE)
## For paired samples, 'repeated_measures_d()' provides more options.
## Cohen's d |       95% CI
## ------------------------
## 1.05      | [0.63, 1.46]
#There was a significant difference in the dependent variable between Pre-program Group (M = 51.54, SD = 17.22) and Post-program Group (M =  = 41.49, SD = 18.89), V = 620, p < .001. The effect size was very large (Cohen’s d = 1.05.