Input data
library(readxl)
## Warning: package 'readxl' was built under R version 4.0.3
Data <- read_excel("C:/Users/Admin/Desktop/R/Data.xlsx",
sheet = "Paired sample t test", col_types = c("text",
"numeric"))
View(Data)
attach(Data)
require(dplyr)
## Loading required package: dplyr
## Warning: package 'dplyr' was built under R version 4.0.4
##
## 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
require(ggplot2)
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.0.3
h=ggplot(Data,aes(x=Group,y=Weight),order = c("Before", "After"))
h+geom_boxplot()+theme_bw()+theme_classic()

Assumption 1: Are the two samples paired?
Assumption 2: Is this a large sample? (n>30)
Assumption 3: Normal distribution
d= with(Data,
Weight[Group == "Before"] - Weight[Group == "After"])
shapiro.test(d)
##
## Shapiro-Wilk normality test
##
## data: d
## W = 0.94545, p-value = 0.6151
Run paired sample t test
res=t.test(Weight ~ Group, data = Data, paired = TRUE)
res
##
## Paired t-test
##
## data: Weight by Group
## t = 20.886, df = 9, p-value = 6.192e-09
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 173.3717 215.4883
## sample estimates:
## mean of the differences
## 194.43
Conclusion: p-value = 6.192e-09 => significantly different mean weight before and after using treatment