## ----echo=FALSE, results='hide'------------------------------------------ source(".Rprofile") ## ------------------------------------------------------------------------ data(Policie, package = "mffSM") head(Policie) dim(Policie) summary(Policie) ## ----fig-CheckModelAssumpt-01-01, fig.ext='png', fig.path=FIGDIRPNG, fig.width=9, fig.height=6---- library("car") palette(c("darkblue", "red3", "olivedrab", rainbow_hcl(5))) scatterplotMatrix(~fat + height + weight, reg.line = lm, smooth = FALSE, spread = TRUE, diagonal = "histogram", data = Policie, pch = 16) ## ------------------------------------------------------------------------ mHeight <- lm(fat ~ height, data = Policie) summary(mHeight) ## ------------------------------------------------------------------------ mWeight <- lm(fat ~ weight, data = Policie) summary(mWeight) ## ------------------------------------------------------------------------ mHeWe <- lm(fat ~ height + weight, data = Policie) summary(mHeWe) ## ------------------------------------------------------------------------ (ybar <- with(Policie, mean(fat))) prY <- residuals(mHeWe, type = "partial") + ybar ## ----fig-CheckModelAssumpt-01-02, fig.ext='png', fig.path=FIGDIRPNG, fig.width=9, fig.height=6---- par(mfrow = c(1, 2), mar = c(4, 4, 2, 1) + 0.1, bty = BTY) # YLIM <- range(c(Policie[, "fat"], prY[, "height"])) bex <- round(coef(mHeWe)["height"], 2) bexCI <- round(confint(mHeWe)["height", ], 2) beMarg <- round(coef(mHeight)[2], 2) beMargCI <- round(confint(mHeight)[2, ], 2) # plot(fat ~ height, data = Policie, ylim = YLIM, main = "Marginal", xlab = "Height [cm]", ylab = "Fat [%]", pch = PCH, col = COL, bg = BGC) abline(mHeight, col = "blue3", lwd = 2) text(165, 25, labels = eval(substitute(expression(paste(hat(beta), " = ", be, " (", beCI1, ", ", beCI2, ")", sep="")), list(be = beMarg, beCI1 = beMargCI[1], beCI2 = beMargCI[2]))), pos = 4, cex = 1.7) # plot(prY[, "height"] ~ height, data = Policie, ylim = YLIM, main = "Partial", xlab = "Height [cm]", ylab = "Response-mean partial residuals [%]", pch = PCH3, col = COL3, bg = BGC3) abline(lm(prY[, "height"] ~ height, data = Policie), col = "red2", lwd = 2) text(165, 25, labels = eval(substitute(expression(paste(hat(beta), " = ", be, " (", beCI1, ", ", beCI2, ")", sep="")), list(be = bex, beCI1 = bexCI[1], beCI2 = bexCI[2]))), pos = 4, cex = 1.7) # par(mfrow = c(1, 1), mar = c(5, 4, 4, 1) + 0.1) ## ----fig-CheckModelAssumpt-01-03, fig.ext='png', fig.path=FIGDIRPNG, fig.width=9, fig.height=6---- par(mfrow = c(1, 2), mar = c(4, 4, 2, 1) + 0.1, bty = BTY) # YLIM <- range(c(Policie[, "fat"], prY[, "weight"])) bex <- format(round(coef(mHeWe)["weight"], 2), nsmall = 2) bexCI <- format(round(confint(mHeWe)["weight", ], 2), nsmall = 2) beMarg <- format(round(coef(mWeight)[2], 2), nsmall = 2) beMargCI <- format(round(confint(mWeight)[2, ], 2), nsmall = 2) # plot(fat ~ weight, data = Policie, ylim = YLIM, main = "Marginal", xlab = "Weight [kg]", ylab = "Fat [%]", pch = PCH, col = COL, bg = BGC) abline(mWeight, col = "blue3", lwd = 2) text(55, 29, labels = eval(substitute(expression(paste(hat(beta), " = ", be, " (", beCI1, ", ", beCI2, ")", sep="")), list(be = beMarg, beCI1 = beMargCI[1], beCI2 = beMargCI[2]))), pos = 4, cex = 1.7) # plot(prY[, "weight"] ~ weight, data = Policie, ylim = YLIM, main = "Partial", xlab = "Weight [kg]", ylab = "Response-mean partial residuals [%]", pch = PCH3, col = COL3, bg = BGC3) abline(lm(prY[, "weight"] ~ weight, data = Policie), col = "red2", lwd = 2) text(55, 29, labels = eval(substitute(expression(paste(hat(beta), " = ", be, " (", beCI1, ", ", beCI2, ")", sep="")), list(be = bex, beCI1 = bexCI[1], beCI2 = bexCI[2]))), pos = 4, cex = 1.7) # par(mfrow = c(1, 1), mar = c(5, 4, 4, 1) + 0.1)