2024-06-04

T-test

  • There are multiple types of t-tests, two of which will be used in this presentation.
  • The data being analyzed will be from “sleep”, which is
  • The objectives will be to determine if the drug administered yielded improved sleep, and also to determine if one drug was more effective than the other.

Boxplot of the two groups

  • As can be seen, both groups average above the 0 hour mark, though outliers under the 0 hour mark do exist.

Slide with R Code

  • By using a t-test, the efficacy of the drug administered can be determined; that is, it can be determined with confidence that the average extra sleep is not less than nor equal to 0.
  • The confidence will be the standard 0.95, so we will be looking for a p-value of 0.05 or lower.

Output of t-test on group 1

## 
##  One Sample t-test
## 
## data:  sleep$extra[1:10]
## t = 1.3257, df = 9, p-value = 0.1088
## alternative hypothesis: true mean is greater than 0
## 95 percent confidence interval:
##  -0.2870553        Inf
## sample estimates:
## mean of x 
##      0.75
  • Because the p-value is not below 0.05, the efficacy of drug 1 cannot be determined as it does not deviate enough from 0.

Output of t-test on group 2

## 
##  One Sample t-test
## 
## data:  sleep$extra[11:20]
## t = 3.6799, df = 9, p-value = 0.002538
## alternative hypothesis: true mean is greater than 0
## 95 percent confidence interval:
##  1.169334      Inf
## sample estimates:
## mean of x 
##      2.33
  • On the other hand, the p-value of group 2 is well below 0.05, so that means that the drug had an actual effect on the improvement of the subjects’ sleep.

Paired t-test

  • Though we have already seen that only one drug was determined to have improved the subjects’ sleep, a paired t-test can see if there is a difference between the two drugs.
  • If there is no difference, the mean difference should be equal to 0.
  • If there is a difference, the mean difference will not be equal to 0.
  • We will use the paired t-test to determine if drug 2 produced significantly more sleep than drug 1.

Paired t-test results

## 
##  Paired t-test
## 
## data:  (filter(.data = sleep, group == 2))$extra and (filter(.data = sleep, group == 1))$extra
## t = 4.0621, df = 9, p-value = 0.001416
## alternative hypothesis: true mean difference is greater than 0
## 95 percent confidence interval:
##  0.8669947       Inf
## sample estimates:
## mean difference 
##            1.58
  • As can be seen with the p-value of 0.001416, the group 2 drug produced significantly more sleep than group 1.

Barplot of differences

  • This barplot will show the visual of the difference of extra hours of sleep from drug 2 to drug 1.