<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/multiple-regression-part-2-diagnostics/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://r-exercises.com/2017/01/26/multiple-regression-part-2-diagnostics/?utm_source=rss&utm_medium=rss&utm_campaign=multiple-regression-part-2-diagnostics"> R-exercises</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a target="_blank" rel="nofollow" href="http://r-exercises.com/wp-content/uploads/2017/01/mlr-exercises2-10.png?x61433"><img sizes="(max-width: 300px) 100vw, 300px" alt="" class="wp-image-4131" src="https://i0.wp.com/r-exercises.com/wp-content/uploads/2017/01/mlr-exercises2-10-300x300.png?resize=300%2C300" data-recalc-dims="1"></a>Multiple Regression is one of the most widely used methods in statistical modelling. However, despite its many benefits, it is oftentimes used without checking the underlying assumptions. This can lead to results which can be misleading or even completely wrong. Therefore, applying diagnostics to detect any strong violations of the assumptions is important. In the exercises below we cover some material on multiple regression diagnostics in R.</p>
<p>Answers to the exercises are available <a target="_blank" rel="nofollow" href="http://r-exercises.com/2017/01/26/multiple-regression-part-2-diagnostics-solutions/">here</a>.</p>
<p>If you obtain a different (correct) answer than those listed on the solutions page, please feel free to post your answer as a comment on that page.</p>
<p>Multiple Regression (Part 1) can be found <a target="_blank" rel="nofollow" href="http://r-exercises.com/2017/01/15/multiple-regression-part-1/">here</a>.</p>
<p>We will be using the dataset <code>state.x77</code>, which is part of the <code>state</code> datasets available in <code>R</code>. (Additional information about the dataset can be obtained by running <code>help(state.x77)</code>.)</p>
<p><strong>Exercise 1</strong><br>
a. Load the <code>state</code> datasets.<br>
b. Convert the <code>state.x77</code> dataset to a dataframe.<br>
c. Rename the <code>Life Exp</code> variable to <code>Life.Exp</code>, and <code>HS Grad</code> to <code>HS.Grad</code>. (This avoids problems with referring to these variables when specifying a model.)<br>
d. Produce the correlation matrix.<br>
e. Create a scatterplot matrix for the variables <code>Life.Exp</code>, <code>HS.Grad</code>, <code>Murder</code>, and <code>Frost</code>.</p>
<p><strong>Exercise 2</strong><br>
a. Fit the model with <code>Life.Exp</code> as dependent variable, and <code>HS.Grad</code> and <code>Murder</code> as predictors.<br>
b. Obtain the residuals.<br>
c. Obtain the fitted values.</p>
<p><strong>Exercise 3</strong><br>
a. Create a residual plot (residuals vs. fitted values).<br>
b. Create the same residual plot using the <code>plot</code> command on the <code>lm</code> object from Exercise 2.</p>
<div>
<aside><img src="http://r-exercises.com/2017/01/26/multiple-regression-part-2-diagnostics/?utm_source=rss&utm_medium=rss&utm_campaign=multiple-regression-part-2-diagnostics"></aside>
<div><strong>Learn more</strong> about multiple linear regression in the online courses <a target="_blank" rel="nofollow" href="http://r-exercises.com/product/linear-regression-in-r-for-data-scientists/">Linear regression in R for Data Scientists</a>, <a target="_blank" rel="nofollow" href="http://r-exercises.com/product/statistics-with-r-advanced-level/">Statistics with R – advanced level</a>, and <a target="_blank" rel="nofollow" href="http://r-exercises.com/product/linear-regression-and-modeling/">Linear Regression and Modeling</a>.</div>
</div>
<p><strong>Exercise 4</strong><br>
Create plots of the residuals vs. each of the predictor variables.</p>
<p><strong>Exercise 5</strong><br>
a. Create a Normality plot.<br>
b. Create the same plot using the <code>plot</code> command on the <code>lm</code> object from Exercise 2.</p>
<p><strong>Exercise 6</strong><br>
a. Obtain the studentized residuals.<br>
b. Does there appear to be any outliers?</p>
<p><strong>Exercise 7</strong><br>
a. Obtain the leverage value for each observation and plot them.<br>
b. Obtain the conventional threshold for leverage values. Are any observations influential?</p>
<p><strong>Exercise 8</strong><br>
a. Obtain DFFITS values.<br>
b. Obtain the conventional threshold. Are any observations influential?<br>
c. Obtain DFBETAS values.<br>
d. Obtain the conventional threshold. Are any observations influential?</p>
<p><strong>Exercise 9</strong><br>
a. Obtain Cook’s distance values and plot them.<br>
b. Obtain the same plot using the <code>plot</code> command on the <code>lm</code> object from Exercise 2.<br>
c. Obtain the threshold value. Are any observations influential?</p>
<p><strong>Exercise 10</strong><br>
Create the Influence Plot using a function from the <code>car</code> package.</p>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://r-exercises.com/2017/01/26/multiple-regression-part-2-diagnostics/?utm_source=rss&utm_medium=rss&utm_campaign=multiple-regression-part-2-diagnostics"> R-exercises</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/IkkPLxhedk4"></a></div>