library("AER")
Loading required package: car
Loading required package: lmtest
Loading required package: zoo
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
Loading required package: sandwich
Loading required package: survival
data("CASchools")
teacher_stu_ratio <- CASchools$students/CASchools$teachers
lm_classsize <- lm(CASchools$math ~ teacher_stu_ratio)
plot(CASchools$math ~ teacher_stu_ratio)
regLine(lm_classsize)
inc <- CASchools$income
lm_inc <- lm(CASchools$math ~ inc)
plot(CASchools$math ~ inc)
regLine(lm_inc)
lm_combined <- lm(CASchools$math ~ inc+teacher_stu_ratio)
covariance<-data.frame(CASchools[,c(11,14)],teacher_stu_ratio)
head(covariance)
plot(covariance, pch=10, col="blue", main="All Correlations Presented")
lm_classsize$coefficients[2]
teacher_stu_ratio
-1.938591
lm_combined$coefficients[3]
teacher_stu_ratio
-0.3474342
The effect decreased substantially since beforehand the chagne was attributed to it, but now we introduced more posible explanatory variables.
Run Model 5: Test Scores = F(STR, income, english)
lm_w_english <- lm(CASchools$math~ teacher_stu_ratio+ inc + CASchools$english)
df_eng<-data.frame(CASchools[,c(11,12,14)],teacher_stu_ratio)
plot(df_eng, pch=10, col="blue", main="All Correlations Presented")
Compare Model 5 to Model 6: Test Scores = F(STR, income, income squared, english). Use adjusted r-squared to argue for the best specification.
lm_inc_squared <- lm(CASchools$math~ teacher_stu_ratio+ inc +inc**2 +CASchools$english)
inc_sq<-data.frame(CASchools[,c(11,12,14)],inc**2, teacher_stu_ratio)
head(inc_sq)
plot(inc_sq, pch=10, col="blue", main="All Correlations Presented")
Use stargazer to put all the models in one regression table (adjust the font size if need be, so it can fit in a single page on the googe doc.)
#install.packages("stargazer")
library(stargazer)
Please cite as:
Hlavac, Marek (2018). stargazer: Well-Formatted Regression and Summary Statistics Tables.
R package version 5.2.1. https://CRAN.R-project.org/package=stargazer
stargazer(lm_classsize,lm_combined,lm_inc_squared, lm_w_english,align=TRUE, no.space=TRUE, type = "text", font.size = "footnotesize")
======================================================================================================================
Dependent variable:
--------------------------------------------------------------------------------------------------
math
(1) (2) (3) (4)
----------------------------------------------------------------------------------------------------------------------
inc 1.794*** 1.510*** 1.510***
(0.093) (0.083) (0.083)
english -0.402*** -0.402***
(0.033) (0.033)
teacher_stu_ratio -1.939*** -0.347 0.130 0.130
(0.476) (0.356) (0.307) (0.307)
Constant 691.417*** 632.687*** 633.994*** 633.994***
(9.382) (7.489) (6.411) (6.411)
----------------------------------------------------------------------------------------------------------------------
Observations 420 420 420 420
R2 0.038 0.490 0.627 0.627
Adjusted R2 0.036 0.488 0.625 0.625
Residual Std. Error 18.414 (df = 418) 13.421 (df = 417) 11.488 (df = 416) 11.488 (df = 416)
F Statistic 16.620*** (df = 1; 418) 200.580*** (df = 2; 417) 233.552*** (df = 3; 416) 233.552*** (df = 3; 416)
======================================================================================================================
Note: *p<0.1; **p<0.05; ***p<0.01
#,lm_inc missing