<?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: Trouble creating Type = COV dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Trouble-creating-Type-COV-dataset/m-p/736758#M229589</link>
    <description>&lt;P&gt;Many thanks for this. Its enormously helpful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not a mathematician, and therefore need to understand more about matrix determinants. So, if you have time:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) Could you point me in the direction of a sensible reference which lays out what the important issues are&lt;/P&gt;&lt;P&gt;2) Do you have SAS code which allowed you to calculate the determinant from the data structure I have, please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, many thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Piers&lt;/P&gt;</description>
    <pubDate>Sat, 24 Apr 2021 16:59:59 GMT</pubDate>
    <dc:creator>Piers</dc:creator>
    <dc:date>2021-04-24T16:59:59Z</dc:date>
    <item>
      <title>Trouble creating Type = COV dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trouble-creating-Type-COV-dataset/m-p/736741#M229579</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would really appreciate some help with the SAS code I attach. What I want to do is to create a dataset consistent with the Type = COV structure, to be read into PROC SIMNORM. I attach the code used to create the dataset. However, I get the following error message when I ask PROC SIMNORM to read the dataset scov :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Invalid covariance or conditional covariance matrix; matrix is not positive definite.&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;WARNING: The data set WORK.SSIM may be incomplete. When this step was stopped there were 1900&lt;BR /&gt;observations and 5 variables.&lt;BR /&gt;WARNING: Data set WORK.SSIM was not replaced because this step was stopped.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I do not understand what I have done wrong.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be deeply appreciated&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Piers C&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>Sat, 24 Apr 2021 12:50:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trouble-creating-Type-COV-dataset/m-p/736741#M229579</guid>
      <dc:creator>Piers</dc:creator>
      <dc:date>2021-04-24T12:50:11Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble creating Type = COV dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trouble-creating-Type-COV-dataset/m-p/736755#M229587</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/275990"&gt;@Piers&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Covariance matrices are &lt;EM&gt;always&lt;/EM&gt; positive semidefinite, but 21 of your 125 matrices are not. The first example is &lt;FONT face="courier new,courier"&gt;mtx=20&lt;/FONT&gt;: The determinant of this matrix is −0.184 &amp;lt; 0, hence it's not a covariance matrix. Therefore SAS errors out after the first 19 matrices (i.e., after creating 19*100=1900 observations in dataset&amp;nbsp;&lt;SPAN&gt;WORK.SSIM).&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Apr 2021 16:36:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trouble-creating-Type-COV-dataset/m-p/736755#M229587</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-04-24T16:36:07Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble creating Type = COV dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trouble-creating-Type-COV-dataset/m-p/736758#M229589</link>
      <description>&lt;P&gt;Many thanks for this. Its enormously helpful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not a mathematician, and therefore need to understand more about matrix determinants. So, if you have time:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) Could you point me in the direction of a sensible reference which lays out what the important issues are&lt;/P&gt;&lt;P&gt;2) Do you have SAS code which allowed you to calculate the determinant from the data structure I have, please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, many thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Piers&lt;/P&gt;</description>
      <pubDate>Sat, 24 Apr 2021 16:59:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trouble-creating-Type-COV-dataset/m-p/736758#M229589</guid>
      <dc:creator>Piers</dc:creator>
      <dc:date>2021-04-24T16:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble creating Type = COV dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trouble-creating-Type-COV-dataset/m-p/736771#M229597</link>
      <description>&lt;P&gt;You're welcome.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the Wikipedia articles&amp;nbsp;&lt;A href="https://en.wikipedia.org/wiki/Covariance_matrix" target="_blank" rel="noopener"&gt;Covariance matrix&lt;/A&gt;,&amp;nbsp;&lt;A href="https://en.wikipedia.org/wiki/Definite_symmetric_matrix" target="_blank" rel="noopener"&gt;Definite symmetric matrix&lt;/A&gt;&amp;nbsp;and &lt;A href="https://en.wikipedia.org/wiki/Determinant" target="_blank" rel="noopener"&gt;Determinant&lt;/A&gt;&amp;nbsp;contain more than enough information for starters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actually I computed that one determinant by hand. &lt;EM&gt;The&lt;/EM&gt; SAS tool for (vector and) matrix operations is SAS/IML, but I don't have a license for it. As part of Base SAS there are some CALL routines for matrix operations available in &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p10b4qouzgi6sqn154ipglazix2q.htm" target="_blank" rel="noopener"&gt;PROC FCMP&lt;/A&gt;, in particular &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p1d8rhskqp3or5n1q976iaz4yegu.htm" target="_blank" rel="noopener"&gt;CALL DET&lt;/A&gt; to compute determinants, but I haven't really started using those special functions and CALL routines (and using them is less convenient than using ordinary SAS functions and CALL routines). Moreover, there are some relevant methods available in the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/p05tdglkbczcp1n1ijbhzakb1cet.htm" target="_blank" rel="noopener"&gt;DS2 procedure&lt;/A&gt;&amp;nbsp;(as I've just discovered!), in particular the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/ds2ref/n168jy52lakjgzn1bs3xs99fjc96.htm" target="_blank" rel="noopener"&gt;DET method&lt;/A&gt;, which also computes determinants.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your 3x3 matrices a manual implementation of the &lt;A href="https://en.wikipedia.org/wiki/Rule_of_Sarrus" target="_blank" rel="noopener"&gt;Rule of Sarrus&lt;/A&gt; is sufficient:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data det(keep=mtx d:);
array m[3,3];
do i=1 to dim1(m);
  set scov(where=(_name_ ne ' '));
  m[i,1]=a;
  m[i,2]=b;
  m[i,3]=c;
end;
d1=m[1,1];
d2=m[1,1]*m[2,2]-m[1,2]*m[2,1];
d3= m[1,1]*m[2,2]*m[3,3]+m[1,2]*m[2,3]*m[3,1]+m[1,3]*m[3,2]*m[2,1]
   -m[1,3]*m[2,2]*m[3,1]-m[2,3]*m[3,2]*m[1,1]-m[3,3]*m[2,1]*m[1,2];
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The DATA step above computes not only the determinants of your 125 matrices (variable &lt;FONT face="courier new,courier"&gt;d3&lt;/FONT&gt;), but also the first and second leading principal &lt;A href="https://en.wikipedia.org/wiki/Minor_(linear_algebra)" target="_blank" rel="noopener"&gt;minors&lt;/A&gt; (variables&amp;nbsp;&lt;FONT face="courier new,courier"&gt;d1&lt;/FONT&gt;&amp;nbsp;and&amp;nbsp;&lt;FONT face="courier new,courier"&gt;d2&lt;/FONT&gt;). If and only if all three are positive and the matrix is symmetric, the matrix is positive &lt;EM&gt;definite&lt;/EM&gt;. The DATA step below selects matrices which cannot be covariance matrices:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data nocovmat;
set det;
if .&amp;lt;min(of d:)&amp;lt;0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(You constructed the matrices to be symmetric. Of course, this could also be checked in the first DATA step:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;sym=(m[1,2]=m[2,1] &amp;amp; m[1,3]=m[3,1] &amp;amp; m[2,3]=m[3,2])&lt;/FONT&gt;.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There's no exactly analogous criterion for positive &lt;EM&gt;semi&lt;/EM&gt;definite matrices, though: All&amp;nbsp;leading principal minors being non-negative&amp;nbsp;does not imply that a symmetric matrix is positive semidefinite. But for &lt;EM&gt;non-degenerate&lt;/EM&gt;&amp;nbsp;&lt;SPAN&gt;&lt;A href="https://en.wikipedia.org/wiki/Multivariate_normal_distribution" target="_blank" rel="noopener"&gt;multivariate normal distributions&lt;/A&gt;&amp;nbsp;you need positive &lt;EM&gt;definite&lt;/EM&gt; covariance matrices anyway.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Apr 2021 19:26:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trouble-creating-Type-COV-dataset/m-p/736771#M229597</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-04-24T19:26:27Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble creating Type = COV dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trouble-creating-Type-COV-dataset/m-p/736821#M229619</link>
      <description>Wow - very many thanks. The reason for doing this is to try and discover under what covariance conditions the regression model A = B + C + B*C gives a potentially significant interaction terms even though A, B, and C are derived from multivariate normal distributions. You have really been astonishingly helpful&lt;BR /&gt;&lt;BR /&gt;Best&lt;BR /&gt;&lt;BR /&gt;Piers</description>
      <pubDate>Sun, 25 Apr 2021 10:05:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trouble-creating-Type-COV-dataset/m-p/736821#M229619</guid>
      <dc:creator>Piers</dc:creator>
      <dc:date>2021-04-25T10:05:21Z</dc:date>
    </item>
  </channel>
</rss>

