class: center, middle, inverse, title-slide # Assessing Conditions --- layout: true <div class="my-footer"> <span> Dr. Lucy D'Agostino McGowan </span> </div> --- class: center, middle ## Revisit late policy --- ## <i class="fas fa-laptop"></i> `Porsche Price (2)` - Go to RStudio Cloud and open `Porsche Price (2)` --- # Steps for modeling  --- # Steps for modeling  --- # Conditions for simple linear regression * Linearity * Zero Mean * Constant Variance * Independence * Random * Normality --- # Conditions for simple linear regression * Linearity * ~~Zero Mean~~ * Constant Variance * Independence * Random * Normality --- # Conditions for simple linear regression * **Linearity** * ~~Zero Mean~~ * **Constant Variance** * Independence * Random * Normality --- # Linearity & Constant Variance <!-- --> --- # Linearity & Constant Variance ### Residuals versus fits plot .question[ What do you think would be on the x-axis and y-axis on a "residuals versus fits" plot? ] --- # Linearity & Constant Variance <!-- --> --- # Linearity & Constant Variance ### Residuals versus fits plot: What are we looking for? * random variation above and below 0 * no apparent "patterns" * the width of the "band" of points is relatively constant --- # Linearity & Constant Variance .question[ What do you think of this plot? ] <!-- --> --- # Linearity & Constant Variance .question[ What do you think of this plot? ] <!-- --> --- # Linearity & Constant Variance .question[ What do you think of this plot? ] <!-- --> --- # Linearity & Constant Variance .question[ What do you think of this plot? ] <!-- --> --- # Conditions for simple linear regression * Linearity * Zero Mean * Constant Variance * Independence * Random * Normality --- # Conditions for simple linear regression * Linearity * Zero Mean * Constant Variance * **Independence** * **Random** * Normality --- # Conditions for simple linear regression * Linearity * Zero Mean * Constant Variance * Independence * Random * **Normality** --- # Normality * Histogram * Normal quantile plot --- # Normality ### Histogram <!-- --> --- # Normality ### Histogram .question[ What do you think of this plot? ] <!-- --> --- # Normality ### Histogram .question[ What do you think of this plot? ] <!-- --> --- # Normality ### Normal quantile plot <!-- --> --- # Normality ### Normal quantile plot .question[ What do you think of this plot? ] <!-- --> --- # Normality ### Normal quantile plot .question[ What do you think of this plot? ] <!-- --> --- class: center, middle # Let's do it in R! --- ## Plot the data with a line <!-- --> --- ## Plot the data with a line ```r y_hat <- lm(Weight ~ WingLength, data = Sparrows) %>% predict() Sparrows <- Sparrows %>% mutate(y_hat = y_hat, residuals = Weight - y_hat) ``` --- ## Plot the data with a line <!-- --> --- ## Residuals vs Fits plot .small[ ```r ggplot(Sparrows, aes(x = y_hat, y = residuals)) + geom_point() + geom_hline(yintercept = 0) + labs(title = "Residuals versus fits", subtitle = "The relationship between WingLength and Weight for Sparrows", x = "y hat") ``` <!-- --> ] --- ## Residuals vs Fits plot .small[ ```r ggplot(Sparrows, aes(x = y_hat, y = residuals)) + geom_point() + * geom_hline(yintercept = 0) + labs(title = "Residuals versus fits", subtitle = "The relationship between WingLength and Weight for Sparrows", x = "y hat") ``` <!-- --> ] --- ## Histogram of the residuals ```r ggplot(Sparrows, aes(residuals)) + geom_histogram(binwidth = 0.5) ``` <!-- --> --- ## Normal quantile plot ```r ggplot(Sparrows, aes(sample = residuals)) + geom_qq() + geom_qq_line() ``` <!-- --> --- ## Normal quantile plot ```r *ggplot(Sparrows, aes(sample = residuals)) + geom_qq() + geom_qq_line() ``` <!-- --> --- ## Normal quantile plot ```r ggplot(Sparrows, aes(sample = residuals)) + * geom_qq() ``` <!-- --> --- ## Normal quantile plot ```r ggplot(Sparrows, aes(sample = residuals)) + geom_qq() + * geom_qq_line() ``` <!-- --> --- ## <i class="fas fa-laptop"></i> `Porsche Price (2)` - Go to RStudio Cloud and open `Porsche Price (2)` - For each question you work on, set the `eval` chunk option to `TRUE` and knit