Chapter 3 Midterm

3.1 Introduction

The purpose of this midterm was to examine a sleep exercise data set and clean it up and analyze it. I ran various tests such as a t-test, ANOVA and post-hoc. ## Setup & Data import

library(tidyverse)
library(readxl)
library(knitr)
library(mosaic)
library(ggplot2)
library(supernova)
library(AICcmodavg)
sleep_exercise_info <- read_excel("midterm_sleep_exercise.xlsx", 
    sheet = "participant_info_midterm")
View(sleep_exercise_info)
sleep_exercise_data <- read_excel("midterm_sleep_exercise.xlsx", 
    sheet = "sleep_data_midterm")
View(sleep_exercise_data)
glimpse(sleep_exercise_info)
## Rows: 100
## Columns: 4
## $ ID             <chr> "P001", "P002", "P003", "P004", "P005", "P006", "P007", "P008", "P009", "P010", "P011", …
## $ Exercise_Group <chr> "NONE", "Nonee", "None", "None", "None", "None", "None", "None", "None", "None", "None",…
## $ Sex            <chr> "Male", "Malee", "Female", "Female", "Male", "Female", "Male", "Female", "Male", "Female…
## $ Age            <dbl> 35, 57, 26, 29, 33, 33, 32, 30, 37, 28, 30, 20, 42, 31, 33, 26, 41, 18, 28, 37, 48, 37, …
glimpse(sleep_exercise_data)
## Rows: 100
## Columns: 4
## $ ID               <chr> "P001", "P002", "P003", "P004", "P005", "P006", "P007", "P008", "P009", "P010", "P011"…
## $ Pre_Sleep        <chr> "zzz-5.8", "Sleep-6.6", NA, "SLEEP-7.2", "score-7.4", "Sleep-6.6", "Sleep-6", "zzz-8.1…
## $ Post_Sleep       <dbl> 4.7, 7.4, 6.2, 7.3, 7.4, 7.1, 6.7, 9.0, 5.1, 6.3, 6.2, 4.6, 7.6, 7.2, 4.6, 8.2, 7.6, 7…
## $ Sleep_Efficiency <dbl> 81.6, 75.7, 82.9, 83.6, 83.5, 88.5, 83.6, 73.4, 88.2, 80.4, 85.2, 82.9, 74.0, 92.0, 89…

We have both data sets and are now ready to clean and analye our data.

3.2 Merge and Base Cleaning

clean_exercise_group<- sleep_exercise_info %>% 
  mutate(Exercise_Group = case_when(
    Exercise_Group %in% c("cardio", "CARDIO", "C") ~ "Cardio",
    Exercise_Group %in% c("WEIGHTS", "WEIGHTSSS", "WEIGHTZ") ~ "Weights",
    Exercise_Group %in% c("CW", "C+W") ~ "Cardio+Weights",
    Exercise_Group %in% c("Nonee", "NONE", "N") ~ "None",
    TRUE ~ Exercise_Group
  ))
View(clean_exercise_group)
clean_sex_label <- sleep_exercise_info %>% 
  mutate(Sex = case_when(
    Sex %in% c("F", "Fem", "Femalee") ~ "Female",
    Sex %in% c("M", "MALE", "Mal", "Malee") ~ "Male",
    TRUE ~ Sex
  ))
View(clean_sex_label)
exercise_group_data <- merge(clean_exercise_group, clean_sex_label)
View(exercise_group_data)
clean_sleep_data<- merge(exercise_group_data, sleep_exercise_data)
View(clean_sleep_data)

I was able to clean up the data in the Exercise group and Sex column in the sleep_exercise_info data set. Now the words in those columns are standardized. I also merged both data sets together.

3.3 Create Derived Variables

clean_sleep_data <- clean_sleep_data %>%
  mutate(
    pre_sleep_num = as.numeric(gsub("[^0-9.]", "", Pre_Sleep))
  )
clean_sleep_data <- clean_sleep_data %>% 
  mutate(Sleep_Difference = clean_sleep_data$Post_Sleep - clean_sleep_data$pre_sleep_num)

clean_sleep_data <- clean_sleep_data %>%  
  mutate(
    AgeGroup2 = case_when(
      Age < 40 ~ "40",
      Age >= 40 ~ "40+"
    )
  )
clean_sleep_data %>%filter(is.na(Sleep_Difference))
##     ID Exercise_Group    Sex Age Pre_Sleep Post_Sleep Sleep_Efficiency pre_sleep_num Sleep_Difference AgeGroup2
## 1 P003           None Female  26      <NA>        6.2             82.9            NA               NA        40
## 2 P014           None   Male  31      <NA>        7.2             92.0            NA               NA        40
## 3 P019           None   Male  28      <NA>        5.7             69.1            NA               NA        40
## 4 P023           None Female  42   sleep-5         NA             81.3           5.0               NA       40+
## 5 P037         Cardio   Male  35      <NA>        9.7             85.6            NA               NA        40
## 6 P095 Cardio+Weights Female  29 Sleep-5.7         NA             85.0           5.7               NA        40
## 7 P099 Cardio+Weights   Male  28      <NA>        8.8             88.5            NA               NA        40
clean_sleep_data %>% filter(!is.na(Sleep_Difference))
##      ID Exercise_Group    Sex Age Pre_Sleep Post_Sleep Sleep_Efficiency pre_sleep_num Sleep_Difference AgeGroup2
## 1  P004           None Female  29 SLEEP-7.2        7.3             83.6           7.2              0.1        40
## 2  P005           None   Male  33 score-7.4        7.4             83.5           7.4              0.0        40
## 3  P006           None Female  33 Sleep-6.6        7.1             88.5           6.6              0.5        40
## 4  P007           None   Male  32   Sleep-6        6.7             83.6           6.0              0.7        40
## 5  P008           None Female  30   zzz-8.1        9.0             73.4           8.1              0.9        40
## 6  P009           None   Male  37 sleep-5.5        5.1             88.2           5.5             -0.4        40
## 7  P010           None Female  28 sleep-5.7        6.3             80.4           5.7              0.6        40
## 8  P011           None Female  30   score-7        6.2             85.2           7.0             -0.8        40
## 9  P012           None   Male  20 sleep-5.5        4.6             82.9           5.5             -0.9        40
## 10 P013           None   Male  42   Sleep-8        7.6             74.0           8.0             -0.4       40+
## 11 P016           None   Male  26 SLEEP-7.8        8.2             71.7           7.8              0.4        40
## 12 P017           None Female  41   zzz-6.7        7.6             78.5           6.7              0.9       40+
## 13 P018           None   Male  18 SLEEP-7.4        7.2             73.8           7.4             -0.2        40
## 14 P021           None   Male  48   zzz-6.8        7.1             78.7           6.8              0.3       40+
## 15 P024           None Female  39   score-6        5.6             76.6           6.0             -0.4        40
## 16 P026         Cardio Female  34 score-5.2        6.7             84.5           5.2              1.5        40
## 17 P027         Cardio Female  28 sleep-6.6        7.8             75.9           6.6              1.2        40
## 18 P028         Cardio Female  29 SLEEP-5.6        6.3             79.0           5.6              0.7        40
## 19 P029         Cardio   Male  36   Sleep-6        6.3             87.6           6.0              0.3        40
## 20 P031         Cardio Female  42 Sleep-6.9        7.6             88.5           6.9              0.7       40+
## 21 P032         Cardio Female  18 SLEEP-6.9        7.9             87.8           6.9              1.0        40
## 22 P033         Cardio Female  38   zzz-5.9        6.6             80.9           5.9              0.7        40
## 23 P034         Cardio Female  20 score-5.2        6.0             92.8           5.2              0.8        40
## 24 P035         Cardio   Male  30 SLEEP-6.7        8.0             86.4           6.7              1.3        40
## 25 P036         Cardio Female  19   zzz-5.4        5.7             88.0           5.4              0.3        40
## 26 P038         Cardio Female  34     zzz-7        8.1             79.6           7.0              1.1        40
## 27 P039         Cardio   Male  39 SLEEP-5.6        6.3             81.3           5.6              0.7        40
## 28 P040         Cardio Female  39     zzz-6        8.1             79.7           6.0              2.1        40
## 29 P042         Cardio Female  28 SLEEP-5.6        7.3             81.9           5.6              1.7        40
## 30 P043         Cardio Female  43   zzz-6.9        8.2             81.3           6.9              1.3       40+
## 31 P044         Cardio Female  33   zzz-5.8        7.1             88.7           5.8              1.3        40
## 32 P046         Cardio   Male  30 SLEEP-7.1        8.5             95.0           7.1              1.4        40
## 33 P047         Cardio Female  42 SLEEP-5.8        7.0             85.5           5.8              1.2       40+
## 34 P050         Cardio   Male  31   zzz-6.4        8.4            101.5           6.4              2.0        40
## 35 P076 Cardio+Weights   Male  37 sleep-5.7        6.5             83.9           5.7              0.8        40
## 36 P077 Cardio+Weights Female  37 score-5.9        7.3             92.4           5.9              1.4        40
## 37 P078 Cardio+Weights Female  24 score-6.6        7.2             74.5           6.6              0.6        40
## 38 P079 Cardio+Weights   Male  38 SLEEP-6.6        7.4             89.0           6.6              0.8        40
## 39 P080 Cardio+Weights   Male  42 Sleep-7.2        8.1             94.5           7.2              0.9       40+
## 40 P081 Cardio+Weights Female  38   Sleep-8        8.9             74.5           8.0              0.9        40
## 41 P082 Cardio+Weights   Male  46 score-6.5        6.4             88.7           6.5             -0.1       40+
## 42 P083 Cardio+Weights Female  49 score-5.9        6.8             90.4           5.9              0.9       40+
## 43 P084 Cardio+Weights Female  31   sleep-8        8.4             80.2           8.0              0.4        40
## 44 P085 Cardio+Weights   Male  33 score-6.2        6.9             89.9           6.2              0.7        40
## 45 P086 Cardio+Weights Female  46 SLEEP-6.2        7.4             83.1           6.2              1.2       40+
## 46 P087 Cardio+Weights   Male  18 SLEEP-6.7        7.6             96.3           6.7              0.9        40
## 47 P088 Cardio+Weights   Male  34 score-7.5        8.9             81.2           7.5              1.4        40
## 48 P090 Cardio+Weights Female  41 Sleep-7.2        7.6             79.9           7.2              0.4       40+
## 49 P091 Cardio+Weights   Male  46   zzz-7.3        7.9             87.5           7.3              0.6       40+
## 50 P093 Cardio+Weights Female  40   Sleep-8        9.5             90.4           8.0              1.5       40+
## 51 P094 Cardio+Weights   Male  35   zzz-6.1        7.2             84.4           6.1              1.1        40
## 52 P097 Cardio+Weights   Male  24 SLEEP-4.4        4.7             88.9           4.4              0.3        40
## 53 P098 Cardio+Weights Female  35 score-5.9        6.9             92.6           5.9              1.0        40
## 54 P100 Cardio+Weights   Male  32   zzz-6.5        7.3             84.2           6.5              0.8        40

I created a new column and called it pre_sleep_num to make the Pre_Sleep column just numeric, without any of the characters. After making it numeric, I was able to create a derived variable called sleep_difference which was the scores from post_sleep minus the scores from pre_sleep. I also created a variable called Age_Group_ which conveyed whether participants were either 40 years old or younger, and 40+ years old. I also ran the is.na function to drop the rows in the Sleep_difference column

3.4 Descriptive Statistics

favstats(clean_sleep_data$Sleep_Difference)
##   min  Q1 median    Q3 max      mean        sd  n missing
##  -0.9 0.4    0.8 1.175 2.1 0.7240741 0.6398512 54       7
favstats(clean_sleep_data$Sleep_Efficiency)
##   min   Q1 median   Q3   max     mean       sd  n missing
##  69.1 80.2   84.2 88.5 101.5 84.25246 6.495886 61       0
clean_sleep_data %>% 
  group_by(Exercise_Group) %>%
  summarise(
    mean_sleep_difference = mean(Sleep_Difference, na.rm = TRUE)
  )
## # A tibble: 3 × 2
##   Exercise_Group mean_sleep_difference
##   <chr>                          <dbl>
## 1 Cardio                        1.12  
## 2 Cardio+Weights                0.825 
## 3 None                          0.0867
clean_sleep_data %>% 
  group_by(Exercise_Group) %>% 
  summarise(
    mean_sleep_efficiency = mean(Sleep_Efficiency, na.rm = TRUE)
  )
## # A tibble: 3 × 2
##   Exercise_Group mean_sleep_efficiency
##   <chr>                          <dbl>
## 1 Cardio                          85.6
## 2 Cardio+Weights                  86.4
## 3 None                            80.4
kable(clean_sleep_data)
Table 3.1: This table shows the cleaned up sleep data.
ID Exercise_Group Sex Age Pre_Sleep Post_Sleep Sleep_Efficiency pre_sleep_num Sleep_Difference AgeGroup2
P003 None Female 26 NA 6.2 82.9 NA NA 40
P004 None Female 29 SLEEP-7.2 7.3 83.6 7.2 0.1 40
P005 None Male 33 score-7.4 7.4 83.5 7.4 0.0 40
P006 None Female 33 Sleep-6.6 7.1 88.5 6.6 0.5 40
P007 None Male 32 Sleep-6 6.7 83.6 6.0 0.7 40
P008 None Female 30 zzz-8.1 9.0 73.4 8.1 0.9 40
P009 None Male 37 sleep-5.5 5.1 88.2 5.5 -0.4 40
P010 None Female 28 sleep-5.7 6.3 80.4 5.7 0.6 40
P011 None Female 30 score-7 6.2 85.2 7.0 -0.8 40
P012 None Male 20 sleep-5.5 4.6 82.9 5.5 -0.9 40
P013 None Male 42 Sleep-8 7.6 74.0 8.0 -0.4 40+
P014 None Male 31 NA 7.2 92.0 NA NA 40
P016 None Male 26 SLEEP-7.8 8.2 71.7 7.8 0.4 40
P017 None Female 41 zzz-6.7 7.6 78.5 6.7 0.9 40+
P018 None Male 18 SLEEP-7.4 7.2 73.8 7.4 -0.2 40
P019 None Male 28 NA 5.7 69.1 NA NA 40
P021 None Male 48 zzz-6.8 7.1 78.7 6.8 0.3 40+
P023 None Female 42 sleep-5 NA 81.3 5.0 NA 40+
P024 None Female 39 score-6 5.6 76.6 6.0 -0.4 40
P026 Cardio Female 34 score-5.2 6.7 84.5 5.2 1.5 40
P027 Cardio Female 28 sleep-6.6 7.8 75.9 6.6 1.2 40
P028 Cardio Female 29 SLEEP-5.6 6.3 79.0 5.6 0.7 40
P029 Cardio Male 36 Sleep-6 6.3 87.6 6.0 0.3 40
P031 Cardio Female 42 Sleep-6.9 7.6 88.5 6.9 0.7 40+
P032 Cardio Female 18 SLEEP-6.9 7.9 87.8 6.9 1.0 40
P033 Cardio Female 38 zzz-5.9 6.6 80.9 5.9 0.7 40
P034 Cardio Female 20 score-5.2 6.0 92.8 5.2 0.8 40
P035 Cardio Male 30 SLEEP-6.7 8.0 86.4 6.7 1.3 40
P036 Cardio Female 19 zzz-5.4 5.7 88.0 5.4 0.3 40
P037 Cardio Male 35 NA 9.7 85.6 NA NA 40
P038 Cardio Female 34 zzz-7 8.1 79.6 7.0 1.1 40
P039 Cardio Male 39 SLEEP-5.6 6.3 81.3 5.6 0.7 40
P040 Cardio Female 39 zzz-6 8.1 79.7 6.0 2.1 40
P042 Cardio Female 28 SLEEP-5.6 7.3 81.9 5.6 1.7 40
P043 Cardio Female 43 zzz-6.9 8.2 81.3 6.9 1.3 40+
P044 Cardio Female 33 zzz-5.8 7.1 88.7 5.8 1.3 40
P046 Cardio Male 30 SLEEP-7.1 8.5 95.0 7.1 1.4 40
P047 Cardio Female 42 SLEEP-5.8 7.0 85.5 5.8 1.2 40+
P050 Cardio Male 31 zzz-6.4 8.4 101.5 6.4 2.0 40
P076 Cardio+Weights Male 37 sleep-5.7 6.5 83.9 5.7 0.8 40
P077 Cardio+Weights Female 37 score-5.9 7.3 92.4 5.9 1.4 40
P078 Cardio+Weights Female 24 score-6.6 7.2 74.5 6.6 0.6 40
P079 Cardio+Weights Male 38 SLEEP-6.6 7.4 89.0 6.6 0.8 40
P080 Cardio+Weights Male 42 Sleep-7.2 8.1 94.5 7.2 0.9 40+
P081 Cardio+Weights Female 38 Sleep-8 8.9 74.5 8.0 0.9 40
P082 Cardio+Weights Male 46 score-6.5 6.4 88.7 6.5 -0.1 40+
P083 Cardio+Weights Female 49 score-5.9 6.8 90.4 5.9 0.9 40+
P084 Cardio+Weights Female 31 sleep-8 8.4 80.2 8.0 0.4 40
P085 Cardio+Weights Male 33 score-6.2 6.9 89.9 6.2 0.7 40
P086 Cardio+Weights Female 46 SLEEP-6.2 7.4 83.1 6.2 1.2 40+
P087 Cardio+Weights Male 18 SLEEP-6.7 7.6 96.3 6.7 0.9 40
P088 Cardio+Weights Male 34 score-7.5 8.9 81.2 7.5 1.4 40
P090 Cardio+Weights Female 41 Sleep-7.2 7.6 79.9 7.2 0.4 40+
P091 Cardio+Weights Male 46 zzz-7.3 7.9 87.5 7.3 0.6 40+
P093 Cardio+Weights Female 40 Sleep-8 9.5 90.4 8.0 1.5 40+
P094 Cardio+Weights Male 35 zzz-6.1 7.2 84.4 6.1 1.1 40
P095 Cardio+Weights Female 29 Sleep-5.7 NA 85.0 5.7 NA 40
P097 Cardio+Weights Male 24 SLEEP-4.4 4.7 88.9 4.4 0.3 40
P098 Cardio+Weights Female 35 score-5.9 6.9 92.6 5.9 1.0 40
P099 Cardio+Weights Male 28 NA 8.8 88.5 NA NA 40
P100 Cardio+Weights Male 32 zzz-6.5 7.3 84.2 6.5 0.8 40

I did some descriptive statistics to look at the mean, min, max, and sd for Sleep_difference and Sleep_efficiency. I also looked at the group means by Exercise Group for Sleep_difference and Sleep_efficiency.

3.5 Visualization

ggplot(clean_sleep_data, aes(x = Exercise_Group, y = Sleep_Difference)) + 
  geom_boxplot() + 
  labs(
    title = "Relationship between Sleep Difference and Exercise Group", 
    x = "Exercise Group",
    y = "Sleep Difference"
  ) +
  theme_minimal()
This is a box plot that shows the relationship between sleep difference and exercise group.

Figure 3.1: This is a box plot that shows the relationship between sleep difference and exercise group.

ggplot(clean_sleep_data, aes(x = Exercise_Group, y = Sleep_Efficiency)) + 
  geom_boxplot() + 
  labs(
    title = "Relationship between Sleep Efficiency and Exercise Group",
    x = "Exercise Group",
    y = "Sleep Efficiency"
  )
This is a boxplot that looks at the relationship between sleep efficiency and exercise group.

Figure 3.2: This is a boxplot that looks at the relationship between sleep efficiency and exercise group.

theme_economist()
## <theme> List of 39
##  $ line                : <ggplot2::element_line>
##   ..@ colour       : chr "black"
##   ..@ linewidth    : NULL
##   ..@ linetype     : NULL
##   ..@ lineend      : NULL
##   ..@ linejoin     : NULL
##   ..@ arrow        : logi FALSE
##   ..@ arrow.fill   : chr "black"
##   ..@ inherit.blank: logi TRUE
##  $ rect                : <ggplot2::element_rect>
##   ..@ fill         : Named chr NA
##  .. .. - attr(*, "names")= chr NA
##   ..@ colour       : logi NA
##   ..@ linewidth    : NULL
##   ..@ linetype     : num 1
##   ..@ linejoin     : NULL
##   ..@ inherit.blank: logi TRUE
##  $ text                : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : chr "black"
##   ..@ size         : NULL
##   ..@ hjust        : NULL
##   ..@ vjust        : NULL
##   ..@ angle        : NULL
##   ..@ lineheight   : NULL
##   ..@ margin       : NULL
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ axis.title          : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : NULL
##   ..@ size         : 'rel' num 1
##   ..@ hjust        : NULL
##   ..@ vjust        : NULL
##   ..@ angle        : NULL
##   ..@ lineheight   : NULL
##   ..@ margin       : NULL
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ axis.title.x        : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : NULL
##   ..@ size         : NULL
##   ..@ hjust        : NULL
##   ..@ vjust        : NULL
##   ..@ angle        : NULL
##   ..@ lineheight   : NULL
##   ..@ margin       : NULL
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ axis.title.y        : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : NULL
##   ..@ size         : NULL
##   ..@ hjust        : NULL
##   ..@ vjust        : NULL
##   ..@ angle        : num 90
##   ..@ lineheight   : NULL
##   ..@ margin       : NULL
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ axis.text           : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : NULL
##   ..@ size         : 'rel' num 1
##   ..@ hjust        : NULL
##   ..@ vjust        : NULL
##   ..@ angle        : NULL
##   ..@ lineheight   : NULL
##   ..@ margin       : NULL
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ axis.text.x         : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : NULL
##   ..@ size         : NULL
##   ..@ hjust        : NULL
##   ..@ vjust        : num 0
##   ..@ angle        : NULL
##   ..@ lineheight   : NULL
##   ..@ margin       : <ggplot2::margin> num [1:4] 10 0 0 0
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ axis.text.x.top     : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : NULL
##   ..@ size         : NULL
##   ..@ hjust        : NULL
##   ..@ vjust        : num 0
##   ..@ angle        : NULL
##   ..@ lineheight   : NULL
##   ..@ margin       : <ggplot2::margin> num [1:4] 0 0 10 0
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ axis.text.y         : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : NULL
##   ..@ size         : NULL
##   ..@ hjust        : num 0
##   ..@ vjust        : NULL
##   ..@ angle        : NULL
##   ..@ lineheight   : NULL
##   ..@ margin       : <ggplot2::margin> num [1:4] 0 10 0 0
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ axis.ticks          : <ggplot2::element_line>
##   ..@ colour       : NULL
##   ..@ linewidth    : NULL
##   ..@ linetype     : NULL
##   ..@ lineend      : NULL
##   ..@ linejoin     : NULL
##   ..@ arrow        : logi FALSE
##   ..@ arrow.fill   : NULL
##   ..@ inherit.blank: logi TRUE
##  $ axis.ticks.y        : <ggplot2::element_blank>
##  $ axis.ticks.length   : 'simpleUnit' num -5points
##   ..- attr(*, "unit")= int 8
##  $ axis.line           : <ggplot2::element_line>
##   ..@ colour       : NULL
##   ..@ linewidth    : 'rel' num 0.8
##   ..@ linetype     : NULL
##   ..@ lineend      : NULL
##   ..@ linejoin     : NULL
##   ..@ arrow        : logi FALSE
##   ..@ arrow.fill   : NULL
##   ..@ inherit.blank: logi TRUE
##  $ axis.line.y         : <ggplot2::element_blank>
##  $ legend.background   : <ggplot2::element_rect>
##   ..@ fill         : NULL
##   ..@ colour       : NULL
##   ..@ linewidth    : NULL
##   ..@ linetype     : num 0
##   ..@ linejoin     : NULL
##   ..@ inherit.blank: logi TRUE
##  $ legend.spacing      : 'simpleUnit' num 15points
##   ..- attr(*, "unit")= int 8
##  $ legend.key          : <ggplot2::element_rect>
##   ..@ fill         : NULL
##   ..@ colour       : NULL
##   ..@ linewidth    : NULL
##   ..@ linetype     : num 0
##   ..@ linejoin     : NULL
##   ..@ inherit.blank: logi TRUE
##  $ legend.key.size     : 'simpleUnit' num 1.2lines
##   ..- attr(*, "unit")= int 3
##  $ legend.key.height   : NULL
##  $ legend.key.width    : NULL
##  $ legend.text         : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : NULL
##   ..@ size         : 'rel' num 1.25
##   ..@ hjust        : NULL
##   ..@ vjust        : NULL
##   ..@ angle        : NULL
##   ..@ lineheight   : NULL
##   ..@ margin       : NULL
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ legend.title        : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : NULL
##   ..@ size         : 'rel' num 1
##   ..@ hjust        : num 0
##   ..@ vjust        : NULL
##   ..@ angle        : NULL
##   ..@ lineheight   : NULL
##   ..@ margin       : NULL
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ legend.position     : chr "top"
##  $ legend.direction    : NULL
##  $ legend.justification: chr "center"
##  $ panel.background    : <ggplot2::element_rect>
##   ..@ fill         : NULL
##   ..@ colour       : NULL
##   ..@ linewidth    : NULL
##   ..@ linetype     : num 0
##   ..@ linejoin     : NULL
##   ..@ inherit.blank: logi TRUE
##  $ panel.border        : <ggplot2::element_blank>
##  $ panel.spacing       : 'simpleUnit' num 0.25lines
##   ..- attr(*, "unit")= int 3
##  $ panel.grid.major    : <ggplot2::element_line>
##   ..@ colour       : chr "white"
##   ..@ linewidth    : 'rel' num 1.75
##   ..@ linetype     : NULL
##   ..@ lineend      : NULL
##   ..@ linejoin     : NULL
##   ..@ arrow        : logi FALSE
##   ..@ arrow.fill   : chr "white"
##   ..@ inherit.blank: logi TRUE
##  $ panel.grid.minor    : <ggplot2::element_blank>
##  $ plot.background     : <ggplot2::element_rect>
##   ..@ fill         : Named chr "#d5e4eb"
##  .. .. - attr(*, "names")= chr "blue-gray"
##   ..@ colour       : logi NA
##   ..@ linewidth    : NULL
##   ..@ linetype     : NULL
##   ..@ linejoin     : NULL
##   ..@ inherit.blank: logi TRUE
##  $ plot.title          : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : chr "bold"
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : NULL
##   ..@ size         : 'rel' num 1.5
##   ..@ hjust        : num 0
##   ..@ vjust        : NULL
##   ..@ angle        : NULL
##   ..@ lineheight   : NULL
##   ..@ margin       : NULL
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ plot.margin         : 'simpleUnit' num [1:4] 12points 10points 12points 10points
##   ..- attr(*, "unit")= int 8
##  $ strip.background    : <ggplot2::element_rect>
##   ..@ fill         : Named chr NA
##  .. .. - attr(*, "names")= chr NA
##   ..@ colour       : logi NA
##   ..@ linewidth    : NULL
##   ..@ linetype     : num 0
##   ..@ linejoin     : NULL
##   ..@ inherit.blank: logi TRUE
##  $ strip.text          : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : NULL
##   ..@ size         : 'rel' num 1.25
##   ..@ hjust        : NULL
##   ..@ vjust        : NULL
##   ..@ angle        : NULL
##   ..@ lineheight   : NULL
##   ..@ margin       : NULL
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ strip.text.x        : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : NULL
##   ..@ size         : NULL
##   ..@ hjust        : NULL
##   ..@ vjust        : NULL
##   ..@ angle        : NULL
##   ..@ lineheight   : NULL
##   ..@ margin       : NULL
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ strip.text.y        : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : NULL
##   ..@ size         : NULL
##   ..@ hjust        : NULL
##   ..@ vjust        : NULL
##   ..@ angle        : num -90
##   ..@ lineheight   : NULL
##   ..@ margin       : NULL
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ panel.grid.major.x  : <ggplot2::element_blank>
##  @ complete: logi TRUE
##  @ validate: logi TRUE
ggplot(clean_sleep_data, aes(x = Sleep_Difference, y = Sleep_Efficiency)) + 
  geom_point() + 
  geom_smooth(method="lm") +
  labs(
    title = "Relationship between Sleep Difference and Efficiency",
    x = "Sleep Difference",
    y = "Sleep Efficiency"
  )
This is a scatterplot to look at the relationship between sleep efficiency and sleep difference.

Figure 3.3: This is a scatterplot to look at the relationship between sleep efficiency and sleep difference.

theme_solarized()
## <theme> List of 144
##  $ line                            : <ggplot2::element_line>
##   ..@ colour       : Named chr "#93a1a1"
##  .. .. - attr(*, "names")= chr "rebase01"
##   ..@ linewidth    : num 0.545
##   ..@ linetype     : num 1
##   ..@ lineend      : chr "butt"
##   ..@ linejoin     : chr "round"
##   ..@ arrow        : logi FALSE
##   ..@ arrow.fill   : Named chr "#93a1a1"
##  .. .. - attr(*, "names")= chr "rebase01"
##   ..@ inherit.blank: logi FALSE
##  $ rect                            : <ggplot2::element_rect>
##   ..@ fill         : Named chr "#fdf6e3"
##  .. .. - attr(*, "names")= chr "rebase03"
##   ..@ colour       : Named chr "#93a1a1"
##  .. .. - attr(*, "names")= chr "rebase01"
##   ..@ linewidth    : num 0.545
##   ..@ linetype     : num 1
##   ..@ linejoin     : chr "round"
##   ..@ inherit.blank: logi FALSE
##  $ text                            : <ggplot2::element_text>
##   ..@ family       : chr ""
##   ..@ face         : chr "plain"
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : Named chr "#93a1a1"
##  .. .. - attr(*, "names")= chr "rebase01"
##   ..@ size         : num 12
##   ..@ hjust        : num 0.5
##   ..@ vjust        : num 0.5
##   ..@ angle        : num 0
##   ..@ lineheight   : num 0.9
##   ..@ margin       : <ggplot2::margin> num [1:4] 0 0 0 0
##   ..@ debug        : logi FALSE
##   ..@ inherit.blank: logi FALSE
##  $ title                           : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : Named chr "#657b83"
##  .. .. - attr(*, "names")= chr "rebase0"
##   ..@ size         : NULL
##   ..@ hjust        : NULL
##   ..@ vjust        : NULL
##   ..@ angle        : NULL
##   ..@ lineheight   : NULL
##   ..@ margin       : NULL
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi FALSE
##  $ point                           : <ggplot2::element_point>
##   ..@ colour       : chr "black"
##   ..@ shape        : num 19
##   ..@ size         : num 1.64
##   ..@ fill         : chr "white"
##   ..@ stroke       : num 0.545
##   ..@ inherit.blank: logi TRUE
##  $ polygon                         : <ggplot2::element_polygon>
##   ..@ fill         : chr "white"
##   ..@ colour       : chr "black"
##   ..@ linewidth    : num 0.545
##   ..@ linetype     : num 1
##   ..@ linejoin     : chr "round"
##   ..@ inherit.blank: logi TRUE
##  $ geom                            : <ggplot2::element_geom>
##   ..@ ink        : chr "black"
##   ..@ paper      : chr "white"
##   ..@ accent     : chr "#3366FF"
##   ..@ linewidth  : num 0.545
##   ..@ borderwidth: num 0.545
##   ..@ linetype   : int 1
##   ..@ bordertype : int 1
##   ..@ family     : chr ""
##   ..@ fontsize   : num 4.22
##   ..@ pointsize  : num 1.64
##   ..@ pointshape : num 19
##   ..@ colour     : NULL
##   ..@ fill       : NULL
##  $ spacing                         : 'simpleUnit' num 6points
##   ..- attr(*, "unit")= int 8
##  $ margins                         : <ggplot2::margin> num [1:4] 6 6 6 6
##  $ aspect.ratio                    : NULL
##  $ axis.title                      : NULL
##  $ axis.title.x                    : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : NULL
##   ..@ size         : NULL
##   ..@ hjust        : NULL
##   ..@ vjust        : num 1
##   ..@ angle        : NULL
##   ..@ lineheight   : NULL
##   ..@ margin       : <ggplot2::margin> num [1:4] 3 0 0 0
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ axis.title.x.top                : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : NULL
##   ..@ size         : NULL
##   ..@ hjust        : NULL
##   ..@ vjust        : num 0
##   ..@ angle        : NULL
##   ..@ lineheight   : NULL
##   ..@ margin       : <ggplot2::margin> num [1:4] 0 0 3 0
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ axis.title.x.bottom             : NULL
##  $ axis.title.y                    : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : NULL
##   ..@ size         : NULL
##   ..@ hjust        : NULL
##   ..@ vjust        : num 1
##   ..@ angle        : num 90
##   ..@ lineheight   : NULL
##   ..@ margin       : <ggplot2::margin> num [1:4] 0 3 0 0
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ axis.title.y.left               : NULL
##  $ axis.title.y.right              : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : NULL
##   ..@ size         : NULL
##   ..@ hjust        : NULL
##   ..@ vjust        : num 1
##   ..@ angle        : num -90
##   ..@ lineheight   : NULL
##   ..@ margin       : <ggplot2::margin> num [1:4] 0 0 0 3
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ axis.text                       : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : chr "#4D4D4DFF"
##   ..@ size         : 'rel' num 0.8
##   ..@ hjust        : NULL
##   ..@ vjust        : NULL
##   ..@ angle        : NULL
##   ..@ lineheight   : NULL
##   ..@ margin       : NULL
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ axis.text.x                     : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : NULL
##   ..@ size         : NULL
##   ..@ hjust        : NULL
##   ..@ vjust        : num 1
##   ..@ angle        : NULL
##   ..@ lineheight   : NULL
##   ..@ margin       : <ggplot2::margin> num [1:4] 2.4 0 0 0
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ axis.text.x.top                 : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : NULL
##   ..@ size         : NULL
##   ..@ hjust        : NULL
##   ..@ vjust        : num 0
##   ..@ angle        : NULL
##   ..@ lineheight   : NULL
##   ..@ margin       : <ggplot2::margin> num [1:4] 0 0 2.4 0
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ axis.text.x.bottom              : NULL
##  $ axis.text.y                     : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : NULL
##   ..@ size         : NULL
##   ..@ hjust        : num 1
##   ..@ vjust        : NULL
##   ..@ angle        : NULL
##   ..@ lineheight   : NULL
##   ..@ margin       : <ggplot2::margin> num [1:4] 0 2.4 0 0
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ axis.text.y.left                : NULL
##  $ axis.text.y.right               : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : NULL
##   ..@ size         : NULL
##   ..@ hjust        : num 0
##   ..@ vjust        : NULL
##   ..@ angle        : NULL
##   ..@ lineheight   : NULL
##   ..@ margin       : <ggplot2::margin> num [1:4] 0 0 0 2.4
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ axis.text.theta                 : NULL
##  $ axis.text.r                     : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : NULL
##   ..@ size         : NULL
##   ..@ hjust        : num 0.5
##   ..@ vjust        : NULL
##   ..@ angle        : NULL
##   ..@ lineheight   : NULL
##   ..@ margin       : <ggplot2::margin> num [1:4] 0 2.4 0 2.4
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ axis.ticks                      : <ggplot2::element_line>
##   ..@ colour       : Named chr "#93a1a1"
##  .. .. - attr(*, "names")= chr "rebase01"
##   ..@ linewidth    : NULL
##   ..@ linetype     : NULL
##   ..@ lineend      : NULL
##   ..@ linejoin     : NULL
##   ..@ arrow        : logi FALSE
##   ..@ arrow.fill   : Named chr "#93a1a1"
##  .. .. - attr(*, "names")= chr "rebase01"
##   ..@ inherit.blank: logi FALSE
##  $ axis.ticks.x                    : NULL
##  $ axis.ticks.x.top                : NULL
##  $ axis.ticks.x.bottom             : NULL
##  $ axis.ticks.y                    : NULL
##  $ axis.ticks.y.left               : NULL
##  $ axis.ticks.y.right              : NULL
##  $ axis.ticks.theta                : NULL
##  $ axis.ticks.r                    : NULL
##  $ axis.minor.ticks.x.top          : NULL
##  $ axis.minor.ticks.x.bottom       : NULL
##  $ axis.minor.ticks.y.left         : NULL
##  $ axis.minor.ticks.y.right        : NULL
##  $ axis.minor.ticks.theta          : NULL
##  $ axis.minor.ticks.r              : NULL
##  $ axis.ticks.length               : 'rel' num 0.5
##  $ axis.ticks.length.x             : NULL
##  $ axis.ticks.length.x.top         : NULL
##  $ axis.ticks.length.x.bottom      : NULL
##  $ axis.ticks.length.y             : NULL
##  $ axis.ticks.length.y.left        : NULL
##  $ axis.ticks.length.y.right       : NULL
##  $ axis.ticks.length.theta         : NULL
##  $ axis.ticks.length.r             : NULL
##  $ axis.minor.ticks.length         : 'rel' num 0.75
##  $ axis.minor.ticks.length.x       : NULL
##  $ axis.minor.ticks.length.x.top   : NULL
##  $ axis.minor.ticks.length.x.bottom: NULL
##  $ axis.minor.ticks.length.y       : NULL
##  $ axis.minor.ticks.length.y.left  : NULL
##  $ axis.minor.ticks.length.y.right : NULL
##  $ axis.minor.ticks.length.theta   : NULL
##  $ axis.minor.ticks.length.r       : NULL
##  $ axis.line                       : <ggplot2::element_line>
##   ..@ colour       : Named chr "#93a1a1"
##  .. .. - attr(*, "names")= chr "rebase01"
##   ..@ linewidth    : NULL
##   ..@ linetype     : num 1
##   ..@ lineend      : NULL
##   ..@ linejoin     : NULL
##   ..@ arrow        : logi FALSE
##   ..@ arrow.fill   : Named chr "#93a1a1"
##  .. .. - attr(*, "names")= chr "rebase01"
##   ..@ inherit.blank: logi FALSE
##  $ axis.line.x                     : NULL
##  $ axis.line.x.top                 : NULL
##  $ axis.line.x.bottom              : NULL
##  $ axis.line.y                     : NULL
##  $ axis.line.y.left                : NULL
##  $ axis.line.y.right               : NULL
##  $ axis.line.theta                 : NULL
##  $ axis.line.r                     : NULL
##  $ legend.background               : <ggplot2::element_rect>
##   ..@ fill         : NULL
##   ..@ colour       : logi NA
##   ..@ linewidth    : NULL
##   ..@ linetype     : NULL
##   ..@ linejoin     : NULL
##   ..@ inherit.blank: logi FALSE
##  $ legend.margin                   : NULL
##  $ legend.spacing                  : 'rel' num 2
##  $ legend.spacing.x                : NULL
##  $ legend.spacing.y                : NULL
##  $ legend.key                      : <ggplot2::element_rect>
##   ..@ fill         : NULL
##   ..@ colour       : NULL
##   ..@ linewidth    : NULL
##   ..@ linetype     : num 0
##   ..@ linejoin     : NULL
##   ..@ inherit.blank: logi FALSE
##  $ legend.key.size                 : 'simpleUnit' num 1.2lines
##   ..- attr(*, "unit")= int 3
##  $ legend.key.height               : NULL
##  $ legend.key.width                : NULL
##  $ legend.key.spacing              : NULL
##  $ legend.key.spacing.x            : NULL
##  $ legend.key.spacing.y            : NULL
##  $ legend.key.justification        : NULL
##  $ legend.frame                    : NULL
##  $ legend.ticks                    : NULL
##  $ legend.ticks.length             : 'rel' num 0.2
##  $ legend.axis.line                : NULL
##  $ legend.text                     : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : NULL
##   ..@ size         : 'rel' num 0.8
##   ..@ hjust        : NULL
##   ..@ vjust        : NULL
##   ..@ angle        : NULL
##   ..@ lineheight   : NULL
##   ..@ margin       : NULL
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ legend.text.position            : NULL
##  $ legend.title                    : <ggplot2::element_text>
##   ..@ family       : NULL
##   ..@ face         : NULL
##   ..@ italic       : chr NA
##   ..@ fontweight   : num NA
##   ..@ fontwidth    : num NA
##   ..@ colour       : NULL
##   ..@ size         : NULL
##   ..@ hjust        : num 0
##   ..@ vjust        : NULL
##   ..@ angle        : NULL
##   ..@ lineheight   : NULL
##   ..@ margin       : NULL
##   ..@ debug        : NULL
##   ..@ inherit.blank: logi TRUE
##  $ legend.title.position           : NULL
##  $ legend.position                 : chr "right"
##  $ legend.position.inside          : NULL
##  $ legend.direction                : NULL
##  $ legend.byrow                    : NULL
##  $ legend.justification            : chr "center"
##  $ legend.justification.top        : NULL
##  $ legend.justification.bottom     : NULL
##  $ legend.justification.left       : NULL
##  $ legend.justification.right      : NULL
##  $ legend.justification.inside     : NULL
##   [list output truncated]
##  @ complete: logi TRUE
##  @ validate: logi TRUE

I created 3 plots, the first 2 were box plots that showed the relationship between Sleep_difference and Exercise group, and Sleep_efficiency and Exercise group. The last one was a scatterplot to look at the relationship between Sleep_efficiency and Sleep_difference.

3.6 T-Tests

ind_t_test_sex<- t.test(Sleep_Difference ~ Sex, data = clean_sleep_data)
ind_t_test_sex
## 
##  Welch Two Sample t-test
## 
## data:  Sleep_Difference by Sex
## t = 1.7108, df = 46.409, p-value = 0.0938
## alternative hypothesis: true difference in means between group Female and group Male is not equal to 0
## 95 percent confidence interval:
##  -0.05259837  0.64926503
## sample estimates:
## mean in group Female   mean in group Male 
##            0.8566667            0.5583333

The mean for the female group is 0.8566667, and the mean for the male group is 0.5583333. The p-value is 0.0938, making the differences not statistically significant.

ind_t_test_age<- t.test(Sleep_Difference ~ AgeGroup2, data = clean_sleep_data)
ind_t_test_age
## 
##  Welch Two Sample t-test
## 
## data:  Sleep_Difference by AgeGroup2
## t = 0.0070374, df = 24.033, p-value = 0.9944
## alternative hypothesis: true difference in means between group 40 and group 40+ is not equal to 0
## 95 percent confidence interval:
##  -0.3838214  0.3864481
## sample estimates:
##  mean in group 40 mean in group 40+ 
##         0.7243902         0.7230769

The mean for age group 40 is 0.7243902, and the mean for group 40+ is 0.7230769. The p-value is 0.9944, making the difference not statistically significant.

I ran independent t-tests for Sleep_difference and sex, and another one for Sleep_difference by AgeGroup2.

3.7 Anovas + Post-Hocs

anova_sleep_difference<- aov(Sleep_Difference ~ Exercise_Group, data = clean_sleep_data)
summary(anova_sleep_difference)
##                Df Sum Sq Mean Sq F value   Pr(>F)    
## Exercise_Group  2  9.292   4.646    19.1 6.44e-07 ***
## Residuals      51 12.406   0.243                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 7 observations deleted due to missingness
supernova(anova_sleep_difference)
##  Analysis of Variance Table (Type III SS)
##  Model: Sleep_Difference ~ Exercise_Group
## 
##                              SS df    MS      F   PRE     p
##  ----- --------------- | ------ -- ----- ------ ----- -----
##  Model (error reduced) |  9.292  2 4.646 19.099 .4282 .0000
##  Error (from model)    | 12.406 51 0.243                   
##  ----- --------------- | ------ -- ----- ------ ----- -----
##  Total (empty model)   | 21.699 53 0.409
TukeyHSD(anova_sleep_difference)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = Sleep_Difference ~ Exercise_Group, data = clean_sleep_data)
## 
## $Exercise_Group
##                             diff        lwr         upr     p adj
## Cardio+Weights-Cardio -0.2960526 -0.6774802  0.08537496 0.1567301
## None-Cardio           -1.0343860 -1.4456196 -0.62315233 0.0000005
## None-Cardio+Weights   -0.7383333 -1.1450060 -0.33166066 0.0001710
plot(TukeyHSD(anova_sleep_difference))

The F-value is 19.1, the df are 2 and 51, the p-value is .0000, the PRE is 42.82%. Looking at the adjusted p-values, None-Cardio and None-Cardio+Weights are the 2 groups that are statistically significant.

anova_sleep_efficiency<- aov(Sleep_Efficiency ~ Exercise_Group, data = clean_sleep_data)
summary(anova_sleep_efficiency)
##                Df Sum Sq Mean Sq F value  Pr(>F)   
## Exercise_Group  2  412.7  206.36   5.648 0.00574 **
## Residuals      58 2119.1   36.54                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
supernova(anova_sleep_efficiency)
##  Analysis of Variance Table (Type III SS)
##  Model: Sleep_Efficiency ~ Exercise_Group
## 
##                                SS df      MS     F   PRE     p
##  ----- --------------- | -------- -- ------- ----- ----- -----
##  Model (error reduced) |  412.718  2 206.359 5.648 .1630 .0057
##  Error (from model)    | 2119.074 58  36.536                  
##  ----- --------------- | -------- -- ------- ----- ----- -----
##  Total (empty model)   | 2531.792 60  42.197
TukeyHSD(anova_sleep_efficiency)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = Sleep_Efficiency ~ Exercise_Group, data = clean_sleep_data)
## 
## $Exercise_Group
##                             diff        lwr       upr     p adj
## Cardio+Weights-Cardio  0.7886364  -3.703252  5.280525 0.9065424
## None-Cardio           -5.1592105  -9.816907 -0.501514 0.0265716
## None-Cardio+Weights   -5.9478469 -10.501233 -1.394461 0.0073440
plot(TukeyHSD(anova_sleep_efficiency))

The F-value is 5.648, the df are 2 and 58, the p-value is 0.0057, the PRE is 16.30%. Looking at the adjusted p values, None-Cardio and None-Cardio+Weights are the 2 statistically significant groups.

I ran 2 ANOVAs, one for Sleep_difference and Exercise group, and the other for Sleep_efficiency and Exercise group. I also ran a Tukey post-hoc test for both ANOVAs.

3.8 Synthesis & Reccomendation

Considering both outcomes (Sleep Difference and Sleep Efficiency) of the anova and post-hoc tests, I would recommend cardio and weights as the exercise regimen to improve overall sleep. The reason for this is because in both the post-hoc tests we can see that cardio+weights-cardio has the smallest difference compared to the other 2 combinations in both tests. Although in the sleep efficiency ~ exercise group post-hoc test the difference between cardio+weights and none is the largest out of the 3 combinations (-5.9478469), it looks like ‘None’ is causing the difference to be large, and not cardio+weight. In the sleep difference ~ exercise group post-hoc test, none - cardio have the largest negative difference out of the the 3 combinations (-1.0343860), with none - cardio+weights having the second largest (-0.7383333), and cardio+weights - cardio having the smallest difference (-0.2960526), conveying that cardio+weight must be the exercise regimen that helps to improve overall sleep. We could also see the differences and their sizes in the plot of the Tukey post-hoc test above.

3.9 Reflection

One challenging thing for me while creating this report was trying to clean the pre_sleep column and just make it numeric, without any characters. One thing I was confident about was cleaning and merging the data, as well as conducting descriptive statistics. Next time, I would like to try to improve on cleaning specific columns like what I had to do with the pre_sleep column.