library(mosaic)library(DT)library(pander)library(car)library(tidyverse)library(lattice)library(dplyr)# Record your data from your own mini experiment in Excel.# Save the data as a .csv file in the Data folder of the Statistics-Notebook.aovsleep <-read_csv("../../data/aovsleep.csv")
I have been tracking my sleep for months using the app AutoSleep and my apple watch. I downloaded my sleep data from July 26th to October 24th 2024. I wanted to put together a comparison of my sleep in the summer vs during school. I split the days that I was home for the summer (July 26th - September 12th) and the school (September 13th - October 24th).
I will be comparing how in the summer vs during school affects my total sleep hours as well as looking at sleep sessions (essentially if I took a nap or not) and how that affected my overall sleep hours. Sleep sessions hours are added to the total hours for the day automatically by AutoSleep.
I’ve listed all 89 tracked sleep days below.
August 10th is missing because I didn’t wear my watch to bed that day.
H_a: \text{The average number sleep hours differs depending of the number of sleep sessions}
(3)
H_0: \text{The effect of sleep session on the average number of sleep hours is consistent across both seasons.}
H_a: \text{The effect of sleep session on the average number of sleep hours differs across the seasons.}
Significance level is
\alpha = 0.05
Show the code
sleep.aov <-aov(as.numeric(asleep)/3600~ SEASON + sessions + SEASON:sessions, MySleepANOVA)summary(sleep.aov) %>%pander()
Analysis of Variance Model
Df
Sum Sq
Mean Sq
F value
Pr(>F)
SEASON
1
0.04393
0.04393
0.01866
0.8917
sessions
1
1.176
1.176
0.4998
0.4815
SEASON:sessions
1
13.58
13.58
5.769
0.01849
Residuals
85
200.1
2.354
NA
NA
The ANOVA test tells us what differences in the means are significant between groups. This two-way ANOVA shows us the comparisons of seasons and sleep sessions on average sleep hours and helps us determine if one group’s mean differs.
The ANOVA shows us the degrees of freedom per group. Because both ‘SEASON’ and ‘sessions’ have only 2 groups the degrees of freedom are 1 each, as is the combination of the two labeled as SEASON:sessions. The residuals are 85 because we have 89 days to observe and that is total - 1 - degrees of freedom.
In comparing Summer and School sleep we don’t see a difference in the average sleep hours, showing that I’ve gotten about the same sleep in the summer as well as while attending school. The low F-Statisitc backs this claim in the high p-value.
We also don’t see a difference in average sleep hours for when I have or haven’t had a nap (sleep sessions). F-value is low and the p-value is high.
We see that the only significant p-value is the combined season and sleep session showing the most impact of the average sleep hours. The F-value of 5.77 coupled with the p-value of 0.0185 helps us determine the significance.
Let’s look into the graphs to see the variance in the data.
Show the code
xyplot(( as.numeric(asleep) /3600) ~as.factor(SEASON), data = MySleepANOVA, type =c("p", "a"),main="Hours of Sleep in the Summer vs Fall(In School)",ylab="Sleep Hours", xlab="Season")
We see barely a difference in the means of School and Summer. There is only a 0.045 difference in the means as shown in the above graph and numerical summary.
Show the code
xyplot(( as.numeric(asleep) /3600) ~as.factor(sessions), data = MySleepANOVA, type =c("p", "a"),main ="Across 89 Days of Sleep: Sleep Sessions and Hours", ylab ="Sleep Hours", xlab ="Sleep Sessions per Day")
We see a slightly steeper drop in the means of 1 sleep session, average is 7.529 and 2 sleep sessions, average is 7.291. That is a 0.238 difference in the means.
Show the code
xyplot(( as.numeric(asleep) /3600) ~as.factor(sessions), data = MySleepANOVA, groups=SEASON, type=c("p","a"), auto.key=TRUE, main="How Naps Affect Sleep in Summer vs During School", ylab="Sleep Hours", xlab="Sleep Sessions Per Day")
This graph show the significance of the combined factors season and sleep sessions.
Show the code
summersleepaov <-filter(MySleepANOVA, SEASON =="Summer")
The difference in the mean sleep hours during School for when I had 2 sessions of sleep is significantly different than the Summer hours. We see here that instead of average hours increasing with a nap, they actually decreased. Average sleep hours with a nap are 6.19 and without one is 7.695. That’s the most drastic difference we have seen– a difference of more than 1 hour average.
The residuals vs fitted values plot is not as appropriate as I would like since the values are showing some spread but not enough to invalidate the test.
The normality of the error terms as shown in the Q-Q Plot can be determined to be satisfied. Overall the results of the test can be considered valid.
Interpretation
There is no statistical significance in comparing Summer sleep hours and School sleep hours directly \alpha < 0.892. There is also no significant difference in sleep hours depending on if I took a nap or not \alpha < 0.482.
However we do see sufficient evidence to conclude that when I took a nap in the Summer I had more sleep that day than when I took a nap on a School day \alpha > 0.0185.
I believe that largely has to do with the abundance of time I had in the summer so naps were more frequent and luxurious whereas my naps during school are out of necessity because I was up doing assignments the night before and staying up late. When I had a nap in the summer my average sleep was 7.72 hours in a day. The school naps were more to catch up to a normal sleep range not to exceed it. So the average sleep was only 6.2 hours when I napped during school.
The best bet for me while I’m in Rexburg, attending Brigham Young University - Idaho, is to get my full night’s rest during the evening and not rely on a nap to refuel me.