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_3 <- read_excel("C:/Users/user/Downloads/Dataset6.3.xlsx")
Before <- Dataset6_3$Stress_Pre
After <- Dataset6_3$Stress_Post

Differences <- Before - After
#Descriptive Statistics for Each Group
mean(Before, na.rm = TRUE)
## [1] 65.86954
median(Before, na.rm = TRUE)
## [1] 67.33135
sd(Before, na.rm = TRUE)
## [1] 9.496524
mean(After, na.rm = TRUE)
## [1] 57.90782
median(After, na.rm = TRUE)
## [1] 59.14539
sd(After, na.rm = TRUE) 
## [1] 10.1712
#a Histogram of the Difference Scores
hist(Differences,
     main = "Histogram of stress difference",
     xlab = "Value",
     ylab = "Frequency",
     col = "blue",
     border = "black",
     breaks = 20)

#Create a Boxplot of the Difference Scores
boxplot(Differences,
        main = "Distribution of Score stress (After - Before)",
        ylab = "Difference in Scores",
        col = "blue",
        border = "darkblue")

shapiro.test(Differences)
## 
##  Shapiro-Wilk normality test
## 
## data:  Differences
## W = 0.95612, p-value = 0.1745
#output
#shapiro.test(Differences)

#Shapiro-Wilk normality test

#data:  Differences
#W = 0.95612, p-value = 0.1745
#If p < .05 , the data was NOT normal.

wilcox.test(Before, After, paired = TRUE)
## 
##  Wilcoxon signed rank exact test
## 
## data:  Before and After
## V = 518, p-value = 0.0005508
## alternative hypothesis: true location shift is not equal to 0
#Wilcoxon signed rank exact test

#data:  Before and After
#V = 518, p-value = 0.0005508
#alternative hypothesis: true location shift is not equal to 0
# the difference between the two groups was significant (p < .05)

cohens_d(Before, After, paired = TRUE)
## For paired samples, 'repeated_measures_d()' provides more options.
## Cohen's d |       95% CI
## ------------------------
## 0.66      | [0.29, 1.03]
# cohen 0.66