library(readxl)
library(ggpubr)
## Loading required package: ggplot2
library(rmarkdown)
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)

A6Q4 <- read_excel("A6Q4-2.xlsx")
#CORRECTION: I corrected the file path so the dataset imports properly.

unique(A6Q4$Exercise)
## [1] "nolift" "lift"
A6Q4 %>%
  group_by(Exercise) %>%
  summarise(
    Mean = mean(Weight, na.rm = TRUE),
    Median = median(Weight, na.rm = TRUE),
    SD = sd(Weight, na.rm = TRUE),
    N = n()
  )
## # A tibble: 2 × 5
##   Exercise  Mean Median    SD     N
##   <chr>    <dbl>  <dbl> <dbl> <int>
## 1 lift     120.   116.   53.3    25
## 2 nolift    33.0   40.8  56.7    25
hist(
  A6Q4$Weight[A6Q4$Exercise == "lift"],
  main = "Histogram of Lift Weight",
  xlab = "Value",
  ylab = "Frequency",
  col = "lightblue",
  border = "black",
  breaks = 10
)

#CORRECTION: I corrected the lift histogram title, x-axis label, color and number of breaks.
#Lift Group Interpretation
#The data is abnormally distributed.
#The data is positively skewed.
#The data does not have a proper bell curve.


hist(
  A6Q4$Weight[A6Q4$Exercise == "nolift"],
  main = "Histogram of NoLift Weight",
  xlab = "Value",
  ylab = "Frequency",
  col = "lightgreen",
  border = "black",
  breaks = 10
)

#CORRECTION: I corrected the no lift histogram title, x-axis label, color, and number of breaks.

#NoLift Group Interpretation
#The data is abnormally distributed.
#The data is negatively skewed.
#The data does not have a proper bell curve.

ggboxplot(A6Q4, x = "Exercise", y = "Weight",
          color = "Exercise",
          palette = "jco",
          add = "jitter")

#CORRECTION: I corrected the boxplot code to display the exercise groups with jittered points.

#Boxplot 1: Lift Group
#There are dots outside the boxplot.
#The dots are not close to the whiskers.
#The dots are very far from the whiskers.
#The outliers are not balanced.
#Based on these findings, the boxplot is not normal.

#Boxplot 2: No Lift Group
#There is one dot outside the boxplot.
#The dot is not very close to the whisker.
#The dot is very far from the whisker.
#The outliers are not balanced.
#Based on these findings, the boxplot is not normal.

shapiro.test(A6Q4$Weight[A6Q4$Exercise == "lift"])
## 
##  Shapiro-Wilk normality test
## 
## data:  A6Q4$Weight[A6Q4$Exercise == "lift"]
## W = 0.78786, p-value = 0.0001436
shapiro.test(A6Q4$Weight[A6Q4$Exercise == "nolift"])
## 
##  Shapiro-Wilk normality test
## 
## data:  A6Q4$Weight[A6Q4$Exercise == "nolift"]
## W = 0.70002, p-value = 7.294e-06
#Shapiro-Wilk Test: Lift Group
#The lift group is not normally distributed (p < .001).
#Overall Normality
#The lift group is not normally distributed.

#Shapiro-Wilk Test: No Lift Group
#The no lift group is not normally distributed (p < .001).
#Overall Normality
#The no lift group is not normally distributed.

#CORRECTION: I updated the Shapiro-Wilk interpretations to include the exact rounded p-values.
wilcox.test(Weight ~ Exercise, data = A6Q4)
## 
##  Wilcoxon rank sum exact test
## 
## data:  Weight by Exercise
## W = 603, p-value = 7.132e-11
## alternative hypothesis: true location shift is not equal to 0
mw_effect <- cliff.delta(Weight ~ Exercise, data = A6Q4)

print(mw_effect)
## 
## Cliff's Delta
## 
## delta estimate: 0.9296 (large)
## 95 percent confidence interval:
##     lower     upper 
## 0.7993841 0.9764036
#A Mann-Whitney U test was conducted to determine if there was a difference in body weight (kg) between the participants that lift weights versus the participants that do not lift weights.
#The body weight for participants that lift weights (Mdn = 116.00) were significantly different from the body weight of participants that do not lift weights (Mdn = 40.80), U = 603, p < .001.
#The effect size was large, Cliff's Delta = .93.
#CORRECTION: I corrected the No Lift median and wording in my final report.