# Run this code to load the required packages
suppressMessages(suppressWarnings(suppressPackageStartupMessages({
library(mosaic)
library(supernova)
library(Lock5withR)
})))
# To make slightly smaller plots
options(repr.plot.width = 5, repr.plot.height = 3)
CensusSchool <- read.csv("https://docs.google.com/spreadsheets/d/e/2PACX-1vSVaWnM4odSxy0mlnhWvvGbeLtiKoZmsbqC6KLzXtBOjQfrF9EVKuX4RVh3XbP3iw/pub?gid=2100178416&single=true&output=csv", header = TRUE)
str(CensusSchool)
select(CensusSchool, Sleep_Hours_Schoolnight, Texting_Messaging_Hours)
CensusSchool$Texting_Messaging_Hours
gf_jitter(Sleep_Hours_Schoolnight ~ Texting_Messaging_Hours, data = CensusSchool)
newHours <- filter(CensusSchool, Texting_Messaging_Hours < 24*7)
NewSchoolHours <- filter(newHours, Sleep_Hours_Schoolnight < 12)
NewSchoolHours1 <- filter(NewSchoolHours, Sleep_Hours_Schoolnight >= 1)
Texting_Sleep <- filter(NewSchoolHours1, Sleep_Hours_Schoolnight != 0)
gf_bar(~ Texting_Messaging_Hours, data = Texting_Sleep, width = 20)
gf_bar(~ Sleep_Hours_Schoolnight, data = Texting_Sleep, width = 6)
gf_jitter(Sleep_Hours_Schoolnight ~ Texting_Messaging_Hours, data = Texting_Sleep, alpha = 0.1)
gf_jitter(Sleep_Hours_Schoolnight ~ Texting_Messaging_Hours, data = Texting_Sleep, alpha = 0.2, color = "goldenrod")
gf_jitter(Sleep_Hours_Schoolnight ~ shuffle(Texting_Messaging_Hours), data = Texting_Sleep, alpha = 0.2, color = "darkorchid1")
sleep_empty <- lm(Sleep_Hours_Schoolnight ~ NULL, data = Texting_Sleep)
sleep_empty
sleep_model <- lm(Sleep_Hours_Schoolnight ~ Texting_Messaging_Hours, data = Texting_Sleep)
sleep_model
gf_jitter(Sleep_Hours_Schoolnight ~ Texting_Messaging_Hours, data = Texting_Sleep, color = "magenta", alpha = 1) %>%
gf_hline(yintercept = 6.80, color = "orange")
Sleep_pred <- predict(sleep_model)
gf_jitter(Sleep_Hours_Schoolnight ~ Texting_Messaging_Hours, data = Texting_Sleep, color = "magenta", alpha = 1) %>%
gf_jitter(Sleep_pred ~ Texting_Messaging_Hours, color = "blue") %>%
gf_hline(yintercept = 6.80, color = "orange")
supernova(sleep_model)
sampleF <- fVal(Sleep_Hours_Schoolnight ~ Texting_Messaging_Hours, data = Texting_Sleep)
sdof <- do(1000) * fVal(Sleep_Hours_Schoolnight ~ shuffle(Texting_Messaging_Hours), data = Texting_Sleep)
gf_histogram(~ fVal, data = sdof)
gf_histogram(~ fVal, data = sdof,fill = ~fVal>sampleF) %>%
gf_point(0 ~ fVal(Sleep_Hours_Schoolnight ~ Texting_Messaging_Hours, data = Texting_Sleep))
confint(sleep_model)