BookmarkSubscribeRSS Feed
kfs
Calcite | Level 5 kfs
Calcite | Level 5
Within a larger SAS program, I wish to compute multinomial coefficients, say

${y \choose a_1, a_2, \ldots, a_k}$

and I can't figure out how to compute this value for a changing value k (ie changing number of terms, a1 through a_k). Any advice or suggestions that can be offered would be greatly appreciated. Thanks.
1 REPLY 1
lvm
Rhodochrosite | Level 12 lvm
Rhodochrosite | Level 12
One approach is to take advantage of the fact that x! is the same as GAM(x+1), where GAM() is the complete gamma function. Also, note that the function can blow up with very large numbers, so it is better to work in log gamma functions, and then use exp() to retrieve the result. If one wanted to do the combinatorial "n choose y", one could use the following code. For instance, "10 choose 3" is 120.
data bb;
input n y;
C1 = (lgamma(n+1) -lgamma(y+1) - lgamma(n-y+1) );
C = exp(C1);
datalines;
5 0
5 1
5 2
5 3
5 4
5 5
10 0
10 1
10 2
10 3
10 4
10 5
10 6
10 7
10 8
10 9
10 10
1000 0
1000 500
1000 999
;
proc print data=bb;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 1186 views
  • 0 likes
  • 2 in conversation