2026-10-14

Question

Sleep is one of the most essential components to human health; however, with the rise of technologies such as screens, getting a healthy amount of sleep is becoming harder and harder. Thus, I seek to answer the following question, “How much do modern adults sleep?” and “What are some factors that contribute or don’t contribute to sleep?”

Used Data-set

I plan to use this dataset from Kaggle – “Sleep Health and Lifestyle” by Ibrahim Elgmmal. This dataset involves ~374 observations and includes fields like Age, Sleep Duration, Sleep quality, BMI, ect.

First Statistical Idea

For my first statistical idea, I’d like to create a 95% confidence interval for the mean Sleep Duration. The reason for calculating the confidence interval is because just calcualting the sample mean isn’t enough. There is a good chance that the population mean could be widly differenct. On the other hand, confidence intervals help us get a good idea of what the population mean will be.

Confidence Interval Example

For instance, if we calculate a 95% confidence interval for Sleep Duration and the result was (7, 7.5), it means that there is a good chance the population’s mean sleep duration is a value between (7, 7.5). It would be best to use T distribution because it tests for mean with an unknown variance.

95% T Confidence Interval of Sleep Duration

T confidence interval = \(\bar{x} \pm t_{\alpha/2}(\frac{s}{\sqrt{n}} )\).

\(\bar{x}\) – sample mean

\(t\) – T distribution

\(s\) – sample standard deviation

\(n\) – number of samples

RT Confidence Interval Calculation Code

## [1] 7.051185 7.212986
## attr(,"conf.level")
## [1] 0.95

I am 95% confident that the true population of sleep duration is [7.051185, 7.212986]. This includes people with sleep disorders like sleep apnea.

T Confidence Interval of Sleep Duration When Filtering Sleep Disorders

sleep_data %>% filter(Sleep.Disorder == "None") %>% select("Sleep.Duration") %>% drop_na("Sleep.Duration") %>% (function(x){t.test(x)$conf.int})()
## [1] 7.260916 7.455979
## attr(,"conf.level")
## [1] 0.95

When filtering for people without sleep disorders, I’m 95% confident that the true population mean of sleep duration is [7.26016, 7.455979].

Sleep Duration Insights

According to the National Sleep Foundation, an adult should get ~7-9 hours of sleep. Our analysis reveals a 95% confidence of the population average sleep duration to be between 7.26016 and 7.455979 when excluding people with sleep disorders.

Even when including people with sleep disorders, our population should still get an acceptable amount of sleep – [7.051185, 7.212986].

Therefore, despite the amount of distractions in modern life (screens, social media, lights, ect) people are getting an ok amount of sleep.

Second Statistical Idea

For my second statiscal idea, I’d like to calculate the Pearson Correlation R score for Age and Physical Activity Level against Sleep Duration to see whether any of these factors have a clear, linear correlation with Sleep Duration. This metric helps establish any linear relationships between these factors and it measures how strong these relationships are. It helps answer questions such as “as people age, do they tend to sleep less or more?”

I’d also like to build a boxchart for Occupation because since Occupation is nominal data, doing linear correlation testing on it makes no sense. On the other hand, a boxplot should show the distributions of sleep quite nicely.

Explaination and Example of Pearson R Correlation Score

An R score will have a range of -1 and 1. -1 being that the variables have a strong negative correlation and 1 being that the the variables have a strong positive correlation. Only a score below -0.7 or above 0.7 will indicate a strong relationship between these two variables.

For instance, if it has been found that the components Age and Sleep duration have an R score of 0.7, it means that as age increases, Sleep duration will significantly increase as well. However, if the R score was close to 0.5, then there is a slight positive relationship between Age and Sleep Duration, but the relationship isn’t that strong.

Pearson R Correlation Formula

Pearson R correlation = \(\frac{\sum (x-\bar{x}) - \sum (y-\bar{y})}{\sqrt{\sum (x-\bar{x})^{2}} \sqrt{\sum (y - \bar{y})^{2}}}\)

x – first variable

\(\bar{x}\) – sample mean of first variable

y – second variable

\(\bar{y}\) – sample mean of second variable

R Scores for Age, Occupation, and Physical Activity Level vs Sleep Duration

R Score for Age vs Sleep Duration

##       cor 
## 0.3447094
## [1] 7.11714e-12

R Score for Physical Activity Level vs Sleep Duration

##       cor 
## 0.2123603
## [1] 3.466618e-05

It seems that there is some relationships between these variables. Both Age and Physical Activity Levels seem to positively correlate with sleep duration. However, the strength of these relationships aren’t that strong. Just to confirm these relationships, let’s create a few scatter plots.

Age vs Sleep Duration

There is something, but this relationship indeed doesn’t seem that strong.

Physical Actvity Level vs Sleep Duration

The linear correlation is a bit stronger. I guess those outliers messed up the R score calculation badly.

Interactive Occupation vs Sleep Duration Boxplot

This plot reveals some interesting material.

It seems that some Occupations that do recieve good sleep are Accountants, Engineeriers, and Lawyers. (Since all of those Occupations consistently have their sleep ranges above 7 hours).

However, if you are a scientist, Teacher, Manager, Sales Rep, Salesperson, and more than half of nurses & software engineers have subpotimal sleep.

Insights and Conclusion

From these tests, we learned that it is very likely that the average population are getting an acceptable amount of sleep (since the confidence intervals are above the minimally recommend 7 hours).

Based on the r correlation analyses and graphs, it seems like that physical activity and age both have a weak but definite positive linear correlation with sleep duration.

Lastly, according to the boxplot, becoming a scientist, teacher, manager, sales rep, salesperson, nurses, or software engineer will have a high chance of compromising your sleep. If sleep is something you’d rather not sacrifice, stick to being an accountant, engineeriers, and lawyer.