Data frame msleep
is a dataset available in ggplot2
. It contains information on 83 mammals with regards to their sleep behavior. To get started, load packages tidyverse
and infer
.
library(tidyverse)
library(infer)
Below is a basic custom theme. Feel free to try it out when you use ggplot()
. Simply add it as a layer to your plot. Rather than using theme_bw()
you can use theme_custom()
. This custom theme increases the font point size on axes and their labels.
theme_custom <- function() {
theme_bw() +
theme(axis.title = element_text(size = 16),
title = element_text(size = 20),
axis.text.x = element_text(size = 12),
axis.text.y = element_text(size = 12),
plot.caption = element_text(size = 10))
}
Take a glimpse()
at the data below
glimpse(msleep)
Observations: 83
Variables: 11
$ name <chr> "Cheetah", "Owl monkey", "Mountain beaver", "Grea...
$ genus <chr> "Acinonyx", "Aotus", "Aplodontia", "Blarina", "Bo...
$ vore <chr> "carni", "omni", "herbi", "omni", "herbi", "herbi...
$ order <chr> "Carnivora", "Primates", "Rodentia", "Soricomorph...
$ conservation <chr> "lc", NA, "nt", "lc", "domesticated", NA, "vu", N...
$ sleep_total <dbl> 12.1, 17.0, 14.4, 14.9, 4.0, 14.4, 8.7, 7.0, 10.1...
$ sleep_rem <dbl> NA, 1.8, 2.4, 2.3, 0.7, 2.2, 1.4, NA, 2.9, NA, 0....
$ sleep_cycle <dbl> NA, NA, NA, 0.1333333, 0.6666667, 0.7666667, 0.38...
$ awake <dbl> 11.9, 7.0, 9.6, 9.1, 20.0, 9.6, 15.3, 17.0, 13.9,...
$ brainwt <dbl> NA, 0.01550, NA, 0.00029, 0.42300, NA, NA, NA, 0....
$ bodywt <dbl> 50.000, 0.480, 1.350, 0.019, 600.000, 3.850, 20.4...
For all the questions that follow, use a sequence of functions in package infer
. For details on msleep
, type ?msleep
in your console.
Create a 95% confidence interval for the mean amount of hours all mammals are awake per day. Also, plot the simulated bootstrap distribution.
Create 90% and 99% confidence intervals for the mean amount of hours all mammals are awake per day. What do you notice about the widths of the three intervals?
Past research has shown that humans have a median sleep time of 7.5 hours per day. Researchers want to investigate if all other mammals have a higher median number of sleep hours per day. A random sample of 82 mammals revealed a median number of sleep hours per day to be 10.1 hours. Is this enough evidence to suggest mammals that are not human have a higher median number of sleep hours per day?
State the null and alternative hypotheses given the problem above.
Plot a histogram of the simulated null distribution and place a vertical line at the value of the observed sample median of 10.1.
Use the simulated null distribution to compute the p-value. Recall that the p-value is the probability of observing data at least as favorable to the alternative hypothesis as the current data set, given that the null hypothesis is true.
State your conclusion in the context of the problem.
V. M. Savage and G. B. West. A quantitative, theoretical framework for understanding mammalian sleep. Proceedings of the National Academy of Sciences, 104 (3):1051-1056, 2007.
https://cran.r-project.org/web/packages/infer/vignettes/flights_examples.html