library(readxl)
library(effsize)

A6Q1 <- read_excel("C:/Users/nehab/OneDrive/A5221/Assignment 6/A6Q1.xlsx")

# Descriptive statistics for body weight before the diet
mean(A6Q1$Before)
## [1] 76.13299
sd(A6Q1$Before)
## [1] 7.781323
median(A6Q1$Before)
## [1] 75.95988
# Descriptive statistics for body weight after the diet
mean(A6Q1$After)
## [1] 71.58994
sd(A6Q1$After)
## [1] 6.639509
median(A6Q1$After)
## [1] 70.88045
# Calculate the difference scores
A6Q1$difference <- A6Q1$Before - A6Q1$After

# Examine the distribution of the difference scores
hist(
  A6Q1$difference,
  main = "Distribution of Weight Difference Scores",
  xlab = "Weight Before Minus Weight After"
)

boxplot(
  A6Q1$difference,
  main = "Weight Difference Scores",
  ylab = "Before Minus After"
)

# Test normality of the difference scores
shapiro.test(A6Q1$difference)
## 
##  Shapiro-Wilk normality test
## 
## data:  A6Q1$difference
## W = 0.94757, p-value = 0.3318
# The difference scores are normally distributed because p = .332.
# The difference scores boxplot has one possible outlier.
# Therefore, a Dependent T-Test will be used.

# Create separate Before and After variables
Before <- A6Q1$Before
After <- A6Q1$After

# 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

Interpretation

A dependent t-test was conducted to compare body weight before and after participants followed the low-calorie diet. There was no statistically significant difference between body weight before (M = 76.13, SD = 7.78) and after (M = 71.59, SD = 6.64), t(19) = 1.90, p = .072. The effect size was medium (Cohen’s d = 0.63). Therefore, the null hypothesis was not rejected.