# Run this code to load the required packages
suppressMessages(suppressWarnings(suppressPackageStartupMessages({
library(mosaic)
library(supernova)
library(Lock5withR)
})))
# Adjust the plots to be a bit smaller
options(repr.plot.width = 6, repr.plot.height = 4)
CensusSchool <- read.csv("https://docs.google.com/spreadsheets/d/e/2PACX-1vSVaWnM4odSxy0mlnhWvvGbeLtiKoZmsbqC6KLzXtBOjQfrF9EVKuX4RVh3XbP3iw/pub?gid=2100178416&single=true&output=csv", header = TRUE)
str(CensusSchool)
CensusG<- filter(CensusSchool, Sleep_Hours_Schoolnight !="NA", Doing_Homework_Hours !="NA")
CensusSchool <- filter(CensusSchool, Sleep_Hours_Schoolnight <= 24*7)
CensusSchool <- filter(CensusSchool, Doing_Homework_Hours <= 24*7)
gf_jitter(Sleep_Hours_Schoolnight~Doing_Homework_Hours, data = CensusG, color = "blue")
sleep.model <- lm(Sleep_Hours_Schoolnight ~ Doing_Homework_Hours, data = CensusG)
sleep.model
CensusG<-filter(CensusG, Sleep_Hours_Schoolnight<= 24*7)
CensusG<-filter(CensusG, Doing_Homework_Hours!="NA")
Empty.model<- lm(Sleep_Hours_Schoolnight~NULL, data = CensusG)
sleep.model<- lm(Sleep_Hours_Schoolnight~Doing_Homework_Hours, data= CensusG)
predict(Empty.model)-> CensusG$Empty.Pred
predict(sleep.model)-> CensusG$sleep.Pred
head(CensusG)
gf_jitter(Sleep_Hours_Schoolnight~Doing_Homework_Hours, data = CensusG, color = "magenta")%>%
gf_jitter(predict(Empty.model)~Doing_Homework_Hours, color = "blue", height= 0)%>%
gf_jitter(predict(sleep.model)~Doing_Homework_Hours, color= "orange", height=0)
supernova(sleep.model)
model<- lm(Sleep_Hours_Schoolnight~Doing_Homework_Hours, data=CensusG)
confint(model)
samplePRE<- PRE(Sleep_Hours_Schoolnight~ Doing_Homework_Hours, data=CensusG)
sdoPRE <- do(1000)* PRE(Sleep_Hours_Schoolnight ~shuffle(Doing_Homework_Hours), data= CensusG)
gf_histogram(~PRE, data=sdoPRE)%>%
gf_point(0 ~ samplePRE, color = "magenta")
tally(~ PRE > samplePRE, data= sdoPRE, format= "proportion")