Independent two-sample t-test comparing school-night sleep for seniors who do and don’t drink caffeine.
R
Hypothesis Testing
t-Test
Author
Spencer Payne
Show the code
library(tidyverse)library(DT)library(pander)library(readr)library(dplyr)library(car)HSS <-read_csv("data/HighSchoolSeniors.csv")#If this code does not work: #Use the top menu from RStudio's window to select "Session, Set Working Directory, To Source File Location", and then play this R-chunk into your console to read the HSS data into R. ## In your Console run View(HSS) to ensure the data has loaded correctly.
In this analysis, we have a data set containing various information regarding high school seniors. Our main area of concern is the relationship between sleep on a school night and caffeine intake.
We will assume that high school seniors who do not drink caffeine get a different amount of sleep than those who do drink caffeine. We will also assume 0.05 as our \alpha
Our null and alternative hypothesis includes the following
H_0: \mu_\text{Non-Caffinated} = \mu_\text{Caffinated}
H_a: \mu_\text{Non-Caffinated} \neq \mu_\text{Caffinated}
\alpha = 0.05
Show the code
t.test(final_sleep ~ caffine_status, bev, mu =0, alternative ="two.sided")
Welch Two Sample t-test
data: final_sleep by caffine_status
t = -1.4012, df = 115.15, p-value = 0.1639
alternative hypothesis: true difference in means between group Caffine and group Non-Caffine is not equal to 0
95 percent confidence interval:
-0.57118955 0.09789252
sample estimates:
mean in group Caffine mean in group Non-Caffine
6.762299 6.998947
Show the code
qqPlot(final_sleep ~ caffine_status, bev)
Show the code
boxplot(final_sleep ~ caffine_status, bev, xlab="Caffeine vs. Non-Caffeine Drinkers", ylab="Hours of Sleep", main ="Hours slept by Caffeine and Non drinkers", col='yellow')
Based on the results of the t-test we can see that the p-value is higher that the level of significance. Meaning therefore that we have insufficient evidence to reject the null hypothesis. We cannot conclude that seniors in high school seniors who drink caffeine get the same amount of sleep than high school seniors who do not drink caffeine.