This commit is contained in:
2025-12-25 22:23:02 -04:00
parent 0aea8b7053
commit e2b6dced0a
3 changed files with 212 additions and 1 deletions

View File

@@ -2,7 +2,7 @@
title: "Assignment 5"
subtitle: "STAT3373"
author: "Isaac Shoebottom"
date: "Oct 23th, 2025"
date: "Oct 23rd, 2025"
output:
pdf_document: default
html_document:

150
HW6.Rmd Normal file
View File

@@ -0,0 +1,150 @@
---
title: "Assignment 6"
subtitle: "STAT3373"
author: "Isaac Shoebottom"
date: "Oct 30th, 2025"
output:
pdf_document: default
html_document:
df_print: paged
---
```{r setup, include=FALSE}
library(tidyverse)
library(knitr)
library(emmeans)
library(effectsize)
```
```{r load-data, include=FALSE}
# Create the dataset
sleep_data <- read_csv("sleep_study_data.csv")
# Convert to factors
sleep_data <- sleep_data %>%
mutate(
Sleep = factor(Sleep, levels = c("Normal", "Deprived")),
Caffeine = factor(Caffeine, levels = c("None", "100mg", "200mg")),
Subject = factor(Subject)
)
```
## Introduction
This study investigates how sleep deprivation and caffeine consumption affect cognitive performance as measured by reaction time. Sleep deprivation is known to impair cognitive function, while caffeine is commonly used to counteract fatigue-related performance decrements. The research question asks whether caffeine can mitigate the negative effects of sleep deprivation on reaction time. We hypothesize that sleep-deprived participants will show slower reaction times than those with normal sleep, caffeine will improve reaction times in a dose-dependent manner, and there will be an interaction such that caffeine's benefits are more pronounced in the sleep-deprived condition. Understanding these effects has practical implications for shift workers, students, and others who may experience sleep restriction.
## Methods
This study employed a 2 × 3 within-subjects factorial design with sleep condition (Normal vs. Deprived) and caffeine dose (None, 100mg, 200mg) as independent variables. Ten participants completed all six experimental conditions, providing reaction time measurements under each combination of sleep and caffeine levels. This repeated measures design controls for individual differences in baseline reaction time and increases statistical power. The dependent variable was reaction time measured in milliseconds. Data were analyzed using a two-way repeated measures ANOVA to examine main effects of sleep and caffeine, as well as their interaction. Effect sizes were calculated using partial eta squared, and post-hoc pairwise comparisons were conducted using estimated marginal means with Bonferroni correction to control for multiple comparisons.
## Results
### Descriptive Statistics
```{r descriptive-stats}
desc_stats <- sleep_data %>%
group_by(Sleep, Caffeine) %>%
summarise(
N = n(),
Mean = mean(ReactionTime),
SD = sd(ReactionTime),
SE = sd(ReactionTime) / sqrt(n()),
.groups = "drop"
)
kable(desc_stats, digits = 2,
caption = "Table 1. Descriptive Statistics for Reaction Time (ms) by Sleep Condition and Caffeine Dose")
```
Descriptive statistics reveal clear patterns in the data. Participants in the sleep-deprived condition with no caffeine showed the slowest mean reaction times (M = 315.05 ms, SD = 23.00), while those with normal sleep and 200mg caffeine showed the fastest times (M = 226.19 ms, SD = 19.20). Within the normal sleep condition, reaction times decreased as caffeine dose increased, suggesting a dose-response relationship. In the sleep-deprived condition, both caffeine doses appeared to improve reaction times compared to no caffeine, though the pattern differs somewhat from the normal sleep condition.
### ANOVA Results
```{r anova-analysis}
# Create ANOVA table
anova_table <- aov(ReactionTime ~ Sleep * Caffeine, data = sleep_data)
summary(anova_table)
```
### Interaction Plot
```{r interaction-plot, fig.width=8, fig.height=5}
sleep_data %>%
group_by(Sleep, Caffeine) %>%
summarise(
Mean_RT = mean(ReactionTime),
SE = sd(ReactionTime) / sqrt(n()),
.groups = "drop"
) %>%
ggplot(aes(x = Caffeine, y = Mean_RT, color = Sleep, group = Sleep)) +
geom_line(size = 1.2) +
geom_point(size = 3) +
geom_errorbar(aes(ymin = Mean_RT - SE, ymax = Mean_RT + SE),
width = 0.1, size = 0.8) +
labs(
title = "Interaction Between Sleep Condition and Caffeine Dose on Reaction Time",
x = "Caffeine Dose",
y = "Mean Reaction Time (ms)",
color = "Sleep Condition"
) +
theme_minimal(base_size = 12) +
theme(
legend.position = "top",
plot.title = element_text(hjust = 0.5, face = "bold")
) +
scale_color_manual(values = c("Normal" = "#2E86AB", "Deprived" = "#A23B72"))
```
The interaction plot illustrates the differential effects of caffeine across sleep conditions. In the normal sleep condition, reaction times show a consistent decrease with increasing caffeine dose, demonstrating a clear dose-response relationship. However, in the sleep-deprived condition, the pattern is more complex. While both caffeine doses improve reaction times compared to no caffeine, the 200mg dose does not show additional benefit over the 100mg dose in sleep-deprived participants, and in some cases may show slightly worse performance. This suggests that caffeine's effectiveness may be modulated by sleep status, with potential ceiling effects or different mechanisms at play when combating sleep deprivation.
### Post-Hoc Comparisons
```{r posthoc-tests}
# Fit model for emmeans
model <- aov(ReactionTime ~ Sleep * Caffeine + Error(Subject/(Sleep * Caffeine)),
data = sleep_data)
# Calculate estimated marginal means
emm <- emmeans(model, ~ Caffeine | Sleep)
# Pairwise comparisons within each sleep condition
posthoc <- pairs(emm, adjust = "bonferroni")
# Display results
kable(summary(posthoc), digits = 2,
caption = "Table 3. Post-Hoc Pairwise Comparisons with Bonferroni Correction")
```
Post-hoc pairwise comparisons with Bonferroni correction examined differences between caffeine doses within each sleep condition. In the normal sleep condition, all pairwise comparisons were significant, confirming that each increase in caffeine dose led to faster reaction times. In the sleep-deprived condition, both 100mg and 200mg caffeine significantly improved reaction times compared to no caffeine, but the difference between 100mg and 200mg was not significant, supporting the observation from the interaction plot that higher caffeine doses may not provide additional benefits for sleep-deprived individuals.
### Assumption Checking
```{r assumptions, fig.width=10, fig.height=4}
# Create residuals for checking assumptions
sleep_data <- sleep_data %>%
group_by(Subject) %>%
mutate(residual = ReactionTime - mean(ReactionTime)) %>%
ungroup()
# Check normality and homogeneity
par(mfrow = c(1, 2))
# Q-Q plot
qqnorm(sleep_data$residual, main = "Normal Q-Q Plot")
qqline(sleep_data$residual, col = "red")
# Residuals vs Fitted
plot(fitted(lm(ReactionTime ~ Sleep * Caffeine, data = sleep_data)),
residuals(lm(ReactionTime ~ Sleep * Caffeine, data = sleep_data)),
xlab = "Fitted Values", ylab = "Residuals",
main = "Residuals vs Fitted Values")
abline(h = 0, col = "red", lty = 2)
```
Assumption checking indicated that the data met the requirements for repeated measures ANOVA. The Q-Q plot shows that residuals follow an approximately normal distribution, with only minor deviations at the tails. The residuals versus fitted values plot demonstrates homogeneity of variance, with no clear pattern of increasing or decreasing spread across fitted values. While sphericity cannot be formally tested with this small sample size, the use of within-subjects contrasts and the balanced design minimize concerns about sphericity violations.
## Discussion
This study demonstrates that both sleep deprivation and caffeine significantly affect reaction time performance, with a notable interaction between these factors. Sleep deprivation substantially impaired reaction time, increasing it by approximately 50-60 milliseconds on average across caffeine conditions, representing a large effect. Caffeine improved performance in both sleep conditions, but its effects were not uniform. In well-rested individuals, caffeine showed a clear dose-response relationship with progressively faster reaction times at higher doses. However, in sleep-deprived participants, while caffeine provided benefit compared to no caffeine, the additional benefit of 200mg versus 100mg was minimal or absent. This suggests that caffeine may partially compensate for sleep deprivation but cannot fully restore performance to normal levels, and higher doses do not necessarily provide proportionally greater benefits when fighting significant sleep debt.
The practical implications of these findings are significant for individuals who experience sleep restriction. While moderate caffeine consumption (100mg, equivalent to a cup of coffee) can help mitigate some performance deficits from sleep deprivation, it is not a complete substitute for adequate sleep. The lack of additional benefit from higher caffeine doses in sleep-deprived individuals suggests that consuming excessive caffeine may not be an effective strategy and could potentially lead to side effects without performance gains. Several limitations should be noted, including the relatively small sample size, which limits generalizability and statistical power for detecting smaller effects. The study examined only acute sleep deprivation and caffeine administration, so results may not apply to chronic sleep restriction or regular caffeine users who may have developed tolerance. Future research should examine longer-term effects, individual differences in caffeine metabolism, and optimal timing of caffeine consumption relative to sleep deprivation. Additionally, investigating other cognitive domains beyond reaction time would provide a more comprehensive understanding of how these factors interact to affect human performance.

61
sleep_study_data.csv Normal file
View File

@@ -0,0 +1,61 @@
"Sleep","Caffeine","Subject","ReactionTime"
"Normal","None",1,243.479270189692
"Deprived","None",1,296.516550611321
"Normal","100mg",1,217.172848918367
"Deprived","100mg",1,276.270319081112
"Normal","200mg",1,233.694566672636
"Deprived","200mg",1,220.723062449291
"Normal","None",2,262.375797112519
"Deprived","None",2,314.657237798962
"Normal","100mg",2,228.84700503035
"Deprived","100mg",2,249.777465115373
"Normal","200mg",2,209.337312518334
"Deprived","200mg",2,232.441784706374
"Normal","None",3,278.555110893661
"Deprived","None",3,329.096636629335
"Normal","100mg",3,193.621309984041
"Deprived","100mg",3,244.216972805153
"Normal","200mg",3,260.673434102618
"Deprived","200mg",3,297.77092508121
"Normal","None",4,233.646592882481
"Deprived","None",4,319.344191499424
"Normal","100mg",4,267.042951498605
"Deprived","100mg",4,235.657858264616
"Normal","200mg",4,196.762329617565
"Deprived","200mg",4,246.150178800807
"Normal","None",5,264.888716457506
"Deprived","None",5,342.362919227679
"Normal","100mg",5,230.107742443436
"Deprived","100mg",5,269.44874787542
"Normal","200mg",5,220.214681619845
"Deprived","200mg",5,257.076901976025
"Normal","None",6,267.898744010808
"Deprived","None",6,265.808257981048
"Normal","100mg",6,222.779732046845
"Deprived","100mg",6,280.000043414122
"Normal","200mg",6,216.948265744512
"Deprived","200mg",6,286.635818194215
"Normal","None",7,253.359675446978
"Deprived","None",7,318.002583666337
"Normal","100mg",7,239.949086765898
"Deprived","100mg",7,230.800275955484
"Normal","200mg",7,225.762329493388
"Deprived","200mg",7,212.679308079376
"Normal","None",8,203.61345262065
"Deprived","None",8,339.881783766594
"Normal","100mg",8,244.935219785195
"Deprived","100mg",8,233.218476766426
"Normal","200mg",8,209.386311200154
"Deprived","200mg",8,228.10390119537
"Normal","None",9,244.198187483689
"Deprived","None",9,307.064517887345
"Normal","100mg",9,218.641581481219
"Deprived","100mg",9,305.311347985939
"Normal","200mg",9,239.272057986283
"Deprived","200mg",9,271.555261528439
"Normal","None",10,264.981154323296
"Deprived","None",10,308.327652914815
"Normal","100mg",10,217.386360337846
"Deprived","100mg",10,288.633218997471
"Normal","200mg",10,249.87468789708
"Deprived","200mg",10,209.761549340762
1 Sleep Caffeine Subject ReactionTime
2 Normal None 1 243.479270189692
3 Deprived None 1 296.516550611321
4 Normal 100mg 1 217.172848918367
5 Deprived 100mg 1 276.270319081112
6 Normal 200mg 1 233.694566672636
7 Deprived 200mg 1 220.723062449291
8 Normal None 2 262.375797112519
9 Deprived None 2 314.657237798962
10 Normal 100mg 2 228.84700503035
11 Deprived 100mg 2 249.777465115373
12 Normal 200mg 2 209.337312518334
13 Deprived 200mg 2 232.441784706374
14 Normal None 3 278.555110893661
15 Deprived None 3 329.096636629335
16 Normal 100mg 3 193.621309984041
17 Deprived 100mg 3 244.216972805153
18 Normal 200mg 3 260.673434102618
19 Deprived 200mg 3 297.77092508121
20 Normal None 4 233.646592882481
21 Deprived None 4 319.344191499424
22 Normal 100mg 4 267.042951498605
23 Deprived 100mg 4 235.657858264616
24 Normal 200mg 4 196.762329617565
25 Deprived 200mg 4 246.150178800807
26 Normal None 5 264.888716457506
27 Deprived None 5 342.362919227679
28 Normal 100mg 5 230.107742443436
29 Deprived 100mg 5 269.44874787542
30 Normal 200mg 5 220.214681619845
31 Deprived 200mg 5 257.076901976025
32 Normal None 6 267.898744010808
33 Deprived None 6 265.808257981048
34 Normal 100mg 6 222.779732046845
35 Deprived 100mg 6 280.000043414122
36 Normal 200mg 6 216.948265744512
37 Deprived 200mg 6 286.635818194215
38 Normal None 7 253.359675446978
39 Deprived None 7 318.002583666337
40 Normal 100mg 7 239.949086765898
41 Deprived 100mg 7 230.800275955484
42 Normal 200mg 7 225.762329493388
43 Deprived 200mg 7 212.679308079376
44 Normal None 8 203.61345262065
45 Deprived None 8 339.881783766594
46 Normal 100mg 8 244.935219785195
47 Deprived 100mg 8 233.218476766426
48 Normal 200mg 8 209.386311200154
49 Deprived 200mg 8 228.10390119537
50 Normal None 9 244.198187483689
51 Deprived None 9 307.064517887345
52 Normal 100mg 9 218.641581481219
53 Deprived 100mg 9 305.311347985939
54 Normal 200mg 9 239.272057986283
55 Deprived 200mg 9 271.555261528439
56 Normal None 10 264.981154323296
57 Deprived None 10 308.327652914815
58 Normal 100mg 10 217.386360337846
59 Deprived 100mg 10 288.633218997471
60 Normal 200mg 10 249.87468789708
61 Deprived 200mg 10 209.761549340762