library(car)
data(NLSY)
#examine the data
scatterplotMatrix(NLSY, smooth=FALSE)
# test control variables by themselves
# -------------------------------------
NLSY.mod1 <- lm(cbind(read, math) ~ income + educ, data=NLSY)
Anova(NLSY.mod1)
heplot(NLSY.mod1, fill=TRUE)
# test of overall regression
coefs <- rownames(coef(NLSY.mod1))[-1]
linearHypothesis(NLSY.mod1, coefs)
heplot(NLSY.mod1, fill=TRUE, hypotheses=list("Overall"=coefs))
# coefficient plot
coefplot(NLSY.mod1, fill = TRUE,
col = c("darkgreen", "brown"),
lwd = 2,
ylim = c(-0.5, 3),
main = "Bivariate coefficient plot for reading and math\nwith 95% confidence ellipses")
# additional contribution of antisoc + hyperact over income + educ
# ----------------------------------------------------------------
NLSY.mod2 <- lm(cbind(read,math) ~ antisoc + hyperact + income + educ, data=NLSY)
Anova(NLSY.mod2)
coefs <- rownames(coef(NLSY.mod2))[-1]
heplot(NLSY.mod2, fill=TRUE, hypotheses=list("Overall"=coefs, "mod2|mod1"=coefs[1:2]))
linearHypothesis(NLSY.mod2, coefs[1:2])
heplot(NLSY.mod2, fill=TRUE, hypotheses=list("mod2|mod1"=coefs[1:2]))
# check for outliers
idx <- cqplot(NLSY.mod2, id.n = 5)
idx
Run the code above in your browser using DataLab