The final episode of this series is a paired t-test. We have done it before, manually. Today we will do it using R.
The exercise we did earlier was on a weight-loss program. “Company X claims its weight-loss drug success by showing the following data. You’ll test whether there’s any statistical evidence for the claim (at a 5% significance level)“.
Before | After |
120 | 114 |
94 | 95 |
86 | 80 |
111 | 116 |
99 | 93 |
78 | 83 |
78 | 74 |
96 | 91 |
132 | 136 |
108 | 109 |
94 | 90 |
88 | 91 |
101 | 100 |
93 | 90 |
121 | 120 |
115 | 110 |
102 | 103 |
94 | 93 |
82 | 81 |
84 | 80 |
The null hypothesis, H0: (weight before – after) = 0.
The alternative hypothesis, HA: (weight before – after) > 0.
We insert the data in the following command and run the function, t.test.
A_B_data <- data.frame(Before = c(120, 94, 86, 111, 99, 78, 78, 96, 132, 108, 94, 88, 101, 93, 121, 115, 102, 94, 82, 84), After = c(114, 95, 80, 116, 93, 83, 74, 91, 136, 109, 90, 91, 100, 90, 120, 110, 103, 93, 81, 80))
t.test(A_B_data$Before, A_B_data$After, paired = TRUE, alternative = "greater")
Note that we went for a one-tailed (right side) test as we wanted to verify the increase (the option, alternative = “greater”), not just a change from the reference value.
Paired t-test
data: A_B_data$Before and A_B_data$After
t = 1.6303, df = 19, p-value = 0.05975
alternative hypothesis: true difference in means is greater than 0
95 percent confidence interval:
-0.08179912 Inf
sample estimates:
mean of the differences
1.35
There was a difference of 1.35, yet the p-value was higher than the critical value we chose (0.05). The test shows no evidence to prove its effectiveness. Therefore, the null hypothesis is not rejected.
What was the significance level?
A few questions remain, did we choose a significance level of 0.05 or something else? We think we used 0.05, but we chose only one side of the t-distribution. That will partially mean a far higher tolerance level (0.05 instead of 0.025 in a two-tailed). So, what is the right way? These are valid questions, and we will answer them in a future post.