1. Paired Sample t-test

The paired samples t-test is used to compare the means between two related groups of samples. In this case, you have two values (i.e., pair of values) for the same samples.

In mtcats data, we are not able to run paired t-test, so I am taking another example for demonstration.

1a (i) Data Setup

##       before after
##  [1,]  200.1 392.9
##  [2,]  190.9 393.2
##  [3,]  192.7 345.1
##  [4,]  213.0 393.0
##  [5,]  241.4 434.0
##  [6,]  196.9 427.9
##  [7,]  172.2 422.0
##  [8,]  185.5 383.9
##  [9,]  205.2 392.3
## [10,]  193.7 352.2
##     group weight
## 1  before  200.1
## 2  before  190.9
## 3  before  192.7
## 4  before  213.0
## 5  before  241.4
## 6  before  196.9
## 7  before  172.2
## 8  before  185.5
## 9  before  205.2
## 10 before  193.7
## 11  after  392.9
## 12  after  393.2
## 13  after  345.1
## 14  after  393.0
## 15  after  434.0
## 16  after  427.9
## 17  after  422.0
## 18  after  383.9
## 19  after  392.3
## 20  after  352.2

1b (i) Running the paired sample t-test

Is there any significant changes in the weights of mice after treatment?

**H0: The mean weight is same before and after the treatment* H1: The mean weight is not same before and after the treatment

## 
##  Paired t-test
## 
## data:  weight by group
## t = 20.883, df = 9, p-value = 6.2e-09
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  173.4219 215.5581
## sample estimates:
## mean of the differences 
##                  194.49
## 
##  Paired t-test
## 
## data:  after and before
## t = 20.883, df = 9, p-value = 6.2e-09
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  173.4219 215.5581
## sample estimates:
## mean of the differences 
##                  194.49

The p-value is 6.2e-09, which is less than 0.05, hence we reject the null hypothesis. The mean weight is not same before and after the treatment.

2. Paired Samples Wilcoxon Test

The paired samples Wilcoxon test (also known as Wilcoxon signed-rank test) is a non-parametric alternative to paired t-test used to compare paired data. It’s used when your data are not normally distributed.

**H0: The median weight is same before and after the treatment* H1: The median weight is not same before and after the treatment

## 
##  Wilcoxon signed rank exact test
## 
## data:  weight by group
## V = 55, p-value = 0.001953
## alternative hypothesis: true location shift is not equal to 0

The p-value is 0.001953, which is less than 0.05, hence we reject the null hypothesis. The mean weight is not same before and after the treatment.