library(dplyr)
library(effectsize)
library(effsize)
library(readxl)
library(ggpubr)
library(ggplot2)
library(rstatix)
A6Q3_2 <- read_excel("C:/Users/rmich/Desktop/A6Q3-2.xlsx")
A6Q3_2 %>%
  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 cardio    74.7   73.3  7.57    25
## 2 nocardio  70.8   69.5  7.35    25
hist(A6Q3_2$Weight[A6Q3_2 == "cardio"],
     main = "Body Weight Distribution: Cardio",
     xlab = "Weight",
     ylab = "Count",
     col = "lightblue",
     border = "black",
     breaks = 10)

hist(A6Q3_2$Weight[A6Q3_2 == "nocardio"],
     main = "Body Weight Distribution: No Cardio",
     xlab = "Weight",
     ylab = "Count",
     col = "lightgreen",
     border = "black",
     breaks = 10)

#Group 1: Body Weight Distribution: Cardio #The first variable looks normally distributed. #The data is negatively skewed. #The data does have a proper bell curve.

#Group 2: Body Weight Distribution: No Cardio #The second variable looks normally distributed. #The data is negatively skewed. #The data does not have a proper bell curve.

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

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

#Boxplot 2: Cardio #There are no dots outside the boxplot. #The dots are close to the whiskers. #The dots are not very far away from the whiskers. #The outliers are balanced. #Based on these findings, the boxplot is normal.

shapiro.test(A6Q3_2$Weight[A6Q3_2$Exercise == "cardio"])
## 
##  Shapiro-Wilk normality test
## 
## data:  A6Q3_2$Weight[A6Q3_2$Exercise == "cardio"]
## W = 0.96745, p-value = 0.5812
shapiro.test(A6Q3_2$Weight[A6Q3_2$Exercise == "nocardio"])
## 
##  Shapiro-Wilk normality test
## 
## data:  A6Q3_2$Weight[A6Q3_2$Exercise == "nocardio"]
## W = 0.97686, p-value = 0.8166

#Group 1: No Cardio #The first group is normally distributed, (p = .817).

#Group 2: Cardio #The second group is normally distributed, (p = .581).

t.test(Weight ~ Exercise, data = A6Q3_2, var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  Weight by Exercise
## t = 1.8552, df = 48, p-value = 0.06971
## alternative hypothesis: true difference in means between group cardio and group nocardio is not equal to 0
## 95 percent confidence interval:
##  -0.3280454  8.1605622
## sample estimates:
##   mean in group cardio mean in group nocardio 
##               74.73336               70.81710
wilcox.test(Weight ~ Exercise, data = A6Q3_2)
## 
##  Wilcoxon rank sum exact test
## 
## data:  Weight by Exercise
## W = 399, p-value = 0.09541
## alternative hypothesis: true location shift is not equal to 0
cohens_d_result <- cohens_d(
  Weight ~ Exercise,
  data = A6Q3_2,
  var.equal = TRUE
)

print(cohens_d_result)
## # A tibble: 1 × 7
##   .y.    group1 group2   effsize    n1    n2 magnitude
## * <chr>  <chr>  <chr>      <dbl> <int> <int> <ord>    
## 1 Weight cardio nocardio   0.525    25    25 moderate

NOTE For PROFESSOR: NEEDED TO USE RSTATIX PACKAGE FOR R STUDIO VERSION

No Whitney Mann test needed, both Shapiro tests were greater than .05

An Independent T-Test was conducted to determine if there was a difference in Weight between those who exercise and those who did not exercise. Those who exercised weighed (M = 74.7, SD = 7.57) were significantly different from those who did not (M = 70.8, SD = 7.35), t(48) = 1.86, p = .070. The effect size was medium, Cohen’s d = .525.