#import library

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)
library(rstatix)
## 
## Attaching package: 'rstatix'
## The following objects are masked from 'package:effectsize':
## 
##     cohens_d, eta_squared
## The following object is masked from 'package:stats':
## 
##     filter

import library

D2 <- read_excel("A6Q2.xlsx")

Descriptive stats

Before <- D2$Before
After <- D2$After

Differences <- After - Before

mean(Before, na.rm = TRUE)
## [1] 76.13299
median(Before, na.rm = TRUE)
## [1] 75.95988
sd(Before, na.rm = TRUE)
## [1] 7.781323
mean(After, na.rm = TRUE)
## [1] 57.17874
median(After, na.rm = TRUE)
## [1] 58.36459
sd(After, na.rm = TRUE)
## [1] 14.39364

Normality check

Before <- D2$Before
After <- D2$After

Differences <- After - Before

mean(Before, na.rm = TRUE)
## [1] 76.13299
median(Before, na.rm = TRUE)
## [1] 75.95988
sd(Before, na.rm = TRUE)
## [1] 7.781323
mean(After, na.rm = TRUE)
## [1] 57.17874
median(After, na.rm = TRUE)
## [1] 58.36459
sd(After, na.rm = TRUE)
## [1] 14.39364

#Histogram of Difference Scores The difference scores look [ normally] distributed. The data is [positively skewed]. The data [Does not have] a proper bell curve.

Box plot for outliers

boxplot(Differences,
        main = "Distribution of Score Differences (After - Before)",
        ylab = "Difference in Scores",
        col = "pink",
        border = "darkblue")

#Boxplot

There [is a] dot outside the boxplot. The dot [is not] close to the whiskers. The dot [is] very far away from the whiskers. Based on these findings, the boxplot is [ not normal]

Wilcoxon Signed Rank

shapiro.test(Differences)
## 
##  Shapiro-Wilk normality test
## 
## data:  Differences
## W = 0.89142, p-value = 0.02856

There is a significant difference between our data’s distribution and a normal distribution p < 0.05

The data is not normally distributed

Dependent T test

wilcox.test(Before, After, paired = TRUE, na.action = na.omit)
## 
##  Wilcoxon signed rank exact test
## 
## data:  Before and After
## V = 210, p-value = 1.907e-06
## alternative hypothesis: true location shift is not equal to 0

Willcox effect size

df_long <- data.frame(
  id = rep(1:length(Before), 2),
  time = rep(c("Before", "After"), each = length(Before)),
  score = c(Before, After)
)

wilcox_effsize(df_long, score ~ time, paired = TRUE)
## # A tibble: 1 × 7
##   .y.   group1 group2 effsize    n1    n2 magnitude
## * <chr> <chr>  <chr>    <dbl> <int> <int> <ord>    
## 1 score After  Before   0.877    20    20 large

##Observarion

A Wilcoxon Signed-Rank Test was conducted to determine if there was a difference in weight in kg before the keto diet versus after the keto diet . Before scores (Mdn = 75.960) were significantly different from after scores (Mdn = 58.365), V = 210, p < 0.001. The effect size was large, r = 0.877.