0.1 Introduction

In this analysis I will investigate sleep patterns among people using data from the sleep75 dataset. I am going to explore various factors influencing sleep duration, focusing particularly on gender differences.

suppressWarnings({
  library(wooldridge)
  library(ggplot2)
  library(broom)
})
# Load the sleep data
data(sleep75)
# Separate data based on gender
male_data <- subset(sleep75, male == 1)
female_data <- subset(sleep75, male == 0)
# Distribution of Sleep Duration for Males
ggplot(male_data, aes(x = sleep)) +
  geom_histogram(binwidth = 30, fill = "skyblue", color = "black") +
  labs(title = "Distribution of Sleep Duration (Males)",
       x = "Minutes of Sleep",
       y = "Frequency") +
  theme_minimal()

# Model for males
male_model <- lm(sleep ~ totwrk + educ + age, data = male_data)
male_model_summary <- tidy(male_model)

# Summary of the model
male_model_summary
## # A tibble: 4 × 5
##   term        estimate std.error statistic  p.value
##   <chr>          <dbl>     <dbl>     <dbl>    <dbl>
## 1 (Intercept) 3759.     149.         25.2  3.67e-84
## 2 totwrk        -0.183    0.0242     -7.56 2.84e-13
## 3 educ         -12.9      7.40       -1.75 8.14e- 2
## 4 age            2.69     1.86        1.44 1.50e- 1
# Scatterplot of Sleep vs. Total Work Hours for Males
ggplot(male_data, aes(x = totwrk, y = sleep)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE, color = "blue") +
  labs(title = "Scatterplot of Sleep vs. Total Work Hours (Males)",
       x = "Total Work Hours",
       y = "Minutes of Sleep") +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

# Boxplot of Sleep Duration by Education Level for Males
ggplot(male_data, aes(x = as.factor(educ), y = sleep)) +
  geom_boxplot(fill = "skyblue") +
  labs(title = "Boxplot of Sleep Duration by Education Level (Males)",
       x = "Education Level",
       y = "Minutes of Sleep") +
  theme_minimal()