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

DatasetZ <- read_excel("/Users/tulsiheerekar/Downloads/A6Q3-2.xlsx")
DatasetZ %>%
  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(DatasetZ$Weight[DatasetZ$Exercise == "cardio"],
     main = "Histogram of Cardio Exercise",
     xlab = "Value",
     ylab = "Frequency",
     col = "lightblue",
     border = "black",
     breaks = 10)

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

#Group 1: cardio
#The first variable looks normally distributed.
#The data is symmetrical.
#The data has a proper bell curve.


#Group 2: nocardio
#The second variable looks normally distributed.
#The data is symmetrical.
#The data has a proper bell curve.

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

#Boxplot 1: cardio
#There is one dot outside the boxplot.
#The dot is close to the whisker.
#Based on these findings, the boxplot is normal.



#Boxplot 2: nocardio
#There are dots outside the boxplot.
#The dots are not close to the whiskers.
#The dots are very far away from the whiskers.
#The outliers are not balanced.
#Based on these findings, the boxplot is not normal.
shapiro.test(DatasetZ$Weight[DatasetZ$Exercise == "cardio"])
## 
##  Shapiro-Wilk normality test
## 
## data:  DatasetZ$Weight[DatasetZ$Exercise == "cardio"]
## W = 0.96745, p-value = 0.5812
shapiro.test(DatasetZ$Weight[DatasetZ$Exercise == "nocardio"])
## 
##  Shapiro-Wilk normality test
## 
## data:  DatasetZ$Weight[DatasetZ$Exercise == "nocardio"]
## W = 0.97686, p-value = 0.8166
#Group 1: cardio
#The first group is abnormally distributed, (p =0.5812 ).

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

t.test(Weight ~ Exercise, data = DatasetZ, 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 = DatasetZ)
## 
##  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 = DatasetZ)
print(cohens_d_result)
## Cohen's d |        95% CI
## -------------------------
## 0.52      | [-0.04, 1.09]
## 
## - Estimated using pooled SD.
mw_effect <- cliff.delta(Weight ~ Exercise, data = DatasetZ)
print(mw_effect)
## 
## Cliff's Delta
## 
## delta estimate: 0.2768 (small)
## 95 percent confidence interval:
##       lower       upper 
## -0.05295739  0.55212525
#An Independent T-Test was conducted to determine if there was a difference in Weight between cardio and nocardio.
#cardio (M = 74.7, SD = 7.57) were significantly different from nocardio (M = 70.8, SD = 7.35), t(48) = 1.8552, p = 0.06971.
#The effect size was medium, Cohen's d = .5812.
#A Mann-Whitney U test was conducted to determine if there was a difference in Weight between cardio and nocardio.
#cardio (Mdn = 73.3) were significantly different from nocardio (Mdn = 69.5), U = 399, p = 0.06971.
#The effect size was medium, Cliff's Delta = 0.2768.