<?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 input shape parameter in randdirichlet in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-input-shape-parameter-in-randdirichlet/m-p/504042#M4396</link>
    <description>&lt;P&gt;Because you mention counts and percentages, I think you are looking for the multinomial distribution, not the Dirichlet distribution, The multinomial distribution, which you can simulate by using the RANDMULTINOMIAL function in SAS/IML, generates random frequencies for k categories where the&amp;nbsp;probabilities of the categories in the population are known. For example,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
call randseed(1);
n = 1000;
counts = {50, 100, 150, 200};	/* expected count for each category */
total = sum(counts);
prob = counts / total;
x = RandMultinomial(n, total, prob); /* x is 1000 x 4 matrix of counts */
print (x[1:5,]);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Dirichlet distribution is a multivariate generalization of the beta distribution, so I do not immediately see how it is related to counts.&lt;/P&gt;</description>
    <pubDate>Sat, 13 Oct 2018 20:56:25 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2018-10-13T20:56:25Z</dc:date>
    <item>
      <title>how to input shape parameter in randdirichlet</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-input-shape-parameter-in-randdirichlet/m-p/504017#M4395</link>
      <description>&lt;P&gt;my data has 4 categories, and each category has count of 50, 100, 150, 200 (percentages as 10%, 20%, 30% and 40% of total data).&lt;/P&gt;
&lt;P&gt;I want to simulate and sampling with randdirichlet function for these 4 percentages, but with the code below, I only got 3 percentages and have to calculate the 4th one myself. Maybe I did not specify the shape parameters correctly. Please advise.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* want to simulate 4 percentages with randdirichlet*/
proc iml;
call randseed(1);
n = 1000;
Shape = {50, 100, 150, 200};	/* counts of each category */
x = RandDirichlet(n,Shape);  	/* x is 1000 x 3 matrix*/
samplemean=mean(x);  		/* check mean */
print samplemean;

varnames='percentage1':'percentage3';
create MyData from x[colname=varnames]; 		
append from x;
close MyData;       /* only first 3 percentages columns */
quit;

/* to get the 4th percentage */
data mydata2;
set mydata;
percentage4=1-(percentage1+percentage2+percentage3); 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;according to &lt;A href="http://support.sas.com/documentation/cdl/en/imlug/66845/HTML/default/viewer.htm#imlug_langref_sect325.htm" target="_self"&gt;sas user's guide&lt;/A&gt;,&amp;nbsp;&lt;/P&gt;
&lt;DIV class="AAdeflist"&gt;
&lt;DL class="AAdeflist"&gt;
&lt;DT&gt;&lt;SPAN class=" AAterm "&gt;&lt;SPAN class="phrase AAargument"&gt;Shape&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;is a&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="inlinemediaobject"&gt;&lt;IMG class="math" src="http://support.sas.com/documentation/cdl/en/imlug/66845/HTML/default/images/imlug_langref0073.png" border="0" alt="$1 \times (p+1)$" width="64" height="16" /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;vector of shape parameters for the distribution,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="inlinemediaobject"&gt;&lt;IMG style="margin: 0px; padding: 0px; border: 0px; font-weight: normal; font-style: normal; line-height: 1.25em; font-family: inherit; text-align: left; vertical-align: -4px;" class="math" src="http://support.sas.com/documentation/cdl/en/imlug/66845/HTML/default/images/imlug_langref1110.png" border="0" alt="$\mbox{Shape}[i]&amp;gt;0$" width="74" height="16" /&gt;&lt;/SPAN&gt;.&amp;nbsp;&lt;/DT&gt;
&lt;DD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and in the example, the shape has 3 parameters for a&lt;SPAN&gt;&amp;nbsp;two-dimensional Dirichlet distribution&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call randseed(1);
n = 1000;
Shape = {2, 1, 1};
x = RandDirichlet(n,Shape);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/DD&gt;
&lt;/DL&gt;
&lt;/DIV&gt;</description>
      <pubDate>Sat, 13 Oct 2018 15:48:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-input-shape-parameter-in-randdirichlet/m-p/504017#M4395</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2018-10-13T15:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: how to input shape parameter in randdirichlet</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-input-shape-parameter-in-randdirichlet/m-p/504042#M4396</link>
      <description>&lt;P&gt;Because you mention counts and percentages, I think you are looking for the multinomial distribution, not the Dirichlet distribution, The multinomial distribution, which you can simulate by using the RANDMULTINOMIAL function in SAS/IML, generates random frequencies for k categories where the&amp;nbsp;probabilities of the categories in the population are known. For example,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
call randseed(1);
n = 1000;
counts = {50, 100, 150, 200};	/* expected count for each category */
total = sum(counts);
prob = counts / total;
x = RandMultinomial(n, total, prob); /* x is 1000 x 4 matrix of counts */
print (x[1:5,]);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Dirichlet distribution is a multivariate generalization of the beta distribution, so I do not immediately see how it is related to counts.&lt;/P&gt;</description>
      <pubDate>Sat, 13 Oct 2018 20:56:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/how-to-input-shape-parameter-in-randdirichlet/m-p/504042#M4396</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-10-13T20:56:25Z</dc:date>
    </item>
  </channel>
</rss>

