data(schooldata)
# initial screening
plot(schooldata)
# better plot
library(corrgram)
corrgram(schooldata,
lower.panel=panel.ellipse,
upper.panel=panel.pts)
#fit the MMreg model
school.mod <- lm(cbind(reading, mathematics, selfesteem) ~
education + occupation + visit + counseling + teacher, data=schooldata)
# shorthand: fit all others
school.mod <- lm(cbind(reading, mathematics, selfesteem) ~ ., data=schooldata)
car::Anova(school.mod)
# HE plots
heplot(school.mod, fill=TRUE, fill.alpha=0.1)
pairs(school.mod, fill=TRUE, fill.alpha=0.1)
# robust model, using robmlm()
school.rmod <- robmlm(cbind(reading, mathematics, selfesteem) ~ ., data=schooldata)
# note that counseling is now significant
car::Anova(school.rmod)
# Index plot of the weights
wts <- school.rmod$weights
notable <- which(wts < 0.8)
plot(wts, type = "h", col="gray", ylab = "Observation weight")
points(1:length(wts), wts,
pch=16,
col = ifelse(wts < 0.8, "red", "black"))
text(notable, wts[notable],
labels = notable,
pos = 3,
col = "red")
# compare classical HE plot with that based on the robust model
heplot(school.mod, cex=1.4, lty=1, fill=TRUE, fill.alpha=0.1)
heplot(school.rmod,
add=TRUE,
error.ellipse=TRUE,
lwd=c(2,2), lty=c(2,2),
term.labels=FALSE, err.label="",
fill=TRUE)
Run the code above in your browser using DataLab