########################################################################### # PUBLG100: Introduction to Quantitative Methods # # Week 6 Solutions: Assumptions and Violations of Assumptions # # ## ------------------------------------------------------------------------ rm(list = ls()) ## ----message = FALSE----------------------------------------------------- library(lmtest) library(sandwich) library(texreg) library(dplyr) ## ------------------------------------------------------------------------ MA_schools <- read.csv("MA_Schools.csv") ## ------------------------------------------------------------------------ model1 <- lm(score8 ~ english, data = MA_schools) summary(model1) ## ------------------------------------------------------------------------ plot(score8 ~ english, data = MA_schools) abline(model1, col = "red") ## ------------------------------------------------------------------------ summary(select(MA_schools, score8, stratio, english, lunch, income)) ## ------------------------------------------------------------------------ cor(select(MA_schools, score8, stratio, english, lunch, income)) ## ------------------------------------------------------------------------ cor(select(MA_schools, score8, stratio, english, lunch, income), use = "pairwise.complete.obs") ## ------------------------------------------------------------------------ model2 <- lm(score8 ~ english + lunch + income, data = MA_schools) summary(model2) ## ------------------------------------------------------------------------ screenreg(list(model1, model2)) ## ------------------------------------------------------------------------ plot(fitted(model2), residuals(model2)) ## ------------------------------------------------------------------------ bptest(model2)