##Question: 4: Is there a difference in body weight (kg) between participants who lift weights versus participants who do not lift weights?

#Open packages
library(readxl)
library(ggpubr)
library(dplyr)
library(effectsize)
library(effsize)
library(rmarkdown)

#Import dataset
Q4 <- read_excel("C:/Users/Julia/OneDrive/Desktop/Assignment 6/Question 4/A6Q4-2.xlsx")

#Descriptive Statistics
Q4 %>%
  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
#Create histograms

hist(Q4$Weight[Q4$Exercise == "lift"],
     main = "Histogram of Lift Weight",
     xlab = "Value",
     ylab = "Frequency",
     col = "lightblue",
     border = "black",
     breaks = 10)

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

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

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


#Create Boxplot for Outliers
ggboxplot(Q4, x = "Exercise", y = "Weight",
          color = "Exercise",
          palette = "jco",
          add = "jitter")

#Interpretation
#The nolift boxplit is not normal.
#The nolift boxplot has dots outside the box. 
#There is one dot not close to the whiskers. 
#The dot is very far away from the whiskers. 
#The outliers are not balanced. 


#Interpretation
#The lift boxplot is not normal.
#The nolift boxplot has dots outside the box. 
#There is one dot not close to the whiskers. 
#The dot is very far away from the whiskers. 
#The outliers are not balanced. 
#Shapiro-Wilk Tests
shapiro.test(Q4$Weight[Q4$Exercise == "lift"])
## 
##  Shapiro-Wilk normality test
## 
## data:  Q4$Weight[Q4$Exercise == "lift"]
## W = 0.78786, p-value = 0.0001436
shapiro.test(Q4$Weight[Q4$Exercise == "nolift"])
## 
##  Shapiro-Wilk normality test
## 
## data:  Q4$Weight[Q4$Exercise == "nolift"]
## W = 0.70002, p-value = 7.294e-06

Shapiro-Wilk Interpretation: Lift is not normal (p < .001) Nolift is abnormal (p < .001)

#Mann-Whitney U Test
wilcox.test(Weight ~ Exercise, data = Q4)
## 
##  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
#Effect Size for Mann-Whitney U
mw_effect <- cliff.delta(Weight ~ Exercise, data = Q4)
print(mw_effect)
## 
## Cliff's Delta
## 
## delta estimate: 0.9296 (large)
## 95 percent confidence interval:
##     lower     upper 
## 0.7993841 0.9764036

Mann-Whitney U Interpretation: 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.