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)
library(readxl)
library(ggpubr)
## Loading required package: ggplot2
A6Q3 <- read_excel("C:/Users/nehab/OneDrive/A5221/Assignment--6/A6Q3.xlsx")
# Descriptive statistics for each cardio group
A6Q3 %>%
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
# I corrected the descriptive-statistics code.
# I combined the mean, median, standard deviation, and sample size
# into one summary table and added na.rm = TRUE.
# Examine the no-cardio distribution
hist(
A6Q3$Weight[A6Q3$Exercise == "nocardio"],
breaks = 15,
col = "skyblue",
border = "white",
main = "Weight Distribution: No Cardio",
xlab = "Body Weight"
)
# Examine the cardio distribution
hist(
A6Q3$Weight[A6Q3$Exercise == "cardio"],
breaks = 15,
col = "firebrick",
border = "white",
main = "Weight Distribution: Cardio",
xlab = "Body Weight"
)
# Data for the no-cardio group appears normally distributed.
# Data for the cardio group appears normally distributed.
# I added separate histograms for both groups as shown in the answer key.
# Create the boxplot
ggboxplot(
A6Q3,
x = "Exercise",
y = "Weight",
color = "Exercise",
palette = "jco",
add = "jitter"
)
# The no-cardio boxplot does not have outliers.
# The cardio boxplot does not have outliers.
# I replaced the original basic boxplot with the answer-key boxplot.
# Test normality separately for both groups
shapiro.test(
A6Q3$Weight[A6Q3$Exercise == "nocardio"]
)
##
## Shapiro-Wilk normality test
##
## data: A6Q3$Weight[A6Q3$Exercise == "nocardio"]
## W = 0.97686, p-value = 0.8166
shapiro.test(
A6Q3$Weight[A6Q3$Exercise == "cardio"]
)
##
## Shapiro-Wilk normality test
##
## data: A6Q3$Weight[A6Q3$Exercise == "cardio"]
## W = 0.96745, p-value = 0.5812
# The no-cardio group is normally distributed because p = .817.
# The cardio group is normally distributed because p = .581.
# Therefore, an Independent T-Test will be used.
# Conduct the Independent T-Test
t.test(
Weight ~ Exercise,
data = A6Q3,
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
# I corrected the independent t-test by adding var.equal = TRUE.
# My original code conducted a Welch t-test and reported df = 47.96.
# The corrected pooled-variance test reports df = 48.
# Calculate Cohen's d effect size
cohens_d_result <- cohens_d(
Weight ~ Exercise,
data = A6Q3,
pooled_sd = TRUE
)
print(cohens_d_result)
## Cohen's d | 95% CI
## -------------------------
## 0.52 | [-0.04, 1.09]
##
## - Estimated using pooled SD.
# I corrected the effect-size code by using cohens_d()
# with pooled_sd = TRUE, as shown in the answer key.
An Independent T-Test was conducted to determine whether there was a difference in body weight between participants who regularly do cardio and participants who do not do cardio. The weight of participants who do cardio (M = 74.73, SD = 7.57) was not significantly different from the weight of participants who do not do cardio (M = 70.82, SD = 7.35), t(48) = 1.86, p > .05. The effect size was medium, Cohen’s d = 0.52. Therefore, the null hypothesis was not rejected.
I corrected the descriptive statistics, added separate histograms, updated the boxplot, used the pooled-variance independent t-test, and corrected the Cohen’s d calculation.