1 Context

Sleep is important for a variety of reasons. Sleep, like breathing, eating, and drinking, is a basic human requirement. Sleep also helps in human development. As a result, infants, children, and teenagers require more sleep than adults. People of all ages require sleep to stay healthy or to recover from illness or injury.

While work schedules and stress can affect sleep, the opposite is true as well. If you’ve ever nodded off at your desk or during an important meeting, you know that sleep loss can have a detrimental impact on work performance. Sleep deprivation can leave you feeling tired, less creative, and make it more difficult to stay focused on important projects. Sacrificing sleep for work, then working more to make up for lost productivity can become an exhausting cycle.

While the National Sleep Foundation recommends that most adults need around 7 to 9 hours of sleep, almost one-third of Americans get less than 6 hours of sleep each night according to the Centers for Disease Control (CDC). This fatigue inevitably bleeds into the workplace and a 2007 study of U.S. workers found that almost 38% of employees experienced fatigue while at work during the previous two weeks.

Sleep deprivation and poor sleep quality can have a wide range of negative consequences. These can be physiological in nature, such as an increased risk of stroke, heart disease, or high blood pressure. Negative psychological effects include increased irritability and the development of anxiety or depression. A lack of quality sleep can even jeopardize your or others’ safety. Driving while sleep deprived, for example, can result in an accident, injury, or even death.

2 Sleep Quality Parameters

When it comes to sleep, quantity is important—but so is quality. Most adults need somewhere between seven and nine hours a night to wake up feeling well-rested, but a lot depends on exactly what happens during those hours. The quality of your sleep ensures that you get the essential physical, mental, and emotional benefits you need from your sleep.

Sleep quality is the measurement of how well you’re sleeping—in other words, whether your sleep is restful and restorative. It differs from sleep satisfaction, which refers to a more subjective judgment of how you feel about the sleep you are getting. Sleep quality is more complicated to measure than sleep quantity, but it’s not entirely subjective. Guidelines give an overview of sleep quality goals, and they include some individual and age differences. Four items are generally assessed to measure sleep quality:

2.1 Sleep Latency

This is a measurement of how long it takes you to fall asleep. Drifting off within 30 minutes or less after the time you go to bed suggests that the quality of your sleep is good.

2.2 Sleep Waking and Wakefulness

This measures how often you wake up during the night. Frequent wakefulness at night can disrupt your sleep cycle and reduce your sleep quality. Waking up once or not at all suggests that your sleep quality is good.

While wakefulness refers to how many minutes you spend awake during the night after you first go to sleep. People with good sleep quality have 20 minutes or less of wakefulness during the night.

2.3 Sleep Efficiency

The amount of time you spend actually sleeping while in bed is known as sleep efficiency. This measurement should ideally be 85 percent or more for optimal health benefits.

3 Sleep Stages

Sleep happens in stages, including REM sleep and non-REM sleep. During the night, you cycle through these two types of sleep. Your brain and body act differently during these different phases.

REM stands for rapid eye movement. During REM sleep, your eyes move around rapidly in a range of directions, but don’t send any visual information to your brain.That doesn’t happen during non-REM sleep. First comes non-REM sleep, followed by a shorter period of REM sleep, and then the cycle starts over again. Dreams typically happen during REM sleep.

3.1 NREM stage

There are three phases of non-REM sleep. Each stage can last from 5 to 15 minutes. You go through all three phases before reaching REM sleep.

  1. Stage 1: Your eyes are closed, but it’s easy to wake you up. This phase may last for 5 to 10 minutes.

  2. Stage 2: You are in light sleep. Your heart rate slows and your body temperature drops. Your body is getting ready for deep sleep. This can last for 10-25 minutes.

  3. Stages 3: This is the deep sleep stage. It’s harder to rouse you during this stage, and if someone woke you up, you would feel disoriented for a few minutes.

During the deep stages of NREM sleep, the body repairs and regrows tissues, builds bone and muscle, and strengthens the immune system. As you get older, you sleep more lightly and get less deep sleep. Aging is also linked to shorter time spans of sleep, although studies show you still need as much sleep as when you were younger.

3.2 REM Stage

Usually, REM sleep happens 90 minutes after you fall asleep. The first period of REM typically lasts 10 minutes. Each of your later REM stages gets longer, and the final one may last up to an hour. Your heart rate and breathing quickens. You can have intense dreams during REM sleep, since your brain is more active. REM is important because it stimulates the areas of the brain that help with learning and is associated with increased production of protein.

In this study, we will analyze the observation result of our sleeping study participants and see the correlation between their biological profile (Age, Gender), sleeping habits (bedtime, wakeup time, sleeping duration, awakenings), and health profile (alcohol, cigarette, and caffeine consumption, as well as their exercise routine) to their sleeping quality (Sleeping Efficiency, Deep Sleep & REM Sleep Percentage).

Dataset used for this report is sourced from Kaggle.

Now that we have enough context on our topic of study, let’s start with the Data Analysis process!

4 Data Preparation

First we read the Sleep_Efficiency dataset downloaded from Kaggle our which contain total of 452 rows (observation results) and 15 columns (observation variables), as displayed below.

## Rows: 452
## Columns: 15
## $ ID                     <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, …
## $ Age                    <int> 65, 69, 40, 40, 57, 36, 27, 53, 41, 11, 50, 55,…
## $ Gender                 <chr> "Female", "Male", "Female", "Female", "Male", "…
## $ Bedtime                <chr> "2021-03-06 01:00:00", "2021-12-05 02:00:00", "…
## $ Wakeup.time            <chr> "2021-03-06 07:00:00", "2021-12-05 09:00:00", "…
## $ Sleep.duration         <dbl> 6.0, 7.0, 8.0, 6.0, 8.0, 7.5, 6.0, 10.0, 6.0, 9…
## $ Sleep.efficiency       <dbl> 0.88, 0.66, 0.89, 0.51, 0.76, 0.90, 0.54, 0.90,…
## $ REM.sleep.percentage   <int> 18, 19, 20, 23, 27, 23, 28, 28, 28, 18, 23, 18,…
## $ Deep.sleep.percentage  <int> 70, 28, 70, 25, 55, 60, 25, 52, 55, 37, 57, 60,…
## $ Light.sleep.percentage <int> 12, 53, 10, 52, 18, 17, 47, 20, 17, 45, 20, 22,…
## $ Awakenings             <dbl> 0, 3, 1, 3, 3, 0, 2, 0, 3, 4, 1, 0, 0, 4, 2, 0,…
## $ Caffeine.consumption   <dbl> 0, 0, 0, 50, 0, NA, 50, 50, 50, 0, 50, 0, 50, 0…
## $ Alcohol.consumption    <dbl> 0, 3, 0, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2,…
## $ Smoking.status         <chr> "Yes", "Yes", "No", "Yes", "No", "No", "Yes", "…
## $ Exercise.frequency     <dbl> 3, 3, 3, 1, 3, 1, 1, 3, 1, 0, 3, 3, 1, 3, 0, 5,…
List of Variables
variable_names description
id a unique identifier for each test subject
Age age of the test subject
Gender Male or Female
Bedtime the time the test subject goes to bed each night
Wakeup Time the time the test subject wakes up each morning
Sleep Duration the total amount of time the test subject slept in hours
Sleep Efficiency a measure of the proportion of time in bed spent asleep
REM Sleep Percentage the percentage of total sleep time spent in REM sleep
Deep Sleep Percentage the percentage of total sleep time spent in deep sleep
Light Sleep Percentage the percentage of total sleep time spent in light sleep
Awakenings the number of times the test subject wakes up during the night
Caffeine Consumption the amount of caffeine consumed in the 24 hours prior to bedtime in mg
Alcohol Consumption the amount of alcohol consumed in the 24 hours prior to bedtime in oz
Smoking Status whether or not the test subject smokes
Exercise Frequency the number of times the test subject exercises each week

Then we might notice several columns are not in the correct data type, hence we will convert the following columns into the correct data types:

  1. Bedtime, Wakeup.time to Date Time using `lubridate``package
  2. Gender, Smoking.status to data tyoe factor
  3. Create column called age_category which classify Age into age group with the following criteria based on this criteria mentioned here
    • Age < 13 : Children
    • Age 13 to 17 : Teenagers
    • Age 17 to 44 : Young Age
    • Age 44 to 60 : Middle Age
    • Age 60+ : Elderly
## Rows: 452
## Columns: 18
## $ ID                     <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, …
## $ Age                    <int> 65, 69, 40, 40, 57, 36, 27, 53, 41, 11, 50, 55,…
## $ Gender                 <fct> Female, Male, Female, Female, Male, Female, Fem…
## $ Bedtime                <dttm> 2021-03-06 01:00:00, 2021-12-05 02:00:00, 2021…
## $ bedtime_h              <int> 1, 2, 21, 2, 1, 21, 21, 0, 2, 1, 0, 22, 2, 1, 1…
## $ Wakeup.time            <dttm> 2021-03-06 07:00:00, 2021-12-05 09:00:00, 2021…
## $ wakeup_h               <int> 7, 9, 5, 8, 9, 4, 3, 10, 8, 10, 8, 6, 11, 9, 10…
## $ Sleep.duration         <dbl> 6.0, 7.0, 8.0, 6.0, 8.0, 7.5, 6.0, 10.0, 6.0, 9…
## $ Sleep.efficiency       <dbl> 0.88, 0.66, 0.89, 0.51, 0.76, 0.90, 0.54, 0.90,…
## $ REM.sleep.percentage   <int> 18, 19, 20, 23, 27, 23, 28, 28, 28, 18, 23, 18,…
## $ Deep.sleep.percentage  <int> 70, 28, 70, 25, 55, 60, 25, 52, 55, 37, 57, 60,…
## $ Light.sleep.percentage <int> 12, 53, 10, 52, 18, 17, 47, 20, 17, 45, 20, 22,…
## $ Awakenings             <dbl> 0, 3, 1, 3, 3, 0, 2, 0, 3, 4, 1, 0, 0, 4, 2, 0,…
## $ Caffeine.consumption   <dbl> 0, 0, 0, 50, 0, NA, 50, 50, 50, 0, 50, 0, 50, 0…
## $ Alcohol.consumption    <dbl> 0, 3, 0, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2,…
## $ Smoking.status         <fct> Yes, Yes, No, Yes, No, No, Yes, Yes, No, No, Ye…
## $ Exercise.frequency     <fct> 3, 3, 3, 1, 3, 1, 1, 3, 1, 0, 3, 3, 1, 3, 0, 5,…
## $ age_category           <fct> elderly, elderly, young age, young age, middle …

After that, we continue to check the missing values and decide what kind of treatment needed to those missing values, and duplicates (if any).

#check missing values and duplicate

sleep_02 %>% is.na() %>% colSums()  
##                     ID                    Age                 Gender 
##                      0                      0                      0 
##                Bedtime              bedtime_h            Wakeup.time 
##                      0                      0                      0 
##               wakeup_h         Sleep.duration       Sleep.efficiency 
##                      0                      0                      0 
##   REM.sleep.percentage  Deep.sleep.percentage Light.sleep.percentage 
##                      0                      0                      0 
##             Awakenings   Caffeine.consumption    Alcohol.consumption 
##                     20                     25                     14 
##         Smoking.status     Exercise.frequency           age_category 
##                      0                      6                      0
sleep_02 %>% duplicated() %>% sum()
## [1] 0

Using is.na() and duplicated() function, we can see that we have missing values at Awakenings, Caffeine.consumption and Alcohol.consumption columns with no duplicated row. Knowing that the missing values are less than 10% of the total rows, we can eliminate those values using drop.na() function. The final dataset then saved into an object called sleep_cln.

#drop missing values

sleep_cln <- sleep_02 %>% drop_na()  
sleep_cln %>% is.na() %>% colSums()
##                     ID                    Age                 Gender 
##                      0                      0                      0 
##                Bedtime              bedtime_h            Wakeup.time 
##                      0                      0                      0 
##               wakeup_h         Sleep.duration       Sleep.efficiency 
##                      0                      0                      0 
##   REM.sleep.percentage  Deep.sleep.percentage Light.sleep.percentage 
##                      0                      0                      0 
##             Awakenings   Caffeine.consumption    Alcohol.consumption 
##                      0                      0                      0 
##         Smoking.status     Exercise.frequency           age_category 
##                      0                      0                      0

And finally, we get our final cleansed dataset:

5 Participant Profiles

5.1 Participant Profiles based on Age Group & Gender

The age of participants involved in this study range from 9 to 69 years old, with Female participants majority came from 20 - 30 age range while the majority of male participants are in their 50-is. In general, the participants list are dominated by people from Young Age and Middle Age group, or from 17 to 60 years old.

5.2 Participant Profiles based on Sleeping Habit

Sleeping habits observed in this study are: - Bedtime - Wakeup time - Sleep Duration - Median of Percentage on each Sleep Stage

Based on our observation, our test subjects are most likely to go to bed at 01:00 or 21:00 for both gender, and slightly different wake up time for Female & Male participants. The female ones tend to wake up at 05:00 or 8:00 while the Male participants at 05:00, 07:00 or 08:30. Despite slight difference in wake up time, the overall sleep duration are similar for both gender, with most participants sleeps for 7 - 8 hours long.

During that 7 - 8 hours duration, our participants spend most of their sleeping-time in Deep Sleep stage (more than 50%).

6 What Affects Sleep Quality?

6.1 Which Gender has better Sleep Quality?

Both Gender has similar sleep quality with majority of test subjects show good sleep efficiency (> 80%).

6.2 How the Sleeping Efficiency Differs for Each Age Group?

As we grow older, we tend to have less and less sleep duration but increase in sleep efficiency.

6.3 How Does Our Life-style Affect Sleeping Quality?

Alcohol is a central nervous system depressant that causes brain activity to slow down. Alcohol has sedative effects that can induce feelings of relaxation and sleepiness, but the consumption of alcohol — especially in excess — has been linked to poor sleep quality and duration. Now, we will see how much is too much for us to consume alcohol prior to sleep. Data used in this analysis is Alcohol.consumption which shows the amount of alcohol consumed in the 24 hours prior to bedtime (in oz).

As we start to consume more than 1 oz alcohol prior to bedtime, the sleep efficiency plunged to below 70%, while the good sleeping efficiency should be > 80%.

So does the smoking habit. People who does not actively smoked, has much better sleep efficiency in general compare to the ones who does.

Contrary to popular belief, based on our study, people who consume caffeinated drinks tend to have better sleep efficiency with slightly lower sleep duration.

And for those who exercise more in a week, it significantly increased their sleeping efficiency.

6.4 Why Do We Wake Up More in Our Sleep?

The more we get up in the middle of our sleep, the less is our sleep quality. For some test subjects, more awakenings will deeply affect their Deep Sleep %, but in general people with no to 1 awakenings per sleep have better Deep Sleep benefits. In the plot below, we find that more alcohol consumption leads to more awakenings in our sleep.

7 Conclusion

As we tried to include all contributing factor to Sleep Quality based on our observation to the study result, we find that :

  • As people get older they have less sleep duration but with better sleep quality.
  • Alcohol and smoking habit contributes in lowering sleeping quality. Combination of both will result in very poor sleeping efficiency (< 60%).
  • While exercise routine boost the quality of sleep.
  • Excessive Alcohol Consumption also contributes in more awakening during one’s sleeping cycle. More awakenings leads to less sleep efficiency & deep sleep benefit
  • So if you want better sleep quality, with less awakenings in the middle of your sleep, consume less alcohol.