#install.packages("AER")
library("AER")
data("CASchools")
teacher_stu_ratio <- CASchools$students/CASchools$teachers
lm_math <- lm(CASchools$math ~ teacher_stu_ratio)
resid<- lm_math$residuals
plot(teacher_stu_ratio, resid,
ylab="Residuals", xlab="teacher_stu_ratio",
main="Residual Plot - Math")
abline(0, 0, col="red") # the horizon
lm_read <- lm(CASchools$read ~ teacher_stu_ratio)
resid<- lm_read$residuals
plot(teacher_stu_ratio, resid,
ylab="Residuals", xlab="teacher_stu_ratio",
main="Residual Plot - Read")
abline(0, 0, col="red") # the horizon
Regression:
plot(CASchools$math ~ teacher_stu_ratio)
regLine(lm_math)
summary(lm_math)
Call:
lm(formula = CASchools$math ~ teacher_stu_ratio)
Residuals:
Min 1Q Median 3Q Max
-44.615 -13.374 -0.828 12.728 52.711
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 691.4174 9.3825 73.692 < 2e-16 ***
teacher_stu_ratio -1.9386 0.4755 -4.077 5.47e-05 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 18.41 on 418 degrees of freedom
Multiple R-squared: 0.03824, Adjusted R-squared: 0.03594
F-statistic: 16.62 on 1 and 418 DF, p-value: 5.467e-05
plot(CASchools$read ~ teacher_stu_ratio)
regLine(lm_read)
summary(lm_read)
Call:
lm(formula = CASchools$read ~ teacher_stu_ratio)
Residuals:
Min 1Q Median 3Q Max
-50.839 -14.479 1.121 14.495 44.370
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 706.4485 9.9410 71.064 < 2e-16 ***
teacher_stu_ratio -2.6210 0.5038 -5.202 3.09e-07 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 19.51 on 418 degrees of freedom
Multiple R-squared: 0.06081, Adjusted R-squared: 0.05856
F-statistic: 27.06 on 1 and 418 DF, p-value: 3.091e-07