| 
 | 
楼主
 
 
 楼主 |
发表于 2012-2-17 12:52:23
|
只看该作者
 
 
 
Mahalanobis distances on a heat map
From Dapangmao's blog on sas-analysis 
 
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-bccx7mtmT64/Tz3NhKhJ9hI/AAAAAAAAA7U/ixPJe2yxiIM/s1600/SGRender20.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="http://1.bp.blogspot.com/-bccx7mtmT64/Tz3NhKhJ9hI/AAAAAAAAA7U/ixPJe2yxiIM/s400/SGRender20.png" width="400" /></a></div><br /> 
I just learned Mahalanobis distance from <a href="http://blogs.sas.com/content/iml/2012/02/15/what-is-mahalanobis-distance/">Rick’s blog post</a> yesterday, and realized <a href="http://blogs.sas.com/content/iml/2012/02/02/detecting-outliers-in-sas-part-3-multivariate-location-and-scatter/">its significance in detecting outliers</a>. One of SAS’s online documents shows how to <a href="http://support.sas.com/kb/30/662.html">use PCA method to find Mahalanobis distances</a>. And in SAS 9.3, the popular <a href="http://blogs.sas.com/content/graphicallyspeaking/2011/12/08/calendar-heatmaps-in-gtl/">heat map</a> becomes available<br /> 
<br /> 
SAS’s classic help dataset SASHELP.CLASS has weight, height, age and some other information for 19 teenagers. I calculated the pair-wise Mahalanobis distances according to their age, weight and height, and showed those distances on a heat map. It seems that it is helpful to tell how similar two teenagers are to each other.<br /> 
<br /> 
<pre style="background-color: #ebebeb; border: 1px dashed rgb(153, 153, 153); color: #000001; font-size: 14px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code> 
/* 1 -- Find pairwise Mahalanobis distances */ 
proc princomp data=sashelp.class std out=_1 noprint; 
     var age weight height; 
run; 
 
proc distance data=_1 out=_2; 
   var interval(prin:); 
   id name; 
run; 
 
/* 2 -- Restructrue data */ 
data _3(where=(missing(distance)=0)); 
   set _2; 
   array a[*] _numeric_; 
   do i = 1 to dim(a); 
      x = name; 
      y = vlabel(a[i]); 
      distance = a[i]; 
      output; 
   end; 
   keep x y distance; 
run; 
 
data _4; 
   set _3 _3(rename=(x=y y=x)); 
run; 
 
/* 3 -- Draw Mahalanobis distances on a heat map */ 
proc template; 
  define statgraph heatmapparm; 
    begingraph; 
      layout overlay / xaxisopts=(label=" ") yaxisopts=(label=" "); 
        heatmapparm x = x y = y colorresponse = distance / name = "heatmap"; 
        continuouslegend "heatmap" / orient = vertical location = outside; 
      endlayout; 
    endgraph; 
  end; 
run; 
 
ods html style = money; 
proc sgrender data=_4 template=heatmapparm; 
run;</code><code></code></pre><br /> 
<div><br /> 
</div><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3256159328630041416-6588531911349796886?l=www.sasanalysis.com' alt='' /></div><img src="http://feeds.feedburner.com/~r/SasAnalysis/~4/d3D3P8o3GFg" height="1" width="1"/> |   
 
 
 
 |