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 ![](img/03/flowchart.png) --- # Steps for modeling ![](img/03/flowchart-arrow.png) --- # 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 ![](04-assessing-conditions_files/figure-html/unnamed-chunk-3-1.png)<!-- --> --- # 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 ![](04-assessing-conditions_files/figure-html/unnamed-chunk-4-1.png)<!-- --> --- # 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? ] ![](04-assessing-conditions_files/figure-html/unnamed-chunk-5-1.png)<!-- --> --- # Linearity & Constant Variance .question[ What do you think of this plot? ] ![](04-assessing-conditions_files/figure-html/unnamed-chunk-6-1.png)<!-- --> --- # Linearity & Constant Variance .question[ What do you think of this plot? ] ![](04-assessing-conditions_files/figure-html/unnamed-chunk-7-1.png)<!-- --> --- # Linearity & Constant Variance .question[ What do you think of this plot? ] ![](04-assessing-conditions_files/figure-html/unnamed-chunk-8-1.png)<!-- --> --- # 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 ![](04-assessing-conditions_files/figure-html/unnamed-chunk-9-1.png)<!-- --> --- # Normality ### Histogram .question[ What do you think of this plot? ] ![](04-assessing-conditions_files/figure-html/unnamed-chunk-10-1.png)<!-- --> --- # Normality ### Histogram .question[ What do you think of this plot? ] ![](04-assessing-conditions_files/figure-html/unnamed-chunk-11-1.png)<!-- --> --- # Normality ### Normal quantile plot ![](04-assessing-conditions_files/figure-html/unnamed-chunk-12-1.png)<!-- --> --- # Normality ### Normal quantile plot .question[ What do you think of this plot? ] ![](04-assessing-conditions_files/figure-html/unnamed-chunk-13-1.png)<!-- --> --- # Normality ### Normal quantile plot .question[ What do you think of this plot? ] ![](04-assessing-conditions_files/figure-html/unnamed-chunk-14-1.png)<!-- --> --- class: center, middle # Let's do it in R! --- ## Plot the data with a line ![](04-assessing-conditions_files/figure-html/unnamed-chunk-15-1.png)<!-- --> --- ## 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 ![](04-assessing-conditions_files/figure-html/unnamed-chunk-17-1.png)<!-- --> --- ## 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") ``` ![](04-assessing-conditions_files/figure-html/unnamed-chunk-18-1.png)<!-- --> ] --- ## 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") ``` ![](04-assessing-conditions_files/figure-html/unnamed-chunk-19-1.png)<!-- --> ] --- ## Histogram of the residuals ```r ggplot(Sparrows, aes(residuals)) + geom_histogram(binwidth = 0.5) ``` ![](04-assessing-conditions_files/figure-html/unnamed-chunk-20-1.png)<!-- --> --- ## Normal quantile plot ```r ggplot(Sparrows, aes(sample = residuals)) + geom_qq() + geom_qq_line() ``` ![](04-assessing-conditions_files/figure-html/unnamed-chunk-21-1.png)<!-- --> --- ## Normal quantile plot ```r *ggplot(Sparrows, aes(sample = residuals)) + geom_qq() + geom_qq_line() ``` ![](04-assessing-conditions_files/figure-html/unnamed-chunk-22-1.png)<!-- --> --- ## Normal quantile plot ```r ggplot(Sparrows, aes(sample = residuals)) + * geom_qq() ``` ![](04-assessing-conditions_files/figure-html/unnamed-chunk-23-1.png)<!-- --> --- ## Normal quantile plot ```r ggplot(Sparrows, aes(sample = residuals)) + geom_qq() + * geom_qq_line() ``` ![](04-assessing-conditions_files/figure-html/unnamed-chunk-24-1.png)<!-- --> --- ## <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