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)

data <- read_excel("C:/Users/kvpra/Documents/spring 2026/rlaanguage/A6Q3-2.xlsx")

colnames(data) <- c("cardio", "bodyweight_kg")
data %>%
  group_by(cardio) %>%
  summarise(
    Mean = mean(bodyweight_kg, na.rm = TRUE),
    Median = median(bodyweight_kg, na.rm = TRUE),
    SD = sd(bodyweight_kg, na.rm = TRUE),
    N = n()
  )
## # A tibble: 2 × 5
##   cardio    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(data$bodyweight_kg[data$cardio == "cardio"],
     main = "Histogram of Cardio Weight",
     xlab = "Weight (kg)",
     ylab = "Frequency",
     col = "lightblue",
     border = "black",
     breaks = 10)

hist(data$bodyweight_kg[data$cardio == "nocardio"],
     main = "Histogram of No Cardio Weight",
     xlab = "Weight (kg)",
     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: No Cardio
#The second variable looks normally distributed.
#The data is symmetrical.
#The data has a proper bell curve.

ggboxplot(data, x = "cardio", y = "bodyweight_kg",
          color = "cardio",
          palette = "jco",
          add = "jitter")

#Boxplot 1: No Cardio
#There are no dots outside the boxplot.
#Based on these findings, the boxplot is normal.

#Boxplot 2: Cardio
#There are no dots outside the boxplot.
#Based on these findings, the boxplot is normal.

shapiro.test(data$bodyweight_kg[data$cardio == "cardio"])
## 
##  Shapiro-Wilk normality test
## 
## data:  data$bodyweight_kg[data$cardio == "cardio"]
## W = 0.96745, p-value = 0.5812
shapiro.test(data$bodyweight_kg[data$cardio == "nocardio"])
## 
##  Shapiro-Wilk normality test
## 
## data:  data$bodyweight_kg[data$cardio == "nocardio"]
## W = 0.97686, p-value = 0.8166
#Group 1: Cardio
#The first group is normally distributed, (p = .581).

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

# Final Normality Decision

# Cardio group:
# Histogram = normal
# Boxplot = normal
# Shapiro-Wilk = normal
# Final decision: The data is normally distributed.

# No Cardio group:
# Histogram = normal
# Boxplot = normal
# Shapiro-Wilk = normal
# Final decision: The data is normally distributed.

t.test(bodyweight_kg ~ cardio, data = data, var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  bodyweight_kg by cardio
## 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
# An Independent T-Test was conducted to determine if there was a difference in body weight between cardio and nocardio groups.
# Cardio scores (M = 74.73, SD = 7.83) were not significantly different from nocardio scores (M = 70.82, SD = 7.66), t(48) = 1.86, p > .05.
# Effect size was not calculated because the results were not statistically significant (p > .05).