<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/the-magic-trick-that-highlights-significant-results-on-any-table/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.displayr.com/the-magic-trick-that-highlights-significant-results-on-any-table/"> R – Displayr</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><img sizes="(max-width: 300px) 100vw, 300px" src="https://i2.wp.com/www.displayr.com/wp-content/uploads/2017/06/magic-trick-300x185.png?resize=300%2C185&ssl=1" alt="statistical significance trick" class="webfeedsFeaturedVisual wp-post-image" data-recalc-dims="1">
<p><img sizes="(max-width: 780px) 100vw, 780px" src="https://i0.wp.com/www.displayr.com/wp-content/uploads/2017/06/magic-trick.png?w=450&ssl=1" alt="magic trick" class="wp-image-2125" data-recalc-dims="1"></p>
<p>This post describes the single biggest time saving technique that I know about for highlighting significant results on a table. The table below, which shows the results of a <em>MANOVA</em>, illustrates the trick. The coloring and bold fonts on the table quickly draw the eye to the two key patterns in the results: people aged 50 or more have lower averages, and the result is strongest for Intel. This is revealed by the coral-colored shading and the <strong>bolding</strong>.</p>
<p> </p>
<p><iframe src="https://embedded.azureedge.net/75668/216162/ea832081-09ed-49f9-ac0b-c1fd1e101683.html?v=350851744139993" width="446" height="487.6"></iframe></p>
<p>The same principles can be applied to any table containing numbers. The table below shows people’s attitude towards Microsoft by age. The attitude is split into three categories: Detractors, Neutrals, and Promoters. What story does it tell? If you are diligent you can work it out. But, it is hard work to do so because it requires you to compare and contrast 15 different numbers on the table.</p>
<p><iframe width="377.73" src="https://embedded.azureedge.net/75668/216162/34987b1b-8fb4-46aa-83c3-7939c331e890.html?v=35085-7012522" height="149.74"></iframe></p>
<p>Now look at the table below. The colors and arrow tell us people aged 50 or more are less likely to be Promoters than people in the other age groups. Sure we could get to this insight by reading the first table and doing a whole lot of significance tests. But, the simple use of coloring and an arrow makes the key result much easier to find.</p>
<p><iframe width="377.73" src="https://embedded.azureedge.net/75668/216162/ed6b9511-047e-4ff9-8d10-ea26fb9a971f.html?v=3508582081552" height="149.74"></iframe></p>
<p>Formatting the table to emphasize differences in <em>residuals </em>is the<em> </em>basic principle used in both examples illustrated above.</p>
<hr>
<p> </p>
<h1><span>A simple approach to computing residuals</span></h1>
<p>How do we work out which cells are interesting automatically? To illustrate this, I will walk through the calculations used in the table showing attitude towards Microsoft by age, returning to more complex analyses later in this post.</p>
<p>We start with a table showing the <em>total percentages</em> (i.e., the number of people in each cell of the table, divided by the total sample size). With this table, our cell showing Promoters aged 50 or more shows a value of 3%. Is this result interesting?</p>
<p>To answer this question we should look at the TOTALs. We can see that 27% is the TOTAL percentage for 50 or more. So, all else being equal we should expect that 27% of Promoters will be aged 50 or more. As 21% of the respondents are Promoters, we would then expect, all else being equal, that the percentage that are Promoters aged 50 or more will be 27% * 21% = 6%. The actual percentage shown on the table is only 3%, so we can conclude that the proportion of people that are Promoters and aged 50 or more is roughly half what we would expect if there was no relationship between age and attitude.</p>
<p><iframe width="375.71" src="https://embedded.azureedge.net/75668/216162/9ec6baf3-9fe8-4d85-9363-9e486ee7e6a1.html?v=35085854436543" height="149.74"></iframe></p>
<p>The 6% value that I computed above for Promoters aged 50 or more is called the <em>expected value</em>. It is an estimate of the percentage of people in the sample who would be Promoters aged 50 or more, in the event that age and attitude are unrelated. The table below shows the <em>expected values </em>for all the cells in the table. That is, the values computed by multiplying together all the row and column totals for each cell. It is showing 5.6% rather than 6% for the Promoters aged 50 or more as I have used all the decimal places in the data when performing the calculations.</p>
<p><iframe src="https://embedded.azureedge.net/75668/216162/dcc2a4f5-2924-435a-9999-7a3c0c2747ef.html?v=35085-1410781417" width="352.4616" height="131"></iframe></p>
<p>This next table shows the beginning of the magic. Now I have subtracted the <em>expected values </em>from the actual (observed) <em>percentages </em>. The resulting table shows the <em>residuals</em> (residuals = observed – expected values). Cells close to 0% tend to be uninteresting.</p>
<p><iframe src="https://embedded.azureedge.net/75668/216162/ceec3d51-a747-4d88-a476-bc5aa1e8bd2d.html?v=350851691356242" width="357.5" height="146"></iframe></p>
<hr>
<p> </p>
<h1><span>Using statistical significance to save more time: standardized residuals</span></h1>
<p>The residuals are difficult to correctly interpret. They have two problems. First, how big is “big”? Second, and less obviously, it is often not appropriate to compare them. We can readily see both of these problems by looking at the residual of -2.6 for Neutral and 30 to 49. This is the biggest residual on the table. It is bigger than the residual for Promoters aged 50 or more. However, the expected value for this the Neutrals aged 30 to 49 is much closer to 50% than it is for the Promoters aged 50 or more. If you have studied your introductory stats, you will recall that this means that there is more uncertainty about the estimate (i.e., a higher <em>sampling error</em>).</p>
<p>There is a simple solution to this problem: scale the residuals so that they show statistical significance. This is straightforward to do (to see the underlying R code, <a rel="nofollow" href="https://app.displayr.com/Try/Residuals%20for%20tables" target="_blank">click here</a> to go into Displayr and click on the tables). These <em>standardized residuals </em>are <em>z-scores.  </em>This means that values of more than 1.96, or less than -1.96, are significant at the 0.05 level. The only cell in this table that is significant at the 0.05 level is Promoters in the 50 or more age group. This tells us that this is the first cell we should look at when exploring the table.</p>
<p><iframe src="https://embedded.azureedge.net/75668/216162/b0ce40e5-354f-4e46-bc08-09e06ef8c33e.html?v=35085-696576342" width="396" height="161.5185"></iframe></p>
<hr>
<p> </p>
<h1><span>Formatting</span></h1>
<p>The standardized residuals provide two types of information that allow us to quickly see patterns on a table. First, we have the standardized residuals themselves. On the table below, negative residuals are shaded in <span>coral </span>and positive values in<span> <span>blue</span><span>,</span></span> with the degree of shading proportional to the values. The second bit of information is the statistical significance of the cells (e.g., whether the <em>z-</em>scores are significant at the 0.05 level). This has been shown via <strong>bolding</strong>.</p>
<p><iframe src="https://embedded.azureedge.net/75668/216162/ea832081-09ed-49f9-ac0b-c1fd1e101683.html?v=350851744139993" width="446" height="487.6"></iframe></p>
<p>The table below uses the standardized residuals in a slightly different way:</p>
<ul>
<li>Arrow lengths are proportional to to the standardized residuals.</li>
<li>Arrows only appear when the residual is significant.</li>
<li>The color of the fonts and the arrows indicates whether the residuals are positive or negative.</li>
<li>The order of the rows and columns follows the values of the standardized residuals (for Google and Fun).</li>
</ul>
<p>The net effect of these formatting choices is that it becomes relatively easy to extract key conclusions from the table. For example, Apple does very well on Stylish, but less so on the price-related dimensions.</p>
<p><iframe width="445.4" src="https://embedded.azureedge.net/75668/216162/f3ec40bb-09c0-462d-9701-8a086a288d4e.html?v=350851274031264" height="305.14"></iframe></p>
<hr>
<p> </p>
<h1><span>Techniques for other types of data</span></h1>
<p>The “magic” consists of two separate things: (1) emphasizing differences in residuals and (2) statistical significance. There are lots of different ways to achieve these outcomes.</p>
<h2>Computing residuals</h2>
<p>The basic method for calculating the residuals illustrated above is technically only “correct” for tables with mutually exclusive categorical variables in the rows and columns. However, it is widely used with pretty much all types of data and does a good job. However, there are no shortage of alternative approaches. For example, in the MANOVA example the residuals are <em>t-</em>statistics. The table immediately above uses a <em>log-linear model</em> to compute the expected values.</p>
<h2>Computing statistical significance</h2>
<p>The method to use to compute statistical significance depends both on the data and the assumptions you want to make. Provided that you can compute the standard error for every cell on the table, you can compute a <em>z- </em>or <em>t-</em>statistic by dividing the residual by the standard error. You can of course get more rigorous. In the MANOVA example above, for example, I have computed robust standard errors and applied the <em>false discovery rate </em>correction.</p>
<hr>
<p> </p>
<h1><span>Software</span></h1>
<p>For this post, I calculated and formatted the standardized residuals and the MANOVA using R (the formatting uses the <span>formattable</span> package). <a rel="nofollow" href="https://app.displayr.com/Try/Residuals%20for%20tables" target="_blank">Click here</a> to go into Displayr, then click on the <em>MANOVA </em>output table in Displayr and you will see the <span>R CODE</span>.</p>
<p>To create the two tables that show standardized residuals with arrows and font colors, I used Displayr, which automatically computes standardized residuals on all tables, and formats them in this way.</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/the-magic-trick-that-highlights-significant-results-on-any-table/"> 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/0rZk2aHuqnA" height="1"></a></div>