<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/5-alternatives-to-the-default-r-outputs-for-glms-and-linear-models/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.displayr.com/5-alternatives-to-the-default-r-outputs-for-glms-and-linear-models/?utm_medium=Feed&utm_source=Syndication"> R – Displayr</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>The standard <span>summary</span> outputs from the <span>glm</span> and <span>lm</span> summary methods are a case in point. If you have been using R for as long as I have (19 or 20 years…) you will no doubt have a certain affection for them, but to a new user they are both ugly and not optimized to aid interpretation.</p>
<h2>The sad old default <span>summary</span> output from <span>glm</span> and <span>lm</span></h2>
<p>The default output, shown below, is not terrible. By 1960s standards it is pretty good. If you know where to look and are good with numbers it is serviceable. But it can be bettered.</p>
<p><iframe width="450" src="https://embedded.azureedge.net/75668/297826/e4e21239-f5e4-4456-a13b-6d2ef043bdd5.html?v=32413;-d3b24494c8;;1095050767"></iframe>
</p>
<h2>1. An HTML table</h2>
<p>The most basic level of improvement is to make an attractive table, as done by the <span>stargazer</span> package. It improves on the 1960s style standard output by creating an HTML table, but in the style of an academic publication (R code: <span>stargazer::stargazer(my.glm, type = “html”)</span>; be careful if copying this as you’ll need to replace the quotation marks with R-friendly ones).</p>
<p><img sizes="(max-width: 404px) 100vw, 404px" src="https://i2.wp.com/www.displayr.com/wp-content/uploads/2018/09/Stargazer.png?resize=404%2C409&ssl=1" alt="" width="404" class="wp-image-10666" data-recalc-dims="1" height="409"></p>
<h2>2. A 21st century table</h2>
<p>The output below uses more modern R technology (HTML widgets). It improves on the previous outputs in two ways:</p>
<ul>
<li>The <span>formattable</span> package is used to create an attractive table which redundantly encodes information by color, bolding, cell shading, and relatively extreme rounding.</li>
<li>The table uses variable labels, rather than names. These labels are stored as attributes of the variables in the data frame (e.g., <span>attr(x$MonthlyCharges, “label”) = “Monthly Charges ($)”</span>;  again, be careful if copying this to replace the quotation marks ). <span>stargazer</span> also supports such labeling, although they are passed into the function as arguments rather than attributes of variables.</li>
</ul>
<p>This output has been created using the <span>Regression</span> function in our <span>flipRegression</span> package. This is running <span>glm</span> in the background. This is preloaded and available from the menus when you <a rel="nofollow" href="https://app.displayr.com/SignUp?plan_id=0" target="_blank">use Displayr</a>, but you can also <a rel="nofollow" href="https://www.displayr.com/installing-r-packages-from-github/" target="_blank">install the package from github</a>.</p>
<p><iframe width="450" src="https://embedded.azureedge.net/75668/297826/c63ebb5c-3689-4d36-9866-99b35a4d7681.html?v=32413;-d3b24494c8;;1048873307"></iframe>
</p>
<h2>3. Importance scores instead of coefficients</h2>
<p>A more extreme approach is to report importance scores instead of coefficients. For example, the table below uses a modification of Johnson’s relative weights as a way of simultaneously addressing the correlation between the predictors and the dependency of coefficients on the scale of the predictors (Johnson, J.W. (2000). A heuristic method for estimating the relative weight of predictor variables in multiple regression. <i>Multivariate behavioral research</i> 35, 1-19.).</p>
<p>The modification is that I’ve assigned the signs based on the signs from a standard <span>glm</span>. This has been produced using the same Regression function described in the previous section, but with an additional argument of  <span>output = “Relative Importance Analysis”</span>.</p>
<p><iframe width="450" src="https://embedded.azureedge.net/75668/297826/0491ff4e-a06c-4044-b485-21ad16f20e12.html?v=32413;-d3b24494c8;;-456168754"></iframe>
</p>
<h2>4. Effects plots</h2>
<p>Alternatively, we can go entirely graphical in our presentation of the model. I’ve created the plots below using the effects package. A few points to note:</p>
<ul>
<li>Of the outputs examined in this post, these are the only ones that both show the effects and the distribution of the predictors. If the goal is to understand the model, these plots are extremely informative.</li>
<li>By using a common y-axis it is easy to assess importance. (Although note that the mean probabilities that can be read off these plots are biased, as these plots are created under the assumption that the mean function for the model is linear, which is not the case for the logit model).</li>
<li>The graphical presentation of the confidence bands is much more informative than the standard errors in the previous outputs.</li>
</ul>
<p><iframe width="450" src="https://embedded.azureedge.net/75668/297826/cf30d512-7d7d-4fce-aadb-3646870b6bb4.html?v=32413;-d3b24494c8;;-201755301"></iframe>
</p>
<h2>5. Simulator</h2>
<p>The last way of presenting the results is to show a simulator, allowing the user to experiment to gain an understanding of the interplay of all the predictors in predicting the outcome categories. Click the image below to go to an online simulator or click the button below to explore and edit the code. You can find out more about creating simulators in “<a rel="nofollow" href="https://www.displayr.com/building-online-interactive-simulators-for-predictive-models-in-r/" target="_blank">Building Online Interactive Simulators for Predictive Models in R.”</a></p>
<p><a rel="nofollow" href="https://app.displayr.com/Dashboard?id=81f9bf66-f475-40a9-8e9c-1c557f80c709" target="_blank"><img sizes="(max-width: 270px) 100vw, 270px" src="https://i0.wp.com/www.displayr.com/wp-content/uploads/2018/09/Simulator1.png?resize=270%2C180&ssl=1" alt="" width="270" class="wp-image-10210" data-recalc-dims="1" height="180"></a></p>
<p><a rel="nofollow" href="https://app.displayr.com/Dashboard?id=81f9bf66-f475-40a9-8e9c-1c557f80c709" target="_blank"><strong><a rel="nofollow" href="https://app.displayr.com/try/Simulator%20Predict" target="_blank"><span>Explore and edit this simulator</span></a></strong></a></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="https://www.displayr.com/5-alternatives-to-the-default-r-outputs-for-glms-and-linear-models/?utm_medium=Feed&utm_source=Syndication"> R – Displayr</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 rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/ZXB_WZ0LrRM" height="1"></a></div>