#' --- #' title: "Graphical analysis of Duncan data" #' author: "Michael Friendly" #' date: "03 Apr 2017" #' --- #+ echo=FALSE knitr::opts_chunk$set(warning=FALSE, message=FALSE, collapse=TRUE) #' ## load car package and the data library(car) data(Duncan, package="carData") head(Duncan) # first few observations #' ## standard pairs plot plot(~ prestige + income + education, data=Duncan) pairs(~prestige + income + education, data=Duncan) #' ### enhanced version scatterplotMatrix(~prestige + income + education, data=Duncan, id.n=2) #' ## model plots duncan.mod <- lm(prestige ~ income + education, data=Duncan) op <- par(mfrow=c(2,2), mar=c(4,4,2,1)+.1) plot(duncan.mod, cex=1.2, cex.lab=1.2, pch=16, lwd=3) par(op) #' ### better version of an influence plot influencePlot(duncan.mod, id.n=3) #' ### added variable plots show the partial relations of each preditor avPlots(duncan.mod, id.n=2, pch=16, ellipse=TRUE, ellipse.args=list(levels=0.68, fill=TRUE, fill.alpha=0.1)) #' ## effect plots library(effects) duncan.eff <- allEffects(duncan.mod) plot(duncan.eff) #' ### add term for type of job duncan.mod1 <- update(duncan.mod, . ~ . + type) summary(duncan.mod1) duncan.eff1 <- allEffects(duncan.mod1) plot(duncan.eff1) plot(duncan.eff1, ci.style="bands", rows=1, cols=3) #' ## coefficient plots library(coefplot) duncan.mod2 <- lm(prestige ~ income * education, data=Duncan) coefplot(duncan.mod2, intercept=FALSE, lwdInner=2, lwdOuter=1, point.size=5, title="Coefficient plot for duncan.mod2") + theme_bw()