Toddler’s Nap

Author

Caresse Cross Beard

Load Packages

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.1     ✔ readr     2.2.0
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.3     ✔ tibble    3.3.1
✔ lubridate 1.9.5     ✔ tidyr     1.3.2
✔ purrr     1.2.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr)
nap_schedule <- tibble(
  Week = c(1, 2),
  `Monday Nap (min)` = c(90, 75),
  `Mon Bedtime` = c("8:00 PM", "8:15 PM"),
  `Tuesday Nap (min)` = c(60, 120),
  `Tuesday bedtime` = c("8:00 PM", "8:30 PM"),
  `Wednesday nap (min)` = c(0, 45),
  `Wednesday Bedtime` = c("7:30 PM", "8:00 PM")
)
# Save original wide dataset
write.csv(
  nap_schedule,"nap_schedule_raw.csv")
glimpse(nap_schedule)
Rows: 2
Columns: 7
$ Week                  <dbl> 1, 2
$ `Monday Nap (min)`    <dbl> 90, 75
$ `Mon Bedtime`         <chr> "8:00 PM", "8:15 PM"
$ `Tuesday Nap (min)`   <dbl> 60, 120
$ `Tuesday bedtime`     <chr> "8:00 PM", "8:30 PM"
$ `Wednesday nap (min)` <dbl> 0, 45
$ `Wednesday Bedtime`   <chr> "7:30 PM", "8:00 PM"
writeLines(names(nap_schedule))
Week
Monday Nap (min)
Mon Bedtime
Tuesday Nap (min)
Tuesday bedtime
Wednesday nap (min)
Wednesday Bedtime
nap_schedule <- nap_schedule %>%
  rename(
    week = Week,
    monday_nap_min = `Monday Nap (min)`,
    monday_bedtime = `Mon Bedtime`,
    tuesday_nap_min = `Tuesday Nap (min)`,
    tuesday_bedtime = `Tuesday bedtime`,
    wednesday_nap_min = `Wednesday nap (min)`,
    wednesday_bedtime = `Wednesday Bedtime`)
nap_tidy <- nap_schedule %>%
  pivot_longer(
    cols = -week,
    names_to = c("day", ".value"),
    names_pattern = "(monday|tuesday|wednesday)_(nap_min|bedtime)"
  ) %>%
  rename(nap_duration_min = nap_min)

Naps by Week

nap_by_day <- nap_tidy %>%
  group_by(day) %>%
  summarise(
    average_nap = mean(nap_duration_min),
    .groups = "drop"
  )

nap_by_day
# A tibble: 3 × 2
  day       average_nap
  <chr>           <dbl>
1 monday           82.5
2 tuesday          90  
3 wednesday        22.5
nap_by_week <- nap_tidy %>%
  group_by(week, day) %>%
  summarise(
    nap_duration_min = mean(nap_duration_min),
    .groups = "drop"
  )

nap_by_week
# A tibble: 6 × 3
   week day       nap_duration_min
  <dbl> <chr>                <dbl>
1     1 monday                  90
2     1 tuesday                 60
3     1 wednesday                0
4     2 monday                  75
5     2 tuesday                120
6     2 wednesday               45

Comparing the two weeks, we can see that Wednesdays has the shortest nap duration each week. Monday in week1 has a nap duration of 90 minutes while in the second week the duration is 75 minutes.

Visualization Nap Duration and Bedtime

nap_tidy <- nap_tidy %>%
  mutate(
    bedtime_time = parse_date_time(bedtime, orders = "I:M p"),
    bedtime_minutes = hour(bedtime_time) * 60 +
      minute(bedtime_time)
  )
ggplot(nap_tidy, aes(x = nap_duration_min, y = bedtime_minutes)) +
  geom_point() +
  labs(
    title = "Nap Duration and Bedtime",
    x = "Nap Duration (minutes)",
    y = "Bedtime"
  ) +
  scale_y_continuous(
    breaks = c(1170, 1200, 1230),
    labels = c("7:30 PM", "8:00 PM", "8:30 PM")
  ) +
  theme_minimal()

Analysis

The data shows that Tuesday had the highest average nap duration at 90 minutes, followed by Monday at 82.5 minutes. Wednesday had the shortest average nap duration at 22.5 minutes.

The data also shows some differences in bedtime and nap duration between the two weeks. However, there are only six observations, so it is difficult to determine whether longer naps are connected to later bedtimes. More data would be needed to identify a clear pattern.