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) 

A6Q42<- read_excel("C:/Users/NITHIN KUMAR/OneDrive/Desktop/Form 1098-T/A6Q42.xlsx")  
colnames(A6Q42) <- c("weight", "bodyweight_kg") 

A6Q42 %>%
  group_by(weight) %>%
  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
##   weight  Mean Median    SD     N
##   <chr>  <dbl>  <dbl> <dbl> <int>
## 1 lift   120.   116.   53.3    25
## 2 nolift  33.0   40.8  56.7    25
hist(A6Q42$bodyweight_kg[A6Q42$weight == "lift"],
     main = "Histogram of lift",
     xlab = "Value",
     ylab = "Frequency",
     col = "lightblue",
     border = "black",
     breaks = 10)

hist(A6Q42$bodyweight_kg[A6Q42$weight == "nolift"],
     main = "Histogram of nolift",
     xlab = "Value",
     ylab = "Frequency",
     col = "lightgreen",
     border = "black",
     breaks = 10) 

#Group 1: lift
#The first variable looks abnormally distributed.
#The data is positively skewed.
#The data does not have a proper bell curve.


#Group 2: nolift
#The second variable looks abnormally distributed.
#The data is negatively skewed.
#The data does not have a proper bell curve. 

ggboxplot(A6Q42, x = "weight", y = "bodyweight_kg",
          color = "weight",
          palette = "jco",
          add = "jitter")   

#Boxplot 1: lift
#There are dots outside the boxplot.
#The dots  are not close to the whiskers.
#The dots are very far away from the whiskers.
#The outliers  are not balanced.
#Based on these findings, the boxplot is not normal

#Boxplot 2: nolift
#There are dots outside the boxplot.
#The dots  are not close to the whiskers.
#The dots are very far away from the whiskers.
#The outliers are not balanced. 
#Based on these findings, the boxplot is not normal.

shapiro.test(A6Q42$bodyweight_kg[A6Q42$weight == "lift"])
## 
##  Shapiro-Wilk normality test
## 
## data:  A6Q42$bodyweight_kg[A6Q42$weight == "lift"]
## W = 0.78786, p-value = 0.0001436
shapiro.test(A6Q42$bodyweight_kg[A6Q42$weight == "nolift"]) 
## 
##  Shapiro-Wilk normality test
## 
## data:  A6Q42$bodyweight_kg[A6Q42$weight == "nolift"]
## W = 0.70002, p-value = 7.294e-06
#Group 1: lift
#The first group is abnormally distributed, (p = 0.0001436).

#Group 2: nolift
#The second group is  abnormally distributed, (p = 7.294e-06). 

wilcox.test(bodyweight_kg ~ weight, data = A6Q42) 
## 
##  Wilcoxon rank sum exact test
## 
## data:  bodyweight_kg by weight
## W = 603, p-value = 7.132e-11
## alternative hypothesis: true location shift is not equal to 0
mw_effect <- cliff.delta(bodyweight_kg ~ weight, data = A6Q42)
print(mw_effect)   
## 
## Cliff's Delta
## 
## delta estimate: 0.9296 (large)
## 95 percent confidence interval:
##     lower     upper 
## 0.7993841 0.9764036
#A Wilcoxon Signed-Rank Test was conducted to determine if there was a difference in OutcomeVariable before Independent Variable versus after Independent Variable.
#Before scores (Mdn = 116.) were significantly different from after scores (Mdn = 40.8), p = < .001.
#The effect size was very large, r = .9296.