<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: how to calculate the mahalanobis distance with my data(two groups of continuous variable interce in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/321933#M3199</link>
    <description>&lt;P&gt;As of SAS/IML 12.1, which shipped in August 2012 as part of SAS 9.3m2, &lt;A href="http://support.sas.com/documentation/cdl/en/imlug/68150/HTML/default/viewer.htm#imlug_langref_sect247.htm" target="_self"&gt;the MAHALANOBIS function&lt;/A&gt;&amp;nbsp;is distributed as part of SAS/IML software. You do not need to define your own function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The doc has an example. For your example, you list a 10x10 covariance matrix. &amp;nbsp;That means that the CENTER vector should be a 1x10 row matrix and the X matrix should have 10 columns, not 10 rows. &amp;nbsp;Also, the covariance matrix must be nonsingular. Yours appears to be singluar.&lt;/P&gt;</description>
    <pubDate>Mon, 02 Jan 2017 15:14:53 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2017-01-02T15:14:53Z</dc:date>
    <item>
      <title>how to calculate the mahalanobis distance with my data(two groups of continuous variable intercept)</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/321912#M3193</link>
      <description>&lt;P&gt;I want to calculate the MD which represents the class separation between these two classes.(variable intercepts are shown in the picture attached)&amp;nbsp;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The intercepts for the first group are 0.35,-0.2,0.6,-0.75,0.35,-0.2,0.6,-0.75,0.35,-0.2&lt;/P&gt;&lt;P&gt;The intercepts for the second group are 0,0,0,0,0,0,0,0,0,0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to calculate the MD beween these two latent classes(in mixture modeling)? I don't know how to edit the appropriate syntax. Thanks in advance!&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13291i153EF00D4F24DE11/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="1.png" title="1.png" /&gt;</description>
      <pubDate>Mon, 02 Jan 2017 08:33:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/321912#M3193</guid>
      <dc:creator>alexandrewen</dc:creator>
      <dc:date>2017-01-02T08:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate the mahalanobis distance with my data(two groups of continuous variable interce</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/321914#M3195</link>
      <description>&lt;P&gt;&lt;EM&gt;My original syntax as follows:&lt;!-- StartFragment  --&gt; &lt;/EM&gt;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc&amp;nbsp;iml;&lt;BR /&gt;/*&amp;nbsp;simplest&amp;nbsp;approach:&amp;nbsp;x&amp;nbsp;and&amp;nbsp;center&amp;nbsp;are&amp;nbsp;row&amp;nbsp;vectors&amp;nbsp;*/&lt;BR /&gt;start&amp;nbsp;mahal1(x,&amp;nbsp;center,&amp;nbsp;cov);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;y&amp;nbsp;=&amp;nbsp;(x&amp;nbsp;-&amp;nbsp;center)`;&amp;nbsp;/*&amp;nbsp;col&amp;nbsp;vector&amp;nbsp;*/&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;d2&amp;nbsp;=&amp;nbsp;y`&amp;nbsp;*&amp;nbsp;inv(cov)&amp;nbsp;*&amp;nbsp;y;&amp;nbsp;/*&amp;nbsp;explicit&amp;nbsp;inverse.&amp;nbsp;Not&amp;nbsp;optimal&amp;nbsp;*/&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;(sqrt(d2));&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;finish;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;x&amp;nbsp;=&amp;nbsp;{0.35&amp;nbsp;0，&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-0.2&amp;nbsp;0，&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.6&amp;nbsp;0，&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-0.75&amp;nbsp;0，&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.35&amp;nbsp;0，&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-0.2&amp;nbsp;0，&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.6&amp;nbsp;0，&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-0.75&amp;nbsp;0，&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.35&amp;nbsp;0，&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-0.2&amp;nbsp;0};&amp;nbsp;&amp;nbsp;/*&amp;nbsp;test&amp;nbsp;it&amp;nbsp;*/&lt;BR /&gt;center&amp;nbsp;=&amp;nbsp;{0.015&amp;nbsp;0};&lt;BR /&gt;cov&amp;nbsp;=&amp;nbsp;{0.1225&amp;nbsp;-0.07&amp;nbsp;0.21&amp;nbsp;-0.2625&amp;nbsp;0.1225&amp;nbsp;-0.07&amp;nbsp;0.21&amp;nbsp;-0.2625&amp;nbsp;0.1225&amp;nbsp;-0.07,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-0.07&amp;nbsp;0.04&amp;nbsp;-0.12&amp;nbsp;0.15&amp;nbsp;-0.07&amp;nbsp;0.04&amp;nbsp;-0.12&amp;nbsp;0.15&amp;nbsp;-0.07&amp;nbsp;0.04,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.21&amp;nbsp;-0.12&amp;nbsp;0.36&amp;nbsp;-0.45&amp;nbsp;0.21&amp;nbsp;-0.12&amp;nbsp;0.36&amp;nbsp;-0.45&amp;nbsp;0.21&amp;nbsp;-0.12,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-0.2625&amp;nbsp;0.15&amp;nbsp;-0.45&amp;nbsp;0.5625&amp;nbsp;-0.2625&amp;nbsp;0.15&amp;nbsp;-0.45&amp;nbsp;0.5625&amp;nbsp;-0.2625&amp;nbsp;0.15,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.1225&amp;nbsp;-0.07&amp;nbsp;0.21&amp;nbsp;-0.2625&amp;nbsp;0.1225&amp;nbsp;-0.07&amp;nbsp;0.21&amp;nbsp;-0.2625&amp;nbsp;0.1225&amp;nbsp;-0.07,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-0.07&amp;nbsp;0.04&amp;nbsp;-0.12&amp;nbsp;0.15&amp;nbsp;-0.07&amp;nbsp;0.04&amp;nbsp;-0.12&amp;nbsp;0.15&amp;nbsp;-0.07&amp;nbsp;0.04,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.21&amp;nbsp;-0.12&amp;nbsp;0.36&amp;nbsp;-0.45&amp;nbsp;0.21&amp;nbsp;-0.12&amp;nbsp;0.36&amp;nbsp;-0.45&amp;nbsp;0.21&amp;nbsp;-0.12,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-0.2625&amp;nbsp;0.15&amp;nbsp;-0.45&amp;nbsp;0.5625&amp;nbsp;-0.2625&amp;nbsp;0.15&amp;nbsp;-0.45&amp;nbsp;0.5625&amp;nbsp;-0.2625&amp;nbsp;0.15,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.1225&amp;nbsp;-0.07&amp;nbsp;0.21&amp;nbsp;-0.2625&amp;nbsp;0.1225&amp;nbsp;-0.07&amp;nbsp;0.21&amp;nbsp;-0.2625&amp;nbsp;0.1225&amp;nbsp;-0.07,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-0.07&amp;nbsp;0.04&amp;nbsp;-0.12&amp;nbsp;0.15&amp;nbsp;-0.07&amp;nbsp;0.04&amp;nbsp;-0.12&amp;nbsp;0.15&amp;nbsp;-0.07&amp;nbsp;0.04};&lt;BR /&gt;md1&amp;nbsp;=&amp;nbsp;mahal1(x,&amp;nbsp;center,&amp;nbsp;cov);&lt;BR /&gt;print&amp;nbsp;md1;&lt;/DIV&gt;</description>
      <pubDate>Mon, 02 Jan 2017 08:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/321914#M3195</guid>
      <dc:creator>alexandrewen</dc:creator>
      <dc:date>2017-01-02T08:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate the mahalanobis distance with my data(two groups of continuous variable interce</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/321915#M3196</link>
      <description>&lt;P&gt;Here is the output, the program presented error messages:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="sasSource"&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;42 ;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;43 proc iml;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: IML Ready&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;44 /* simplest approach: x and center are row vectors */&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;45 start mahal1(x, center, cov);&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;46 y = (x - center)`;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;46 ! /* col vector */&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;47 d2 = y` * inv(cov) * y;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;47 ! /* explicit inverse. Not optimal */&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;48 return (sqrt(d2));&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;49 finish;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Module MAHAL1 defined.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;50&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;51 x = {0.35 0，&lt;/DIV&gt;&lt;DIV class="sasError"&gt;ERROR: Mixing character with numeric in matrix literal at line=51 col=12.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;52 -0.2 0，&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;53 0.6 0，&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;54 -0.75 0，&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;55 0.35 0，&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;56 -0.2 0，&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;57 0.6 0，&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;58 -0.75 0，&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;59 0.35 0，&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;60 -0.2 0};&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;60 ! /* test it */&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;61 center = {0.015 0};&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;62 cov = {0.1225 -0.07 0.21 -0.2625 0.1225 -0.07 0.21 -0.2625 0.1225 -0.07,&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;63 -0.07 0.04 -0.12 0.15 -0.07 0.04 -0.12 0.15 -0.07 0.04,&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;64 0.21 -0.12 0.36 -0.45 0.21 -0.12 0.36 -0.45 0.21 -0.12,&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;65 -0.2625 0.15 -0.45 0.5625 -0.2625 0.15 -0.45 0.5625 -0.2625 0.15,&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;66 0.1225 -0.07 0.21 -0.2625 0.1225 -0.07 0.21 -0.2625 0.1225 -0.07,&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;67 -0.07 0.04 -0.12 0.15 -0.07 0.04 -0.12 0.15 -0.07 0.04,&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;68 0.21 -0.12 0.36 -0.45 0.21 -0.12 0.36 -0.45 0.21 -0.12,&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;69 -0.2625 0.15 -0.45 0.5625 -0.2625 0.15 -0.45 0.5625 -0.2625 0.15,&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;70 0.1225 -0.07 0.21 -0.2625 0.1225 -0.07 0.21 -0.2625 0.1225 -0.07,&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;71 -0.07 0.04 -0.12 0.15 -0.07 0.04 -0.12 0.15 -0.07 0.04};&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;72 md1 = mahal1(x, center, cov);&lt;/DIV&gt;&lt;DIV class="sasError"&gt;ERROR: (execution) Matrix has not been set to a value.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;operation : - at line 46 column 11&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;operands : x, center&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;x 0 row 0 col (type ?, size 0)&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;center 1 row 2 cols (numeric)&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;0.015 0&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;statement : ASSIGN at line 46 column 4&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;traceback : module MAHAL1 at line 46 column 4&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;NOTE: Paused in module MAHAL1.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;73 print md1;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;ERROR: Matrix md1 has not been set to a value.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;statement : PRINT at line 73 column 1&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;74 ;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;75 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;85 ;&lt;/DIV&gt;</description>
      <pubDate>Mon, 02 Jan 2017 08:39:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/321915#M3196</guid>
      <dc:creator>alexandrewen</dc:creator>
      <dc:date>2017-01-02T08:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate the mahalanobis distance with my data(two groups of continuous variable interce</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/321916#M3197</link>
      <description>&lt;P&gt;I would recommend that you&amp;nbsp;move your question to the IML forum here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/bd-p/sas_iml" target="_blank"&gt;https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/bd-p/sas_iml&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jan 2017 08:47:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/321916#M3197</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-01-02T08:47:18Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate the mahalanobis distance with my data(two groups of continuous variable interce</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/321920#M3198</link>
      <description>&lt;P&gt;I moved your post to the IML forum.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe this post from Rick Wicklin on how to write a function or use built in function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc distance will also calculate the distance.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.sas.com/content/iml/2012/02/22/how-to-compute-mahalanobis-distance-in-sas.html" target="_blank"&gt;http://blogs.sas.com/content/iml/2012/02/22/how-to-compute-mahalanobis-distance-in-sas.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jan 2017 09:26:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/321920#M3198</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-01-02T09:26:20Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate the mahalanobis distance with my data(two groups of continuous variable interce</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/321933#M3199</link>
      <description>&lt;P&gt;As of SAS/IML 12.1, which shipped in August 2012 as part of SAS 9.3m2, &lt;A href="http://support.sas.com/documentation/cdl/en/imlug/68150/HTML/default/viewer.htm#imlug_langref_sect247.htm" target="_self"&gt;the MAHALANOBIS function&lt;/A&gt;&amp;nbsp;is distributed as part of SAS/IML software. You do not need to define your own function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The doc has an example. For your example, you list a 10x10 covariance matrix. &amp;nbsp;That means that the CENTER vector should be a 1x10 row matrix and the X matrix should have 10 columns, not 10 rows. &amp;nbsp;Also, the covariance matrix must be nonsingular. Yours appears to be singluar.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jan 2017 15:14:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/321933#M3199</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-01-02T15:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate the mahalanobis distance with my data(two groups of continuous variable interce</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/321950#M3200</link>
      <description>&lt;P&gt;Thanks, Dr. Wicklin! I have read the article concerning the calculation of MD within SAS before, but I am so sorry that I don't truly understand what does the "center" mean in SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In your blog, the article says"&lt;SPAN&gt;Given an observation &lt;/SPAN&gt;&lt;EM&gt;x&lt;/EM&gt;&lt;SPAN&gt; from a multivariate normal distribution with mean μ and covariance matrix Σ, the squared Mahalanobis distance from &lt;/SPAN&gt;&lt;EM&gt;x&lt;/EM&gt;&lt;SPAN&gt; to μ is given by the formula &lt;/SPAN&gt;&lt;EM&gt;d2 = (x - μ)T Σ -1 (x - μ)&lt;/EM&gt;&lt;SPAN&gt;. You can use this definition to define a function that returns the Mahalanobis distance for a row vector x, given a center vector (usually μ or an estimate of μ) and a covariance matrix:&lt;/SPAN&gt;"&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my word, the center vector in my example is the 10 variable intercepts of the second class, namely 0,0,0,0,0,0,0,0,0,0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know I am wrong, but don't know &amp;nbsp;what is wrong. I hope that you can help me with my problem. Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc iml;&lt;BR /&gt;/* simplest approach: x and center are row vectors */&lt;BR /&gt;start mahal1(x, center, cov);&lt;BR /&gt;y = (x - center)`; /* col vector */&lt;BR /&gt;d2 = y` * inv(cov) * y; /* explicit inverse. Not optimal */&lt;BR /&gt;return (sqrt(d2));&lt;BR /&gt;finish;&lt;BR /&gt;&lt;BR /&gt;x = {0.35 -0.2 0.6 -0.75 0.35 -0.2 0.6 -0.75 0.35 -0.2,&lt;BR /&gt;0 0 0 0 0 0 0 0 0 0}; /* test it */&lt;BR /&gt;center = {0 0 0 0 0 0 0 0 0 0 0};&lt;BR /&gt;cov = {0.1225 -0.07 0.21 -0.2625 0.1225 -0.07 0.21 -0.2625 0.1225 -0.07,&lt;BR /&gt;-0.07 0.04 -0.12 0.15 -0.07 0.04 -0.12 0.15 -0.07 0.04,&lt;BR /&gt;0.21 -0.12 0.36 -0.45 0.21 -0.12 0.36 -0.45 0.21 -0.12,&lt;BR /&gt;-0.2625 0.15 -0.45 0.5625 -0.2625 0.15 -0.45 0.5625 -0.2625 0.15,&lt;BR /&gt;0.1225 -0.07 0.21 -0.2625 0.1225 -0.07 0.21 -0.2625 0.1225 -0.07,&lt;BR /&gt;-0.07 0.04 -0.12 0.15 -0.07 0.04 -0.12 0.15 -0.07 0.04,&lt;BR /&gt;0.21 -0.12 0.36 -0.45 0.21 -0.12 0.36 -0.45 0.21 -0.12,&lt;BR /&gt;-0.2625 0.15 -0.45 0.5625 -0.2625 0.15 -0.45 0.5625 -0.2625 0.15,&lt;BR /&gt;0.1225 -0.07 0.21 -0.2625 0.1225 -0.07 0.21 -0.2625 0.1225 -0.07,&lt;BR /&gt;-0.07 0.04 -0.12 0.15 -0.07 0.04 -0.12 0.15 -0.07 0.04};&lt;BR /&gt;md1 = mahal1(x, center, cov);&lt;BR /&gt;print md1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jan 2017 15:14:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/321950#M3200</guid>
      <dc:creator>alexandrewen</dc:creator>
      <dc:date>2017-01-02T15:14:12Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate the mahalanobis distance with my data(two groups of continuous variable interce</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/321952#M3201</link>
      <description>&lt;P&gt;The 'center' matrix is an estimate of the center of the population. for example, the center is often taken to the be the sample mean of the data, just as the covariance estimate is the sample covariance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the code that you posted, there are two things wrong:&lt;/P&gt;
&lt;P&gt;1. The Center vector has 11 elements, not 10.&lt;/P&gt;
&lt;P&gt;2. The covariance matrix is singular. The covariance must be nonsingular to compute the Mahalanobis distance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For demonstration purposes, the following code adds a multiple of the identity matrix to your&amp;nbsp;covariance. In real life, you'll have to &amp;nbsp;figure out how to get a nonsingular matrix. &amp;nbsp;Notice that I call the built-in MAHALANOBIS function:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;

x = {0.35 -0.2 0.6 -0.75 0.35 -0.2 0.6 -0.75 0.35 -0.2};
center = {0 0 0 0 0 0 0 0 0 0};
cov = {0.1225 -0.07 0.21 -0.2625 0.1225 -0.07 0.21 -0.2625 0.1225 -0.07,
-0.07 0.04 -0.12 0.15 -0.07 0.04 -0.12 0.15 -0.07 0.04,
0.21 -0.12 0.36 -0.45 0.21 -0.12 0.36 -0.45 0.21 -0.12,
-0.2625 0.15 -0.45 0.5625 -0.2625 0.15 -0.45 0.5625 -0.2625 0.15,
0.1225 -0.07 0.21 -0.2625 0.1225 -0.07 0.21 -0.2625 0.1225 -0.07,
-0.07 0.04 -0.12 0.15 -0.07 0.04 -0.12 0.15 -0.07 0.04,
0.21 -0.12 0.36 -0.45 0.21 -0.12 0.36 -0.45 0.21 -0.12,
-0.2625 0.15 -0.45 0.5625 -0.2625 0.15 -0.45 0.5625 -0.2625 0.15,
0.1225 -0.07 0.21 -0.2625 0.1225 -0.07 0.21 -0.2625 0.1225 -0.07,
-0.07 0.04 -0.12 0.15 -0.07 0.04 -0.12 0.15 -0.07 0.04};

cov = cov + I(10);   /* HACK: make the cov matrix nonsingular for demonstration */
md1 = mahalanobis(x, center, cov);
print md1;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Jan 2017 15:23:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/321952#M3201</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-01-02T15:23:54Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate the mahalanobis distance with my data(two groups of continuous variable interce</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/322680#M3203</link>
      <description>&lt;P&gt;Hello again! With the default MD function and the previous syntax, the MD value is 0.83. But in the simulation study, the author fixed the MD value at 1.5 for small separation between the 2 classes. (As you can see in the 2 pictures attached) Thank you for your light on this difference!&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13300iD9D82630CA5D3B4C/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="picture1.png" title="picture1.png" /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13301i4D4CB266AAFF66D9/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="picture2.png" title="picture2.png" /&gt;</description>
      <pubDate>Thu, 05 Jan 2017 15:17:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/322680#M3203</guid>
      <dc:creator>alexandrewen</dc:creator>
      <dc:date>2017-01-05T15:17:15Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate the mahalanobis distance with my data(two groups of continuous variable interce</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/322685#M3204</link>
      <description>&lt;P&gt;Please READ my response which says&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;"For demonstration purposes&lt;/STRONG&gt;, &lt;STRONG&gt;the following code adds a multiple of the identity matrix to your&amp;nbsp;covariance. In real life, you'll have to &amp;nbsp;figure out how to get a nonsingular matrix."&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Also the program says&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token comment"&gt;/* HACK: make the cov matrix nonsingular for demonstration */&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;In other words, I am not claiming that the MD is 0.83. &amp;nbsp;You have provided a singular matrix, which means that the MD is undefined. I modified your covariance matrix in order to show you how to calculate the MD. You won't match someone else's results unless you use the same inputs (mean vector and covariance matrix)&amp;nbsp;that they used. &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2017 15:35:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/322685#M3204</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-01-05T15:35:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate the mahalanobis distance with my data(two groups of continuous variable interce</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/323007#M3205</link>
      <description>&lt;P&gt;Yes, the covariance matrix in fact should be a 2*2 matrix because the sample has 2 dimensions(2 groups of observed variable intercepts).&lt;/P&gt;&lt;P&gt;cov = {0.2589 0,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 0};&lt;/P&gt;&lt;P&gt;The x should be&lt;/P&gt;&lt;P&gt;x = {0.35 -0.2 0.6 -0.75 0.35 -0.2 0.6 -0.75 0.35 -0.2};&lt;/P&gt;&lt;P&gt;But the center. You said the center is the sample mean of the data.&lt;/P&gt;&lt;P&gt;The center should be {0.015,0};&lt;/P&gt;&lt;P&gt;But this syntax still did not work. I am a green hand in statistics. Thank you for your help!&lt;/P&gt;&lt;P&gt;proc iml;&lt;/P&gt;&lt;P&gt;x = {0.35 -0.2 0.6 -0.75 0.35 -0.2 0.6 -0.75 0.35 -0.2};&lt;/P&gt;&lt;P&gt;center = {0.015 0};&lt;/P&gt;&lt;P&gt;cov = {0.2589 0,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 0};&lt;/P&gt;&lt;P&gt;md1 = mahalanobis(x, center, cov);&lt;/P&gt;&lt;P&gt;print md1;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2017 15:49:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/323007#M3205</guid>
      <dc:creator>alexandrewen</dc:creator>
      <dc:date>2017-01-06T15:49:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate the mahalanobis distance with my data(two groups of continuous variable interce</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/323012#M3206</link>
      <description>&lt;P&gt;Let p be the number of variables in your problem.&lt;/P&gt;
&lt;P&gt;Then&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;X should be a matrix that has p columns.&lt;/LI&gt;
&lt;LI&gt;'center' should be a 1 x p row vector.&lt;/LI&gt;
&lt;LI&gt;the covariance matrix should be a symmetric nonsingular p x p matrix.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;In your problem, do you have 2 variables or 10?&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2017 15:52:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/323012#M3206</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-01-06T15:52:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate the mahalanobis distance with my data(two groups of continuous variable interce</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/323150#M3207</link>
      <description>The number of variables p is 2 in my example. The intercepts of the two latent classes specify the class separation. But in my example, the covariance beween u1 and u2 is 0. The MD simplifies to Euclidean distance. Therefore I can calculate the ED manually and get the 1.5 value. But in SAS with the built-in MD function, I don't know how to range the sample values in matrix X. Thank you! Here is my syntax. proc iml; x = {0.35 -0.2 0.6 -0.75 0.35 -0.2 0.6 -0.75 0.35 -0.2, 0 0 0 0 0 0 0 0 0 0}; center = {0.015 0}; cov = {0.2589 0, 0 0}; md1 = mahalanobis(x, center, cov); print md1;</description>
      <pubDate>Sat, 07 Jan 2017 08:52:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/323150#M3207</guid>
      <dc:creator>alexandrewen</dc:creator>
      <dc:date>2017-01-07T08:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate the mahalanobis distance with my data(two groups of continuous variable interce</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/323169#M3208</link>
      <description>&lt;P&gt;Sorry to repeat myself, but you still do not have the dimensions correct.&lt;/P&gt;
&lt;P&gt;1. If the mean is 1x2 and the covariance matrix is 2x2, then the X matrix must have two columns.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. The covariance matrix must be nonsingular. Your matrix&amp;nbsp;&lt;SPAN&gt;cov = {0.2589 0, 0 0} is singular.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3. If you expect to get one "distance" (you say the answer is 1.5), then X would have 1 row. &amp;nbsp;If you specify 10 rows, you are saying that there are 10 points and you want to know the distance from each point to the center.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If you show the Euclidean calculation&amp;nbsp;(for which you claim you get the correct &amp;nbsp;answer) that might help us to make sense of what you are trying to do.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Jan 2017 17:59:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/323169#M3208</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-01-07T17:59:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate the mahalanobis distance with my data(two groups of continuous variable interce</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/323208#M3209</link>
      <description>Here is the Euclidean calculation with respect to my example, Euclidean distance = sqrt[0.35*2+(-0.2)*2+0.6*2+(-0.75)*2+0.35*2+(-0.2)*2+0.6*2+(-0.75)*2+0.35*2+(-0.2)*2] = sqrt(2.3325) = 1.53 I am not very familiar with sas program and may confuse the definitions. Thank you for your support and understanding!</description>
      <pubDate>Sun, 08 Jan 2017 10:23:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/323208#M3209</guid>
      <dc:creator>alexandrewen</dc:creator>
      <dc:date>2017-01-08T10:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate the mahalanobis distance with my data(two groups of continuous variable interce</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/323215#M3210</link>
      <description>&lt;P&gt;The Euclidean distance formula you are using is the distance between two 10 -dimensional points. The general ED &amp;nbsp;formula for the distance between points p and q is&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ED = sqrt( (p1-q1)**2 + (p2-q2)**2 + ... + (p10 -q10)**2 )&lt;/P&gt;
&lt;P&gt;In this case p is the set of 10 X values and q is the center (0,0,0,...0).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you need to produce a nonsingular 10x10 covariance matrix if you want to compute the Mahalanobis distance.&lt;/P&gt;</description>
      <pubDate>Sun, 08 Jan 2017 11:55:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-calculate-the-mahalanobis-distance-with-my-data-two/m-p/323215#M3210</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-01-08T11:55:21Z</dc:date>
    </item>
  </channel>
</rss>

