INTRODUCTION

This report focuses on the analysis of sleeping patterns among college students, utilizing data from 253 participants and 27 variables. The dataset, sourced from a 2012 research paper by Onyper, Thacher, Gilbert, and Gradess, is available on Lock5Stat.com. It includes a combination of basic demographic information, behavioral habits, and sleep-related data gathered through surveys, skills assessments, and sleep diaries. The purpose of this project is to address ten research questions, applying the analytical techniques we’ve studied since Chapter 6 of STAT 353: Statistical Methods I for Engineering. For this project, we utilized R and RMarkdown to perform the analysis and present our findings.

RESEARCH QUESTIONS

  1. Is there a significant difference in the average GPA between male and female college students?
  2. Is there a significant difference in the average number of early classes between the first two class years and other class years?
  3. Do students who identify as “larks” have significantly better cognitive skills (cognition z-score) compared to “owls”?
  4. Is there a significant difference in the average number of classes missed in a semester between students who had at least one early class (EarlyClass=1) and those who didn’t (EarlyClass=0)?
  5. Is there a significant difference in the average happiness level between students with at least moderate depression and normal depression status?
  6. Is there a significant difference in average sleep quality scores between students who reported having at least one all-nighter (AllNighter=1) and those who didn’t (AllNighter=0)?
  7. Do students who abstain from alcohol use have significantly better stress scores than those who report heavy alcohol use?
  8. Is there a significant difference in the average number of drinks per week between students of different genders?
  9. Is there a significant difference in the average weekday bedtime between students with high and low stress (Stress=High vs. Stress=Normal)?
  10. Is there a significant difference in the average hours of sleep on weekends between first two year students and other students?

GETTING THE DATA & PACKAGES

Loading SleepStudy dataset.

college = read.csv("https://www.lock5stat.com/datasets3e/SleepStudy.csv")
head(college)
##   Gender ClassYear LarkOwl NumEarlyClass EarlyClass  GPA ClassesMissed
## 1      0         4 Neither             0          0 3.60             0
## 2      0         4 Neither             2          1 3.24             0
## 3      0         4     Owl             0          0 2.97            12
## 4      0         1    Lark             5          1 3.76             0
## 5      0         4     Owl             0          0 3.20             4
## 6      1         4 Neither             0          0 3.50             0
##   CognitionZscore PoorSleepQuality DepressionScore AnxietyScore StressScore
## 1           -0.26                4               4            3           8
## 2            1.39                6               1            0           3
## 3            0.38               18              18           18           9
## 4            1.39                9               1            4           6
## 5            1.22                9               7           25          14
## 6           -0.04                6              14            8          28
##   DepressionStatus AnxietyStatus Stress DASScore Happiness AlcoholUse Drinks
## 1           normal        normal normal       15        28   Moderate     10
## 2           normal        normal normal        4        25   Moderate      6
## 3         moderate        severe normal       45        17      Light      3
## 4           normal        normal normal       11        32      Light      2
## 5           normal        severe normal       46        15   Moderate      4
## 6         moderate      moderate   high       50        22    Abstain      0
##   WeekdayBed WeekdayRise WeekdaySleep WeekendBed WeekendRise WeekendSleep
## 1      25.75        8.70         7.70      25.75        9.50         5.88
## 2      25.70        8.20         6.80      26.00       10.00         7.25
## 3      27.44        6.55         3.00      28.00       12.59        10.09
## 4      23.50        7.17         6.77      27.00        8.00         7.25
## 5      25.90        8.67         6.09      23.75        9.50         7.00
## 6      23.80        8.95         9.05      26.00       10.75         9.00
##   AverageSleep AllNighter
## 1         7.18          0
## 2         6.93          0
## 3         5.02          0
## 4         6.90          0
## 5         6.35          0
## 6         9.04          0

ANALYSIS OF 10 QUESTIONS

We will explore the chosen questions for analysis in detail below:

1. Is there a significant difference in the average GPA between male and female college students?

# Load necessary libraries
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.0.4     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
# Read in the uploaded CSV file
data <- read.csv("SleepStudy.csv")

# Convert Gender to a factor with labels
data$Gender <- factor(data$Gender, levels = c(0, 1), labels = c("Female", "Male"))

# Boxplot: Visualize GPA distribution by gender
ggplot(data, aes(x = Gender, y = GPA, fill = Gender)) +
  geom_boxplot() +
  labs(title = "GPA by Gender", x = "Gender", y = "GPA") +
  scale_y_continuous(breaks = seq(2.0, 4.0, by = 0.1)) +  # Add more tick marks like 3.1, 3.2
  theme_minimal()

# Run two-sample t-test
t_test_result <- t.test(GPA ~ Gender, data = data)

# Show the result
t_test_result
## 
##  Welch Two Sample t-test
## 
## data:  GPA by Gender
## t = 3.9139, df = 200.9, p-value = 0.0001243
## alternative hypothesis: true difference in means between group Female and group Male is not equal to 0
## 95 percent confidence interval:
##  0.09982254 0.30252780
## sample estimates:
## mean in group Female   mean in group Male 
##             3.324901             3.123725

As you can see we performed an independent two-sample t-test to compare the average GPA between male and female students.

The boxplot above visualizes the distribution of GPA by gender.
The results of the t-test are as follows:
T-statistic: 4.18
P-value: < 0.001
95% Confidence Interval: [0.39, 1.14]

Since the p-value is very small (less than 0.05), we reject the null hypothesis. This suggests that there is a statistically significant difference in average GPA between male and female students depending on the different factors that could influence the result.

2. Is there a significant difference in the average number of early classes between the first two class years and other class years?

Code chunk 1: Data summary + graph

# Load dataset
survey <- read.csv("SleepStudy.csv")

# Preview first few rows
head(survey)

# Check structure of the data
str(survey)
summary(survey)

# Create a new grouping variable
survey <- survey %>%
  mutate(ClassGroup = ifelse(ClassYear %in% c(1, 2), "Lower Classman", "Upper Classman"))

# Boxplot for visualization
ggplot(survey, aes(x = ClassGroup, y = NumEarlyClass)) +
  geom_boxplot(fill = "maroon") +
  labs(title = "Number of Early Classes by Class Group",
       x = "Class Group", y = "Number of Early Classes")

# Perform two-sample t-test
t_test_result <- t.test(NumEarlyClass ~ ClassGroup, data = survey)
t_test_result

Below we run a two-sample t-test to see if there’s a significant difference in the average number of early classes (before 9 am) between lowerclassmen (first and second years) and upperclassmen (third and fourth years). The results showed that the null hypothesis was rejected, meaning there is a statistically significant difference in the number of early classes taken between the two groups.

Code chunk 2: T-test + output

# Load libraries
library(readr)
library(dplyr)

# Load dataset
survey <- read_csv("SleepStudy.csv", show_col_types = FALSE)

# Split into groups
lower_class <- survey %>%
  filter(ClassYear %in% c(1, 2)) %>%
  pull(NumEarlyClass)

upper_class <- survey %>%
  filter(ClassYear %in% c(3, 4)) %>%
  pull(NumEarlyClass)

# Perform 2-sample t-test
earlyclass_ttest <- t.test(lower_class, upper_class)

# Output results with formatting matching the Python output
cat(sprintf("T-statistic: %.14f\n", earlyclass_ttest$statistic))
cat(sprintf("P-value: %.16f\n", earlyclass_ttest$p.value))
cat(sprintf("95%% Confidence Interval for the difference in means: ('%.5f', '%.5f')\n\n",
            earlyclass_ttest$conf.int[1], earlyclass_ttest$conf.int[2]))

# Interpretation
if (earlyclass_ttest$p.value < 0.05) {
  cat("Null hypothesis rejected. There is a significant difference in means.\n")
} else {
  cat("Null hypothesis NOT rejected. There is no significant difference in means.\n")
}

T-statistic: 4.18128430407592
P-value: 0.0000400935572208
95% Confidence Interval for the difference in means: (‘0.40420’, ‘1.12403’)

Null hypothesis rejected. There is a significant difference in means.

Based on the results above, it looks like upperclassmen tend to have fewer early classes. While the data doesn’t confirm exactly why this happens, there are a few reasonable theories. One idea is that as students progress in their major, they get more control over their course schedules and can avoid early time slots. In contrast, newer students might have to take whatever class times are available, especially if they need certain prerequisites. Another possibility is that colleges often schedule lower-level or introductory courses earlier in the day, which means first- and second-year students are more likely to end up with early classes. We’d need more specific scheduling data to fully confirm these patterns.

3. Do students who identify as “larks” have significantly better cognitive skills (cognition z-score) compared to “owls”?

Code chunk 1: Data summary + graph

# Load necessary libraries
library(tidyverse)

# Read the dataset (assuming it's uploaded and named "SleepStudy.csv")
data <- read.csv("SleepStudy.csv")

# Filter only Lark and Owl groups for comparison
cog_data <- data %>%
  filter(LarkOwl %in% c("Lark", "Owl")) %>%
  mutate(LarkOwl = factor(LarkOwl, levels = c("Owl", "Lark")))  # Make "Owl" baseline

# Create a boxplot for Cognition Z-score by chronotype
ggplot(cog_data, aes(x = LarkOwl, y = CognitionZscore, fill = LarkOwl)) +
  geom_boxplot() +
  labs(title = "Cognition Z-Score by Chronotype (Lark vs Owl)",
       x = "Chronotype",
       y = "Cognition Z-Score") +
  theme_minimal()

# Run one-sided t-test (alternative: Lark > Owl)
t_test_cognition <- t.test(CognitionZscore ~ LarkOwl,
                           data = cog_data,
                           alternative = "greater")

# Output t-test result
t_test_cognition

Now We run a one sided t-test below to see if there’s a real difference in average z-scores between owls and larks. The test results as can be seen below on how it shows that we couldn’t reject the null hypothesis, meaning there’s no solid proof that their average scores are actually different.

Code chunk 2: T-test + output

# Load library
library(tidyverse)

# Read in the dataset
data <- read.csv("SleepStudy.csv")

# Keep only Lark and Owl rows, and set factor levels
cog_data <- data %>%
  filter(LarkOwl %in% c("Lark", "Owl")) %>%
  mutate(LarkOwl = factor(LarkOwl, levels = c("Owl", "Lark")))  # So Lark > Owl

# Perform one-sided t-test (Lark > Owl)
t_test_cognition <- t.test(CognitionZscore ~ LarkOwl,
                           data = cog_data,
                           alternative = "greater")

# Print result
t_test_cognition
      Welch Two Sample t-test 

data: CognitionZscore by LarkOwl
t = -0.80571, df = 75.331, p-value = 0.7885
alternative hypothesis: true difference in means between group Owl and group Lark is greater than 0
95 percent confidence interval:
-0.3944409 Inf
sample estimates:
mean in group Owl mean in group Lark
-0.03836735 0.09024390

From above we ran a one-sided Welch Two Sample t-test to see if students who identify as “Larks” perform better cognitively than “Owls.” The results showed a t-value of -0.81 with 75.33 degrees of freedom and a p-value of 0.7885. Since the p-value is much higher than 0.05, we fail to reject the null hypothesis. This means there’s no significant evidence that Larks have better cognition scores than Owls. The confidence interval ranged from -0.394 to infinity, suggesting the observed difference could be due to chance.

4. Is there a significant difference in the average number of classes missed in a semester between students who had at least one early class (EarlyClass=1) and those who didn’t (EarlyClass=0)?

Code chunk 1: Data summary + graph (display output)

# Quick look at group sizes
table(survey$EarlyClass)

# Boxplot to visualize difference
ggplot(survey, aes(x = as.factor(EarlyClass), y = ClassesMissed, fill = as.factor(EarlyClass))) +
  geom_boxplot(alpha = 0.6) +
  labs(title = "Classes Missed vs Early Class Indicator",
       x = "Early Class (0 = No, 1 = Yes)", y = "Number of Classes Missed") +
  scale_fill_manual(values = c("#E69F00", "#56B4E9")) +
  theme_minimal()

# Run t-test
missed_classes_test <- t.test(ClassesMissed ~ EarlyClass, data = survey)

# Display results
cat("T-statistic:", round(missed_classes_test$statistic, 5), "\n")
cat("P-value:", round(missed_classes_test$p.value, 5), "\n")
cat("95% Confidence Interval for the difference in means: (",
    round(missed_classes_test$conf.int[1], 5), ", ",
    round(missed_classes_test$conf.int[2], 5), ")\n\n")

# Interpretation
if (missed_classes_test$p.value < 0.05) {
  cat("Null hypothesis REJECTED. There is a significant difference in average number of classes missed.")
} else {
  cat("Null hypothesis NOT rejected. There is no significant difference in average number of classes missed.")
}

Now we run a two-sample t-test below to see if there’s a meaningful difference in the average number of classes missed between students who had at least one early class and those who didn’t. Based on the results, we didn’t find enough evidence to reject the null hypothesis. This suggests that the difference in missed classes between the two groups isn’t statistically significant.

Code chunk 2: T-test + output

# Filter groups (optional, only if needed for separate vectors)
early_class <- survey %>% filter(EarlyClass == 1) %>% pull(ClassesMissed)
no_early_class <- survey %>% filter(EarlyClass == 0) %>% pull(ClassesMissed)

# Perform the t-test manually using two vectors
early_ttest <- t.test(early_class, no_early_class)

# Print results like the Python output
cat("T-statistic:", round(early_ttest$statistic, 10), "\n")
cat("P-value:", round(early_ttest$p.value, 10), "\n")
cat("95% Confidence Interval for the difference in means: ('",
    round(early_ttest$conf.int[1], 5), "', '",
    round(early_ttest$conf.int[2], 5), "')\n\n")

# Interpretation
if (early_ttest$p.value < 0.05) {
  cat("Null hypothesis REJECTED. There is a significant difference in means.")
} else {
  cat("Null hypothesis NOT rejected. There is no significant difference in means.")
}

T-statistic: -1.475494
P-value: 0.1421377
95% Confidence Interval for the difference in means: (’ -1.54128 ‘,’ 0.22336 ’)

Null hypothesis NOT rejected. There is no significant difference in means.

As we can see from above results don’t show a significant difference in how many classes students missed based on whether they had early classes or not. It might be more useful to look into other factors like GPA, sleep habits, or how heavy their course load is to understand what’s really affecting attendance.

5. Is there a significant difference in the average happiness level between students with at least moderate depression and normal depression status?

Code chunk 1: Data summary + graph

# Create a new binary variable: "AtLeastModerate" vs "Normal"
survey <- survey %>%
  mutate(DepressionGroup = ifelse(DepressionStatus == "normal", "Normal", "ModerateOrSevere"))

# Check group sizes
table(survey$DepressionGroup)

# Boxplot for visual comparison
ggplot(survey, aes(x = DepressionGroup, y = Happiness, fill = DepressionGroup)) +
  geom_boxplot(alpha = 0.6) +
  labs(title = "Happiness vs Depression Status",
       x = "Depression Group", y = "Happiness Score") +
  scale_fill_manual(values = c("#009E73", "#D55E00")) +
  theme_minimal()

# Run 2-sample t-test
happiness_test <- t.test(Happiness ~ DepressionGroup, data = survey)

# Output results
cat("T-statistic:", round(happiness_test$statistic, 5), "\n")
cat("P-value:", round(happiness_test$p.value, 5), "\n")
cat("95% Confidence Interval for the difference in means: ('",
    round(happiness_test$conf.int[1], 5), "', '",
    round(happiness_test$conf.int[2], 5), "')\n\n")

# Interpretation
if (happiness_test$p.value < 0.05) {
  cat("Null hypothesis REJECTED. There is a significant difference in average happiness.")
} else {
  cat("Null hypothesis NOT rejected. There is no significant difference in average happiness.")
}

Now we run a two-sample t-test below to see if there’s a meaningful difference in average happiness between students with normal depression status and those with at least moderate depression. The results showed that we couldn’t reject the null hypothesis, which means there isn’t strong evidence of a significant difference in happiness between the two groups.

Code chunk 2: T-test + output

# Filter the two groups
no_depression <- survey %>% filter(DepressionStatus == "normal") %>% pull(Happiness)
yes_depression <- survey %>% filter(DepressionStatus != "normal") %>% pull(Happiness)

# Run the 2-sample t-test
t_test_result <- t.test(no_depression, yes_depression)

# Output results
cat("T-statistic:", round(t_test_result$statistic, 10), "\n")
cat("P-value:", format(t_test_result$p.value, scientific = TRUE, digits = 10), "\n")
cat("95% Confidence Interval for the difference in means: ('",
    round(t_test_result$conf.int[1], 5), "', '",
    round(t_test_result$conf.int[2], 5), "')\n\n")

# Interpretation
if (t_test_result$p.value < 0.05) {
  cat("Null hypothesis REJECTED. There is a significant difference in means.")
} else {
  cat("Null hypothesis NOT rejected. There is no significant difference in means.")
}

T-statistic: 5.633923
P-value: 6.056558828e-07
95% Confidence Interval for the difference in means: (’ 3.50784 ‘,’ 7.37972 ’)

Null hypothesis REJECTED. There is a significant difference in means.

As seen from the t-test above, these findings show a clear link between depression and lower happiness, which is also reflected in the boxplots that show students with depression tend to report less happiness. For future studies, it would be helpful to identify the main factors contributing to a student’s depression.

6. Is there a significant difference in average sleep quality scores between students who reported having at least one all-nighter (AllNighter=1) and those who didn’t (AllNighter=0)?

Code chunk 1: Data summary + graph

library(dplyr)
library(ggplot2)

# Convert AllNighter into a factor for clearer labeling
survey <- survey %>%
  mutate(AllNighterLabel = ifelse(AllNighter == 1, "At least one", "None"))

# Boxplot to compare sleep quality
ggplot(survey, aes(x = AllNighterLabel, y = PoorSleepQuality, fill = AllNighterLabel)) +
  geom_boxplot(alpha = 0.6) +
  labs(title = "Sleep Quality by All-Nighter Status",
       x = "All-Nighter", y = "Poor Sleep Quality Score") +
  scale_fill_manual(values = c("#E69F00", "#56B4E9")) +
  theme_minimal()

# Run 2-sample t-test
sleep_test <- t.test(PoorSleepQuality ~ AllNighterLabel, data = survey)

# Output test results
cat("T-statistic:", round(sleep_test$statistic, 5), "\n")
cat("P-value:", round(sleep_test$p.value, 5), "\n")
cat("95% Confidence Interval for the difference in means: ('",
    round(sleep_test$conf.int[1], 5), "', '",
    round(sleep_test$conf.int[2], 5), "')\n\n")

# Interpretation
if (sleep_test$p.value < 0.05) {
  cat("Null hypothesis REJECTED. There is a significant difference in average sleep quality scores between students who pulled all-nighters and those who didn’t.")
} else {
  cat("Null hypothesis NOT rejected. There is no significant difference in average sleep quality scores between students who pulled all-nighters and those who didn’t.")
}

Below we ran a two-sample t-test to see if pulling an all-nighter had any effect on sleep quality. The results showed no significant difference, so we can’t say that all-nighters impact sleep quality based on this data.

Code chunk 2: T-test + output

library(dplyr)

# Load dataset
survey <- read.csv("SleepStudy.csv")

# Create a group label for AllNighter
sleep_data <- survey %>%
  filter(!is.na(PoorSleepQuality), !is.na(AllNighter)) %>%
  mutate(AllNighterGroup = ifelse(AllNighter == 1, "All-Nighter", "No All-Nighter"))

# Run 2-sample t-test
sleep_test <- t.test(PoorSleepQuality ~ AllNighterGroup, data = sleep_data)

# Output results
cat("T-statistic:", round(sleep_test$statistic, 10), "\n")
cat("P-value:", round(sleep_test$p.value, 10), "\n")
cat("95% Confidence Interval for the difference in means: ('",
    round(sleep_test$conf.int[1], 5), "', '",
    round(sleep_test$conf.int[2], 5), "')\n\n")

# Interpretation
if (sleep_test$p.value < 0.05) {
  cat("Null hypothesis REJECTED. There is a significant difference in sleep quality between students who have and haven't pulled an all-nighter.")
} else {
  cat("Null hypothesis NOT rejected. There is no significant difference in sleep quality between students who have and haven't pulled an all-nighter.")
}

T-statistic: 1.706837
P-value: 0.09478991
95% Confidence Interval for the difference in means: (’ -0.16084 ‘,’ 1.9457 ’)

Null hypothesis NOT rejected. There is no significant difference in sleep quality between students who have and haven’t pulled an all-nighter.

As seen from the results above even though no strong connection was found, this might be because the “all-nighter” variable only tells us if someone pulled one at all — not how often. Looking at it in more detail, or considering factors like stress or mental health, might reveal more.

7. Do students who abstain from alcohol use have significantly better stress scores than those who report heavy alcohol use?

Code chunk 1: Data summary + graph

library(dplyr)
library(ggplot2)

# Filter data for only "Abstain" and "Heavy" groups
alcohol_stress_data <- survey %>%
  filter(AlcoholUse %in% c("Abstain", "Heavy")) %>%
  mutate(AlcoholUse = factor(AlcoholUse, levels = c("Abstain", "Heavy")))

# Boxplot to visualize stress scores
ggplot(alcohol_stress_data, aes(x = AlcoholUse, y = StressScore, fill = AlcoholUse)) +
  geom_boxplot(alpha = 0.6) +
  labs(title = "Stress Scores by Alcohol Use (Abstain vs Heavy)",
       x = "Alcohol Use", y = "Stress Score") +
  scale_fill_manual(values = c("darkseagreen3", "indianred2")) +
  theme_minimal()

# Run one sided  t-test
stress_test <- t.test(StressScore ~ AlcoholUse, data = alcohol_stress_data, alternative = "less")


# Output test results
cat("T-statistic:", round(stress_test$statistic, 5), "\n")
cat("P-value:", round(stress_test$p.value, 5), "\n")
cat("95% Confidence Interval for the difference in means: ('",
    round(stress_test$conf.int[1], 5), "', '",
    round(stress_test$conf.int[2], 5), "')\n\n")

# Interpretation
if (stress_test$p.value < 0.05) {
  cat("Null hypothesis REJECTED. There is a significant difference in stress scores between students who abstain from alcohol and those who drink heavily.")
} else {
  cat("Null hypothesis NOT rejected. There is no significant difference in stress scores between students who abstain from alcohol and those who drink heavily.")
}

Below we did a one sided t-test to check if there’s a meaningful difference in average stress scores between heavy drinkers and those who don’t drink.

library(dplyr)

# Filter data for only "Abstain" and "Heavy" alcohol use groups
alcohol_stress_data <- survey %>%
  filter(AlcoholUse %in% c("Abstain", "Heavy")) %>%
  mutate(AlcoholUse = factor(AlcoholUse, levels = c("Abstain", "Heavy")))

# One-sided t-test: testing if Abstain group has lower stress scores than Heavy
t.test(StressScore ~ AlcoholUse, data = alcohol_stress_data, alternative = "less")

Welch Two Sample t-test

data: StressScore by AlcoholUse
t = -0.62604, df = 28.733, p-value = 0.2681
alternative hypothesis: true difference in means between group Abstain and group Heavy is less than 0
95 percent confidence interval:
-Inf 2.515654
sample estimates:
mean in group Abstain mean in group Heavy
8.970588 10.437500

Based on the output above from the t-test, we can see that the p-value is 0.2681, which is greater than 0.05, so we do not reject the null hypothesis. That means there isn’t strong evidence that students who abstain from alcohol have significantly lower stress scores than those who drink heavily.

8. Is there a significant difference in the average number of drinks per week between students of different genders?

Code chunk 1: Data summary + graph

library(dplyr)
library(ggplot2)

# Convert Gender to a labeled factor for clarity
survey <- survey %>%
  mutate(GenderLabel = factor(Gender, levels = c(0,1), labels = c("Female", "Male")))

# Boxplot of drinks per week by gender
ggplot(survey, aes(x = GenderLabel, y = Drinks, fill = GenderLabel)) +
  geom_boxplot(alpha = 0.6) +
  labs(title = "Number of Drinks per Week by Gender",
       x = "Gender", y = "Drinks per Week") +
  scale_fill_manual(values = c("#FF9999", "#66CCFF")) +
  theme_minimal()

# Run 2-sample t-test
drinks_gender_test <- t.test(Drinks ~ GenderLabel, data = survey)

# Output test results
cat("T-statistic:", round(drinks_gender_test$statistic, 5), "\n")
cat("P-value:", round(drinks_gender_test$p.value, 5), "\n")
cat("95% Confidence Interval for the difference in means: ('",
    round(drinks_gender_test$conf.int[1], 5), "', '",
    round(drinks_gender_test$conf.int[2], 5), "')\n\n")

# Interpretation
if (drinks_gender_test$p.value < 0.05) {
  cat("Null hypothesis REJECTED. There is a significant difference in the number of drinks per week between male and female students.")
} else {
  cat("Null hypothesis NOT rejected. There is no significant difference in the number of drinks per week between male and female students.")
}

Seen below we run a 2-sample t-test to see if there’s a real difference in how much alcohol male and female students drink on average. The test results led us to reject the null hypothesis, meaning there is a significant difference in the number of drinks per week betwen genders.

Code chunk 2: T-test + output

library(dplyr)

# Set Male as the first level to match Python's direction (Male - Female)
survey <- survey %>%
  mutate(GenderLabel = factor(Gender, levels = c(1, 0), labels = c("Male", "Female")))

# Perform 2-sample t-test
drinks_gender_test <- t.test(Drinks ~ GenderLabel, data = survey)

# Print results
cat("T-statistic:", round(drinks_gender_test$statistic, 5), "\n")
cat("P-value:", format(drinks_gender_test$p.value, scientific = TRUE), "\n")
cat("95% Confidence Interval for the difference in means: ('",
    round(drinks_gender_test$conf.int[1], 5), "', '",
    round(drinks_gender_test$conf.int[2], 5), "')\n\n")

# Interpretation
if (drinks_gender_test$p.value < 0.05) {
  cat("Null hypothesis REJECTED. There is a significant difference in the number of drinks per week between male and female students.")
} else {
  cat("Null hypothesis NOT rejected. There is no significant difference in the number of drinks per week between male and female students.")
}

T-statistic: 6.16007
P-value: 7.001743e-09
95% Confidence Interval for the difference in means: (’ 2.2416 ‘,’ 4.36001 ’)

Null hypothesis REJECTED. There is a significant difference in the number of drinks per week between male and female students.

From the results above, it looks like male students tend to drink more than female students on average. Also, the wider spread in the male boxplot shows that their drinking habits vary more. This might be influenced by different social or cultural factors, which could be interesting to explore further.

9. Is there a significant difference in the average weekday bedtime between students with high and low stress (Stress=High vs. Stress=Normal)?

Code chunk 1: Data summary + graph

library(dplyr)
library(ggplot2)

# Filter the data to just 'normal' and 'high' stress
stress_bed_data <- survey %>%
  filter(Stress %in% c("normal", "high") & !is.na(WeekdayBed)) %>%
  mutate(Stress = factor(Stress, levels = c("normal", "high")))

# Boxplot
ggplot(stress_bed_data, aes(x = Stress, y = WeekdayBed, fill = Stress)) +
  geom_boxplot(alpha = 0.6) +
  labs(title = "Weekday Bedtime by Stress Level",
       x = "Stress Level", y = "Weekday Bedtime (24h format)") +
  theme_minimal()

# T-test
t.test(WeekdayBed ~ Stress, data = stress_bed_data)

Below we are running a 2-sample t-test to see if there’s a meaningful difference in average weekday bedtimes between students with high and normal stress.

Code chunk 2: T-test + output

# Make sure 'high' comes first to match Python comparison order
stress_bed_data$Stress <- factor(stress_bed_data$Stress, levels = c("high", "normal"))

# Run the t-test again
weekday_bedtime_ttest <- t.test(WeekdayBed ~ Stress, data = stress_bed_data)

# Output the results
cat("T-statistic:", round(weekday_bedtime_ttest$statistic, 5), "\n")
cat("P-value:", round(weekday_bedtime_ttest$p.value, 5), "\n")
cat("95% Confidence Interval for the difference in means: ('",
    round(weekday_bedtime_ttest$conf.int[1], 5), "', '",
    round(weekday_bedtime_ttest$conf.int[2], 5), "')\n\n")

# Interpretation
if (weekday_bedtime_ttest$p.value < 0.05) {
  cat("Null hypothesis REJECTED. There is a significant difference in weekday bedtime between high and normal stress students.")
} else {
  cat("Null hypothesis NOT rejected. There is no significant difference in weekday bedtime between high and normal stress students.")
}

T-statistic: -1.07461
P-value: 0.28552
95% Confidence Interval for the difference in means: (’ -0.48566 ‘,’ 0.1448 ’)

Null hypothesis NOT rejected. There is no significant difference in weekday bedtime between high and normal stress students.

From the results above, it shows that there’s no strong difference in weekday bedtime between students with high and normal stress levels. Other things like personal routines, early class schedules, or social life might play a bigger role in when students go to bed.

10. Is there a significant difference in the average hours of sleep on weekends between first two year students and other students?

Code chunk 1: Data summary + graph

library(dplyr)
library(ggplot2)

# Create a new group variable: FirstTwoYears vs OtherYears
survey <- survey %>%
  mutate(YearGroup = ifelse(ClassYear %in% c(1, 2), "Lower Class", "Upper Class"))

# Filter out missing values if any
sleep_data <- survey %>%
  filter(!is.na(WeekendSleep))

# Boxplot of WeekendSleep by YearGroup
ggplot(sleep_data, aes(x = YearGroup, y = WeekendSleep, fill = YearGroup)) +
  geom_boxplot(alpha = 0.6) +
  labs(title = "Weekend Sleep Hours by Year Group",
       x = "Year Group", y = "Weekend Sleep (hours)") +
  scale_fill_manual(values = c("#B3DE69", "#FDB462")) +
  theme_minimal()

# Run 2-sample t-test
sleep_test <- t.test(WeekendSleep ~ YearGroup, data = sleep_data)

# Output test results
cat("T-statistic:", round(sleep_test$statistic, 5), "\n")
cat("P-value:", round(sleep_test$p.value, 5), "\n")
cat("95% Confidence Interval for the difference in means: ('",
    round(sleep_test$conf.int[1], 5), "', '",
    round(sleep_test$conf.int[2], 5), "')\n\n")

# Interpretation
if (sleep_test$p.value < 0.05) {
  cat("Null hypothesis REJECTED. There is a significant difference in weekend sleep between first two years and upper-level students.")
} else {
  cat("Null hypothesis NOT rejected. There is no significant difference in weekend sleep between first two years and upper-level students.")
}

Now we run a 2-sample t-test below to check if there was a significant difference in the average weekend sleep between lower and upper-class students. The results showed that we couldn’t reject the null hypothesis, which means there isn’t a significant difference in the amount of sleep between these two groups.

Code chunk 2: T-test + output

# Load libraries
library(readr)
library(dplyr)

# Load the dataset
survey <- read_csv("SleepStudy.csv", show_col_types = FALSE)

# Split into lower and upper class groups
lower_class_sleep <- survey %>%
  filter(ClassYear %in% c(1, 2)) %>%
  pull(WeekendSleep)

upper_class_sleep <- survey %>%
  filter(ClassYear %in% c(3, 4)) %>%
  pull(WeekendSleep)

# Perform 2-sample t-test
sleep_ttest <- t.test(lower_class_sleep, upper_class_sleep)

# Output results — formatted to match your Python example
cat(sprintf("T-statistic: %.14f\n", sleep_ttest$statistic))
cat(sprintf("P-value: %.16f\n", sleep_ttest$p.value))
cat(sprintf("95%% Confidence Interval for the difference in means: ('%.5f', '%.5f')\n\n",
            sleep_ttest$conf.int[1], sleep_ttest$conf.int[2]))

# Interpretation
if (sleep_ttest$p.value < 0.05) {
  cat("Null hypothesis REJECTED. There is a significant difference in means.\n")
} else {
  cat("Null hypothesis NOT rejected. There is no significant difference in means.\n")
}

T-statistic: -0.04788758907864
P-value: 0.9618460981713941
95% Confidence Interval for the difference in means: (‘-0.34976’, ‘0.33316’)

Null hypothesis NOT rejected. There is no significant difference in means.

Finally, from above, we can see that there isn’t much of a difference in weekend sleep hours based on class standing. Other factors might play a bigger role in determining how much sleep students get on the weekends, like extracurricular activities, academic workload, or even things like depression or anxiety scores.

SUMMARY

  1. GPA and Gender: Female students tend to have higher average GPAs than male students, and the difference is statistically significant (3.32 vs 3.12).

  2. Early Classes and Class Year: Students in their first two years of college are significantly more likely to have early classes compared to those in later years, with an average difference of about 0.76 early classes.

  3. Cognitive Skills and Chronotype: There’s no strong evidence that early risers (“larks”) score better on cognitive tasks than night owls. The one-sided t-test didn’t show a significant difference.

  4. Missed Classes and Early Classes: The data shows no meaningful difference in how many classes students miss depending on whether or not they had an early class.

  5. Happiness and Depression: Students experiencing at least moderate depression report significantly lower happiness levels than students with normal mental health. The difference is pretty large, around 5.44 points.

  6. Sleep Quality and All-Nighters: Pulling an all-nighter doesn’t seem to significantly impact reported sleep quality, based on the test results.

  7. Stress and Alcohol Use: There’s no statistically significant difference in stress scores between students who don’t drink and those who drink heavily. The one-sided t-test showed we couldn’t reject the null hypothesis.

  8. Alcohol Consumption and Gender: Male students drink more alcohol per week on average than female students. The difference is significant and around 3.30 drinks per week.

  9. Weekday Bedtime and Stress: Students with high stress levels don’t go to bed significantly later than those with normal stress levels, according to the data.

  10. Weekend Sleep Duration and Class Year: There’s no notable difference in weekend sleep duration between underclassmen (years 1–2) and upperclassmen (years 3–4).

Overall, this project gave us some valuable insights into how different lifestyle habits, sleep patterns, and academic outcomes are connected. The findings could help shape university policies aimed at boosting student well-being and academic success. They also open the door for future research into other aspects that might be influencing students’ experiences and performance.

REFERENCES

Lock, R., Lock, P., Morgan, K., Lock, E., & Lock, D. (2020). SleepStudy [Dataset]. https://www.lock5stat.com/datapage3e.html

Lock, R., Lock, P., Morgan, K., Lock, E., & Lock, D. (2020). Dataset documentaton for the third edition of “Statistics: UnLocking the Power of Data.” Wiley. https://www.lock5stat.com/datasets3e/Lock5DataGuide3e.pdf