Step 1: Open the installed packages
library(readxl)
library(ggpubr)
## Loading required package: ggplot2
#library(effectsize)
library(rstatix)
##
## Attaching package: 'rstatix'
## The following object is masked from 'package:stats':
##
## filter
Step 2: Import Data Set
Dataset6.4 <- read_excel("D:/SLU/APPLIED ANALYTICS/ASSIGNMENT 6/Dataset6.4.xlsx")
Step 3: Seperate the Data by Condition
Before <- Dataset6.4$Stress_Pre
After <- Dataset6.4$Stress_Post
Differences <- After - Before
Step 4: Calculating 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 5: Create a Histogram of the Difference Scores
hist(Differences,
main = "Histogram of Difference in Stress Levels",
xlab = "Stress",
ylab = "Frequency",
col = "lightblue",
border = "black",
breaks = 20)
The histogram appears negatively skewed and does not have a proper bell curve.
Step 6: Creating a Boxplot of the Difference Scores
boxplot(Differences,
main = "Distribution of Stress Level Differences (After - Before)",
ylab = "Difference in Stress Level",
col = "blue",
border = "darkblue")
There are two outliers in the boxplot. However, they are not very far away from the whisker.
Step 7: Shapiro-Wilk Test of Normality
shapiro.test(Differences)
##
## Shapiro-Wilk normality test
##
## data: Differences
## W = 0.87495, p-value = 0.0008963
p < .05 (0.0008963 less than .05), the data is NOT NORMAL. We may proceed with Wilcoxon Sign Rank
Step 8: Conducting 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
p<0.05, this means results are significant, effect size is calculated in the next step.
Step 9: Calculating (Rank Biserial Correlation for Mann-Whitney U) Effect Size
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
The effect size is 0.844 which is very large
Step 10: Reporting of Results
There was a significant difference in stress levels between Stress_Pre (Mdn = 47.24) and Stress_Post (Mdn = 40.84), V = 620, p < .001. The effect size was very large (r₍rb₎ = .84).
library(rmarkdown)