```{r setup, include=FALSE, cache=FALSE}
library(rgl)
options(format.R.blank=FALSE)
options(width=80)
options(continue=" ")
options(replace.assign=TRUE)
options(scipen=8, digits=4)
knitr::opts_chunk$set(
size = 'small',
par=TRUE,
tidy=FALSE,
prompt=FALSE,
comment=NA,
echo=TRUE,
collapse=TRUE
)
knitr::opts_chunk$set(cache=FALSE)
# Tighten the spacing within R output from knitr
hook1 <- function(x){ gsub("```\n*```r*\n*", "", x) }
hook2 <- function(x){ gsub("```\n+```\n", "", x) }
knitr::knit_hooks$set(
webgl = hook_webgl,
rgl.static = hook_rgl, # use to capture a single rgl graphic
crop=knitr::hook_pdfcrop,
inline = function(x) {
if(is.numeric(x)){
return(prettyNum(x, big.mark=","))
}else{
return(x)
}
},
document = hook1,
par=function(before, options, envir){
if (before) {
## load packages before a chunk is executed
for (p in options$packages) library(p, character.only = TRUE)
}
if (before && options$fig.show!='none') par(oma=c(0,0,0,0)+0.01, mar=c(4,4,0,0)+0.01, cex=0.9, cex.lab=.95,cex.axis=.9,mgp=c(2,.7,0),tcl=-.3)
}
)
knitr::opts_knit$set(concordance=TRUE, self.contained=FALSE)
# For printing code blocks in black and white
# knitr::knit_theme$set("greyscale0")
uchicago.lattice.theme=mosaic::col.mosaic(bw=TRUE)
uchicago.lattice.theme$box.dot$pch=20
uchicago.lattice.theme$dot.symbol$pch=20
uchicago.lattice.theme$plot.symbol$pch=20
uchicago.lattice.theme$box.dot$cex=1.0
uchicago.lattice.theme$dot.symbol$cex=1.0
uchicago.lattice.theme$plot.symbol$cex=1.0
uchicago.lattice.theme$layout.heights$main=0.5
uchicago.lattice.theme$layout.heights$top.padding=0.0
uchicago.lattice.theme$layout.heights$bottom.padding=0.0
uchicago.lattice.theme$layout.widths$left.padding=0.75
uchicago.lattice.theme$layout.widths$right.padding=0.75
lattice::trellis.par.set(theme=uchicago.lattice.theme, warn=FALSE)
lattice::trellis.par.set(fontsize=list(text=11,points=5))
# try to improve ggplot2 appearance on a projector screen
ggplot2::theme_set(ggplot2::theme_bw())
ggplot2::theme_update(panel.grid.major = ggplot2::element_line(colour = "grey75"))
```
```{r load-packages, message=FALSE,cache=FALSE,echo=FALSE}
library(MASS)
library(modelr)
library(car)
library(GGally)
library(gridExtra)
library(tidyverse)
library(mosaic)
library(knitr)
library(ggformula)
library(broom)
```
```{r, results='asis', echo = FALSE}
# Set section numbering depth to equal toc depth
# toc_depth <- rmarkdown::metadata$output$html_document$toc_depth
toc_depth <- 3
sel <- paste0("h",(toc_depth+1):10, collapse = " > span, ")
cat(paste0("
"))
```
\newcommand{\xbar}{\overline{x}}
\newcommand{\Xbar}{\overline{X}}
\newcommand{\ybar}{\overline{y}}
\newcommand{\Ybar}{\overline{Y}}
\newcommand{\zbar}{\overline{z}}
\newcommand{\Zbar}{\overline{Z}}
\newcommand{\wbar}{\overline{w}}
\newcommand{\Wbar}{\overline{W}}
\newcommand{\vbar}{\overline{v}}
\newcommand{\Vbar}{\overline{V}}
\newcommand{\dbar}{\overline{d}}
\newcommand{\Dbar}{\overline{D}}
\newcommand{\ebar}{\overline{e}}
\newcommand{\ehat}{\widehat{\epsilon}}
\newcommand{\yhat}{\widehat{y}}
\newcommand{\Yhat}{\widehat{Y}}
\newcommand{\bhat}{\widehat{b}}
\newcommand{\d}[1]{\widehat{\delta}_{#1}}
\newcommand{\g}[1]{\widehat{\gamma}_{#1}}
\newcommand{\a}[1]{\widehat{\alpha}_{#1}}
\newcommand{\B}[1]{\beta_{#1}}
\newcommand{\b}[1]{\widehat{\beta}_{#1}}
\newcommand{\Bp}{{\beta_p}}
\newcommand{\BETA}{{\boldsymbol\beta}}
\newcommand{\bp}{\widehat{\beta}_p}
\newcommand{\bj}{\widehat{\beta}_j}
\newcommand{\df}{\mathrm{df}}
\newcommand{\VIF}{\mathrm{VIF}}
\newcommand{\SSE}{\mathrm{SSE}}
\newcommand{\SST}{\mathrm{SST}}
\newcommand{\SSR}{\mathrm{SSR}}
\newcommand{\MSE}{\mathrm{MSE}}
\newcommand{\MST}{\mathrm{MST}}
\newcommand{\MSR}{\mathrm{MSR}}
\newcommand{\RM}{\mathrm{RM}}
\newcommand{\FM}{\mathrm{FM}}
\newcommand{\E}{\mathrm{E}}
\newcommand{\P}{\mathrm{P}}
\newcommand{\var}{\mathrm{var}}
\newcommand{\sd}{\mathrm{sd}}
\newcommand{\se}{\mathrm{se}}
\newcommand{\cov}{\mathrm{cov}}
\newcommand{\corr}{\mathrm{corr}}
\newcommand{\hsigma}{\widehat{\sigma}}
\newcommand{\betahat}{\widehat{\beta}}
\newcommand{\slide}{
}
\newcommand{\bbeta}{\boldsymbol{\beta}}
\newcommand{\bX}{\mathbf{X}}
\newcommand{\bY}{\mathbf{Y}}
\newcommand{\bH}{\mathbf{H}}
\newcommand{\bI}{\mathbf{I}}
\newcommand{\be}{\mathbf{e}}
\newcommand{\pval}{\mathit{P}\mathrm{-val}}
\newcommand{\pr}{\mathrm{P}}
\newcommand{\logit}{\mathrm{logit}}
[All lectures](http://galton.uchicago.edu/~collins/s224/)