# 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)
newhours<- filter(CensusSchool, Doing_Homework_Hours > 2, Doing_Homework_Hours < 5, Sleep_Hours_Schoolnight>2, Sleep_Hours_Schoolnight<9)
#sleephours<-filter (CensusSchool, Sleep_Hours_Schoolnight >2, Sleep_Hours_Schoolnight <9)
gf_point(Sleep_Hours_Schoolnight ~ Doing_Homework_Hours, data = newhours)
lm(Doing_Homework_Hours ~ Sleep_Hours_Schoolnight,data= newhours)
lm(Sleep_Hours_Schoolnight~Doing_Homework_Hours,data= newhours)
sleep.model<-lm(Sleep_Hours_Schoolnight~ Doing_Homework_Hours,data = newhours)
predict(sleep.model)->newhours$sleep.pred
supernova(sleep.model)
homework.model<-lm(Doing_Homework_Hours~ Sleep_Hours_Schoolnight,data = newhours)
predict(homework.model)->newhours$homework.pred
supernova(homework.model)
gf_point(Sleep_Hours_Schoolnight~ Doing_Homework_Hours, data= newhours)%>%gf_point(sleep.pred~ Sleep_Hours_Schoolnight, data= newhours, color ="magenta", size= 3)
gf_point(Doing_Homework_Hours ~Sleep_Hours_Schoolnight, data= newhours)%>%gf_point(homework.pred~ Doing_Homework_Hours, data= newhours, color ="magenta", size= 3)
empty_model <- lm(Sleep_Hours_Schoolnight~ NULL, data = newhours)
sleephours.model <- lm(Sleep_Hours_Schoolnight~ Doing_Homework_Hours, data = newhours)
gf_jitter(Sleep_Hours_Schoolnight~ Doing_Homework_Hours, data = newhours, width = .6, size = 2) %>%
gf_jitter(predict(empty_model) ~ Doing_Homework_Hours,color = "blue") %>%
gf_jitter(predict(sleephours.model) ~ Doing_Homework_Hours,color = "magenta")
empty_model <- lm(Doing_Homework_Hours~ NULL, data = newhours)
homework.model <- lm(Doing_Homework_Hours~ Sleep_Hours_Schoolnight, data = newhours)
gf_jitter(Doing_Homework_Hours~ Sleep_Hours_Schoolnight, data = newhours, width = .6, size = 2) %>%
gf_jitter(predict(empty_model) ~ Sleep_Hours_Schoolnight,color = "pink") %>%
gf_jitter(predict(homework.model) ~ Sleep_Hours_Schoolnight,color = "magenta")
supernova(sleephours.model)
supernova(homework.model)
confint(sleephours.model)
confint(homework.model)
fVal( Sleep_Hours_Schoolnight~ Doing_Homework_Hours, data=newhours)->samplef
do(1000)*fVal( Sleep_Hours_Schoolnight~ shuffle(Doing_Homework_Hours),data=newhours)->sdof
gf_histogram(~fVal, data = sdof,fill=~fVal>samplef)
samplef
fVal(Doing_Homework_Hours~Sleep_Hours_Schoolnight, data=newhours)->samplef
do(1000)*fVal( Doing_Homework_Hours~ shuffle(Sleep_Hours_Schoolnight),data=newhours)->sdof
gf_histogram(~fVal, data = sdof,fill=~fVal>samplef)
sdopre <- do(1000) * PRE(Sleep_Hours_Schoolnight~ shuffle(Doing_Homework_Hours), data = newhours)
gf_histogram(~ PRE, data = sdopre) %>%
gf_point(0 ~ PRE(Sleep_Hours_Schoolnight~ Doing_Homework_Hours, data = newhours))
sdopre <- do(1000) * PRE(Doing_Homework_Hours~ shuffle(Sleep_Hours_Schoolnight), data = newhours)
gf_histogram(~ PRE, data = sdopre) %>%
gf_point(0 ~ PRE(Doing_Homework_Hours~ Sleep_Hours_Schoolnight, data = newhours))