# 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)
Introduction
CensusSchool2<-select(CensusSchool, Doing_Homework_Hours, Travel_to_School)
CensusSchool2 <- filter(CensusSchool2, Doing_Homework_Hours != "NA", Travel_to_School !="NA")
filter(CensusSchool2,Doing_Homework_Hours<= 20,Doing_Homework_Hours> -1)-> CensusSchool2
gf_histogram(~Doing_Homework_Hours, data=CensusSchool2, fill="orange", color="black")
gf_bar(~Travel_to_School,data=CensusSchool2, fill="purple", color="black")->bargraph
bargraph+coord_flip()
gf_boxplot(Doing_Homework_Hours~Travel_to_School, data=CensusSchool2)->boxplot
boxplot+coord_flip()
lm(Doing_Homework_Hours~Travel_to_School, data=CensusSchool2)
travel.model<-lm(Doing_Homework_Hours~Travel_to_School, data=CensusSchool2)
supernova(travel.model)
GLM Notation
$Y_i = 7.30 + -4.60X_i + -1.1X_i + -0.33+ 1.44X_i+ -0.062X_i + -2.35X_i+ 1.18X_i + e_i$
empty.model<-lm(Doing_Homework_Hours~ NULL, data = CensusSchool2)
travel.model <- lm(Doing_Homework_Hours~Travel_to_School, data=CensusSchool2)
gf_jitter(Doing_Homework_Hours~Travel_to_School, data=CensusSchool2, width = .2, color = "purple", size = 2) %>%
gf_jitter(predict(empty.model) ~ Travel_to_School, height = 0, color = "blue") %>%
gf_jitter(predict(travel.model) ~ Travel_to_School, height = 0, color = "orange")->jitter
jitter+coord_flip()
$b_0$: average predicted homework hours when Travel_to_School is at 0
$b_1$: the increment you add or remove for Travel_to_School
samplePRE<-PRE(Doing_Homework_Hours~ Travel_to_School, data = CensusSchool2)
sdoPRE<-do(1000)*PRE(Doing_Homework_Hours~ shuffle(Travel_to_School), data = CensusSchool2)
gf_histogram(~PRE, data=sdoPRE)%>%
gf_point(0~samplePRE, color="magenta")
tally(~PRE > samplePRE, data=sdoPRE)
confint(travel.model)