This material was adapted from the UF Biostatistics open Open Learning Textbook. https://bolt.mph.ufl.edu/6050-6052/unit-4b/module-13/paired-t-test/
Drunk driving is one of the main causes of car accidents. Interviews with drunk drivers who were involved in accidents and survived revealed that one of the main problems is that drivers do not realize that they are impaired, thinking “I only had 1-2 drinks … I am OK to drive.”
A random sample of 20 drivers was chosen, and their reaction times in an obstacle course were measured before and after drinking two beers. The purpose of this study was to check whether drivers are impaired after drinking two beers.
before <- read.csv("Before2Beers.csv")
after <- read.csv("After2Beers.csv")
view(before)
view(after)
before_after <- merge(before, after)
view(before_after)
for( i in 1:nrow(before_after)){
before_after$Difference <- before_after$After - before_after$Before
}
view(before_after)
before_after
## SubjectID Before After Difference
## 1 1 6.25 6.85 0.60
## 2 2 2.96 4.78 1.82
## 3 3 4.95 5.57 0.62
## 4 4 3.94 4.01 0.07
## 5 5 4.85 5.91 1.06
## 6 6 4.81 5.34 0.53
## 7 7 6.60 6.09 -0.51
## 8 8 5.33 5.84 0.51
## 9 9 5.15 4.19 -0.96
## 10 10 4.88 5.75 0.87
## 11 11 5.75 6.25 0.50
## 12 12 5.26 7.23 1.97
## 13 13 3.16 4.55 1.39
## 14 14 6.65 6.42 -0.23
## 15 15 5.49 5.25 -0.24
## 16 16 4.05 5.59 1.54
## 17 17 4.42 3.96 -0.46
## 18 18 4.99 5.93 0.94
## 19 19 5.01 6.03 1.02
## 20 20 4.69 3.72 -0.97
ggplot(before_after,aes(x=Difference))+geom_histogram(color = "black", fill = "light grey", bins = 8)
mean(before_after$Difference)
## [1] 0.5035
t.test(before_after$Difference, alternative="greater",mu=0,conf.level = 0.98)
##
## One Sample t-test
##
## data: before_after$Difference
## t = 2.6031, df = 19, p-value = 0.008734
## alternative hypothesis: true mean is greater than 0
## 98 percent confidence interval:
## 0.07706723 Inf
## sample estimates:
## mean of x
## 0.5035
Reject the null.
At 0.02 level of significance,there is enough evidence to conclude that a driver’s reaction time after two beers increases compared to their reaction time before the two beers.
(11)Zero is not in the interval, which is consistent with our conclusion from the previous question. If zero was in the interval, it would mean we would fail to reject the null, but since it is, we still can reject the null using the confidence interval.
t.test(before_after$Difference,conf.level = 0.98)
##
## One Sample t-test
##
## data: before_after$Difference
## t = 2.6031, df = 19, p-value = 0.01747
## alternative hypothesis: true mean is not equal to 0
## 98 percent confidence interval:
## 0.01231381 0.99468619
## sample estimates:
## mean of x
## 0.5035