Research Question

Do students who are more physically active tend to get more sleep on school nights?

Introduction

For this project, I wanted to see if there is a relationship between physical activity and sleep among students. I used the yrbss_samp dataset from OpenIntro. This is a sample of the CDC Youth Risk Behavior Surveillance System (YRBSS) and contains 100 student observations.

The two columns I will use are physically_active_7d and school_night_hours_sleep. The physically_active_7d column shows how many days in the last 7 days a student was physically active for at least 60 minutes. The school_night_hours_sleep column shows how many hours of sleep a student usually gets on a school night.

Data Analysis

I will first import and look at the data. Then I will keep only the two columns needed for my question and remove rows with missing sleep or physical activity values. After that, I will group students by their amount of sleep and find the average number of physically active days for each group. Finally, I will make a bar plot to make the results easier to compare.

yrbss <- read.csv("https://www.openintro.org/data/csv/yrbss_samp.csv")

head(yrbss)
##   age gender grade hispanic                      race height weight helmet_12m
## 1  16 female    11      not Black or African American   1.50  52.62      never
## 2  17   male    11      not                     White   1.78  74.84     rarely
## 3  17   male    11      not                     White   1.75 106.60      never
## 4  15   male    10 hispanic                      <NA>   1.68  66.68      never
## 5  18   male    12      not Black or African American   1.70  80.29      never
## 6  15 female     9      not Black or African American   1.57  46.27       <NA>
##   text_while_driving_30d physically_active_7d hours_tv_per_school_day
## 1                    1-2                    0                       4
## 2                      0                    7                       1
## 3                      0                    7                       2
## 4          did not drive                    3                       2
## 5          did not drive                    0                       2
## 6          did not drive                    4                    <NA>
##   strength_training_7d school_night_hours_sleep
## 1                    0                        8
## 2                    5                        7
## 3                    0                        7
## 4                    1                        5
## 5                    2                        6
## 6                    3                        5
dim(yrbss)
## [1] 100  13
df <- yrbss |>
  dplyr::select(physically_active_7d, school_night_hours_sleep) |>
  dplyr::filter(!is.na(physically_active_7d), !is.na(school_night_hours_sleep))

summary(df)
##  physically_active_7d school_night_hours_sleep
##  Min.   :0.000        Length   :91            
##  1st Qu.:1.000        N.unique : 7            
##  Median :4.000        N.blank  : 0            
##  Mean   :3.758        Min.nchar: 1            
##  3rd Qu.:7.000        Max.nchar: 3            
##  Max.   :7.000
df <- df |>
  dplyr::mutate(
    school_night_hours_sleep = factor(
      school_night_hours_sleep,
      levels = c("<5", "5", "6", "7", "8", "9", "10+")
    )
  )

activity_summary <- df |>
  dplyr::group_by(school_night_hours_sleep) |>
  dplyr::summarize(
    students = dplyr::n(),
    avg_active_days = mean(physically_active_7d)
  )

activity_summary
## # A tibble: 7 × 3
##   school_night_hours_sleep students avg_active_days
##   <fct>                       <int>           <dbl>
## 1 <5                              8            1.62
## 2 5                               8            4   
## 3 6                              15            3.07
## 4 7                              28            4.25
## 5 8                              21            4.29
## 6 9                               9            3.44
## 7 10+                             2            5.5
barplot(
  activity_summary$avg_active_days,
  names.arg = activity_summary$school_night_hours_sleep,
  xlab = "Hours of Sleep on a School Night",
  ylab = "Average Physically Active Days",
  main = "Physical Activity by Hours of Sleep"
)

Conclusion and Future Directions

The results show some relationship between physical activity and sleep, but the pattern is not perfectly consistent. Students with different amounts of school-night sleep had different average numbers of physically active days. The results help compare physical activity across sleep groups, but they do not prove that physical activity causes students to sleep more.

This dataset is only a sample of 100 students, so a larger dataset could give a clearer result. In the future, I could use the full YRBSS dataset and also look at other variables such as age, grade, gender, or strength training to see if they are related to sleep and physical activity.

References

OpenIntro. “Sample of Youth Risk Behavior Surveillance System (YRBSS).”
https://www.openintro.org/data/index.php?data=yrbss_samp

Centers for Disease Control and Prevention. “Youth Risk Behavior Surveillance System (YRBSS).”
https://www.cdc.gov/yrbs/