library(readxl)
library(effsize)
A6Q1 <- read_excel("C:/Users/nehab/OneDrive/A5221/Assignment--6/A6Q1.xlsx")
# Create the Before and After variables
Before <- A6Q1$Before
After <- A6Q1$After
# Descriptive statistics before the diet
mean(Before, na.rm = TRUE)
## [1] 76.13299
median(Before, na.rm = TRUE)
## [1] 75.95988
sd(Before, na.rm = TRUE)
## [1] 7.781323
# Descriptive statistics after the diet
mean(After, na.rm = TRUE)
## [1] 71.58994
median(After, na.rm = TRUE)
## [1] 70.88045
sd(After, na.rm = TRUE)
## [1] 6.639509
# I added na.rm = TRUE to the descriptive statistics.
# This prevents missing values from causing errors.
# Calculate the difference scores
Differences <- After - Before
# I corrected the difference-score calculation.
# Originally, I calculated Before minus After.
# I changed it to After minus Before to match the answer key.
# Examine the distribution of the difference scores
hist(
Differences,
breaks = 15,
col = "blue",
border = "white",
main = "Distribution of Score Differences",
xlab = "Difference in Scores (After Minus Before)"
)
boxplot(
Differences,
main = "Distribution of Score Differences (After - Before)",
ylab = "Difference in Scores",
col = "blue",
border = "darkblue"
)
# I corrected the histogram and boxplot formatting
# so that the graphs match the answer key.
# Test normality of the difference scores
shapiro.test(Differences)
##
## Shapiro-Wilk normality test
##
## data: Differences
## W = 0.94757, p-value = 0.3318
# The difference scores are approximately normally distributed
# because the Shapiro-Wilk p-value is .332, which is greater than .05.
# Therefore, a dependent t-test will be used.
# Conduct the dependent t-test
t.test(
Before,
After,
paired = TRUE,
na.action = na.omit
)
##
## Paired t-test
##
## data: Before and After
## t = 1.902, df = 19, p-value = 0.07245
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -0.4563808 9.5424763
## sample estimates:
## mean difference
## 4.543048
# Calculate Cohen's d effect size
cohen.d(
Before,
After,
paired = TRUE
)
##
## Cohen's d
##
## d estimate: 0.6284306 (medium)
## 95 percent confidence interval:
## lower upper
## -0.1035207 1.3603820
A dependent t-test was conducted to compare participants’ body weight before and after the low-calorie diet. Body weight was lower after the diet (M = 71.59, SD = 6.64) than before the diet (M = 76.13, SD = 7.78). However, this difference was not statistically significant, t(19) = 1.90, p = .072. Cohen’s d was 0.63. Therefore, the null hypothesis was not rejected.
I corrected the difference-score calculation by using After minus Before, as shown in the answer key. I also added missing-value handling and changed the histogram and boxplot formatting. The actual t-test output shows p = .072, which is greater than .05, so the result is not statistically significant.