Visualize correlation matrix using symnum function

[html]

<!--====================== start from here when you copy to sthda================-->
<div id="rdoc">
<div id="TOC">
<ul>
<li><a href="#graph-of-correlation-matrix-using-symnum-function">Graph of correlation matrix using symnum function</a></li>
<li><a href="#conclusions">Conclusions</a></li>
<li><a href="#infos">Infos</a></li>
</ul>
</div>


<p>This article describes how to make a <strong>graph of correlation matrix</strong> in <strong>R</strong>. The R <strong>symnum()</strong> function is used. It takes the <strong>correlation table</strong> as an argument. The result is a table in which <strong>correlation coefficients</strong> are replaced by symbols according to the <strong>degree of correlation</strong>.</p>
<div class="block">
<i class="fa - fa-cogs fa-4x valign_middle"></i> Note that online software is also available <a href="/english/rsthda/correlation-matrix.php">here</a> to compute <strong>correlation matrix</strong> and to plot a <strong>correlogram</strong> without any installation.
</div>
<div id="graph-of-correlation-matrix-using-symnum-function" class="section level1">
<h1>Graph of correlation matrix using symnum function</h1>
<p>The R function <strong>symnum</strong> can be used to easily highlight the highly correlated variables. It replaces correlation coefficients by symbols according to the value.</p>
<p>The simplified format of the function is :</p>
<pre class="r"><code>symnum(x, cutpoints = c(0.3, 0.6, 0.8, 0.9, 0.95),
symbols = c(" ", ".", ",", "+", "*", "B"))</code></pre>
<p><span class="warning"> - <strong>x</strong> is the correlation matrix to visualize
- <strong>cutpoints</strong> : <strong>correlation coefficient</strong> cutpoints. The <strong>correlation coefficients</strong> between 0 and 0.3 are replaced by a space (" “;); <strong>correlation coefficients</strong> between 0.3 and 0.6 are replace by”.“; etc …
- <strong>symbols</strong> : the symbols to use. </span></p>
<p>The following R code performs a <strong>correlation analysis</strong> and displays a <strong>graph of the correlation matrix</strong> :</p>
<pre class="r"><code>## Correlation matrix
corMat<-cor(mtcars)
head(round(corMat,2))</code></pre>
<pre><code> mpg cyl disp hp drat wt qsec vs am gear carb
mpg 1.00 -0.85 -0.85 -0.78 0.68 -0.87 0.42 0.66 0.60 0.48 -0.55
cyl -0.85 1.00 0.90 0.83 -0.70 0.78 -0.59 -0.81 -0.52 -0.49 0.53
disp -0.85 0.90 1.00 0.79 -0.71 0.89 -0.43 -0.71 -0.59 -0.56 0.39
hp -0.78 0.83 0.79 1.00 -0.45 0.66 -0.71 -0.72 -0.24 -0.13 0.75
drat 0.68 -0.70 -0.71 -0.45 1.00 -0.71 0.09 0.44 0.71 0.70 -0.09
wt -0.87 0.78 0.89 0.66 -0.71 1.00 -0.17 -0.55 -0.69 -0.58 0.43</code></pre>
<pre class="r"><code>## Correlation graph for visualization
## abbr.colnames=FALSE to avoid abbreviation of column names
symnum(corMat, abbr.colnames=FALSE)</code></pre>
<pre><code> mpg cyl disp hp drat wt qsec vs am gear carb
mpg 1
cyl + 1
disp + * 1
hp , + , 1
drat , , , . 1
wt + , + , , 1
qsec . . . , 1
vs , + , , . . , 1
am . . . , , 1
gear . . . , . , 1
carb . . . , . , . 1
attr(,"legend")
[1] 0 ' ' 0.3 '.' 0.6 ',' 0.8 '+' 0.9 '*' 0.95 'B' 1</code></pre>
</div>
<div id="conclusions" class="section level1">
<h1>Conclusions</h1>
<div class="block">
One of the easy way to visualize <strong>correlation matrix</strong> in R is to use the <strong>symnum()</strong> R function.
</div>
</div>
<div id="infos" class="section level1">
<h1>Infos</h1>
<pre class="warning"><code>This analysis was performed using R (ver. 3.1.0).</code></pre>
</div>
<script>jQuery(document).ready(function () {
jQuery('h1').addClass('wiki_paragraph1');
jQuery('h2').addClass('wiki_paragraph2');
jQuery('h3').addClass('wiki_paragraph3');
jQuery('h4').addClass('wiki_paragraph4');
});//add phpboost class to header</script>
<style>.content{padding:0px;}</style>
</div><!--end rdoc-->
<!--====================== stop here when you copy to sthda================-->
[/html]

Enjoyed this article? I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Twitter, Facebook or Linked In.

Show me some love with the like buttons below... Thank you and please don't forget to share and comment below!!
Avez vous aimé cet article? Je vous serais très reconnaissant si vous aidiez à sa diffusion en l'envoyant par courriel à un ami ou en le partageant sur Twitter, Facebook ou Linked In.

Montrez-moi un peu d'amour avec les like ci-dessous ... Merci et n'oubliez pas, s'il vous plaît, de partager et de commenter ci-dessous!





This page has been seen 21840 times