Step 2: Load the required packages

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

Step 3 : import and name dataset

dataset6.4 <- read_excel("/Users/sarva/Desktop/Dataset6.4.xlsx") 

Step 4 : seperate the data by condition

Before <- dataset6.4$Stress_Pre
After <- dataset6.4$Stress_Post

differences <- After - Before

Segregating the data between two groups, stress pre labelled as before and stress post labelled as after .

Step 5 : Calculate descriptive statistics for each group

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

Step 6: Creating a histogram of the difference score

hist(differences,
     main = "Histogram of Difference Scores",
     xlab = "Value",
     ylab = "Frequency",
     col = "yellow",
     border = "black",
     breaks = 20)

# Group difference, Skewness = Negatively skewed, Kurtosis = Mesokurtic

Step 7 : Box plot of the difference score

boxplot(differences,
        main = "Distribution of Score Differences (After - Before)",
        ylab = "Difference in Scores",
        col = "yellow",
        border = "black")

# The boxplot appears to be normal with no extreme outliers in the diagram

Step 8 : Shapiro-Wilk test of normality

shapiro.test(differences)
## 
##  Shapiro-Wilk normality test
## 
## data:  differences
## W = 0.87495, p-value = 0.0008963

after conducting the shapiro wilk test of normality we obtain the p-value of 0.000089,

Step 10 : 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

Step 11 : Calculating the effect size

cohens_d <- effectsize::cohens_d(Before, After, paired = TRUE)
## For paired samples, 'repeated_measures_d()' provides more options.
print(cohens_d)
## Cohen's d |       95% CI
## ------------------------
## 1.05      | [0.63, 1.46]

Step 12 :

df_long <- data.frame(
  id = rep(1:length(Before), 2),
  time = rep(c("Before", "After"), each = length(Before)),
  score = c(Before, After)
)

wilcox_effsize(df_long, score ~ time, paired = TRUE)
## # A tibble: 1 × 7
##   .y.   group1 group2 effsize    n1    n2 magnitude
## * <chr> <chr>  <chr>    <dbl> <int> <int> <ord>    
## 1 score After  Before   0.844    35    35 large

after computing the effect size we obtain the effectsize to be 1.05 indicating a large difference in the between the two samples