
Statistical Functions in ASP?
I have a need for some statistical functions in ASP, especially <BR><BR>Combin(f,n), <BR><BR>which equals:<BR><BR> f!<BR><BR>n!*(fn)!<BR><BR>Now this function is mentioned on Microsofts website:<BR>http://msdn.microsoft.com/library/default.asp?url=/library/enus/office97/xhtml/SEB62.asp<BR><BR>(Must be an office97 function.)<BR><BR>But the function does not exist in ASP. Is that function written out some place? I need it, but I don't seem to know where to get it. If you have experience in getting this off of Microsoft's website so that it can work within an asp page, please let me know what I am missing here.<BR><BR>Thanks,<BR><BR>Edward<BR>;)

RE: Statistical Functions in ASP?  HELP!
A better function than the one just mentioned would be:<BR>HYPGEOMDIST <BR>shown here:<BR>http://msdn.microsoft.com/library/default.asp?url=/library/enus/office97/xhtml/SEBBD.asp<BR>Please let me know if you know how to make this function work in asp.<BR><BR>THANK YOU and happy new year!<BR><BR>Edward<BR>

No...but easy to write...
<%<BR>Function Factorial(n)<BR> dim i, p<BR> p = 1<BR> For i = 2 To n<BR> p = p * i<BR> Next<BR> Factorial = p<BR>End Function<BR><BR>Function Combin( f, n )<BR> Combin = Factorial(f) / ( Factorial(n) * Factorial(fn) )<BR>End Function<BR>%><BR><BR>If you recognize that<BR>f!<BR><BR>n! <BR>can be done via a shortcut, you can write code that's a bit faster. But maybe stick to the straightforward way when starting out?<BR>

More code, but not...
...really more complicated.<BR><BR>Function hypgeomdist( x, y, M, N ) <BR> Dim t1, t2, t3<BR> t1 = Combin( M, x )<BR> t2 = Combin( NM, yx )<BR> t3 = Combin( N, y )<BR> hypgeomdist = t1 * t2 / t3<BR>End Function <BR><BR>Assuming I read that correctly!<BR><BR>

OVERFLOW
I have tried writing code like that, but I keep getting overflow errors (not enough stacks, etc.)<BR><BR>The reason I am looking to reproduce the function HYPGEOMDIST (available to Microsoft office) is that there are many simplifications possible in the fraction form, that using VBscript cannot do. So, I end up with the HUGE numbers that finally create overflow errors. If I could copy this function, written by some hotshot microsoft techie, I am pretty sure I would not run into the trouble. Please take a look at this page:<BR>http://msdn.microsoft.com/library/default.asp?url=/library/enus/office97/xhtml/SEBBD.asp<BR><BR>And this page:<BR>http://www.lottery.state.mn.us/hypergeo.html<BR><BR>Thank you Bill!<BR><BR>Edward<BR>

Worked for me...
*********** FILE: hypTest.asp **********<BR><HTML><BODY><BR> <% <BR>Function Factorial(n) <BR> dim i, p <BR> p = 1 <BR> For i = 2 To n <BR> p = p * i <BR> Next <BR> Factorial = p <BR>End Function <BR><BR>Function Combin( f, n ) <BR> Combin = Factorial(f) / ( Factorial(n) * Factorial(fn) ) <BR>End Function <BR><BR>Function hypgeomdist( x, y, M, N ) <BR> Dim t1, t2, t3 <BR> t1 = Combin( M, x ) <BR> t2 = Combin( NM, yx ) <BR> t3 = Combin( N, y ) <BR> hypgeomdist = t1 * t2 / t3 <BR>End Function <BR><BR>%> <BR><BR>hypgeomdist( 1, 4, 8, 20 ) is <%= hypgeomdist( 1, 4, 8, 20 ) %><BR><BR></BODY></HTML><BR><BR>******************************** *********<BR><BR>If you are getting overflow, then you might need to pull the trick I mentioned.<BR><BR>Recognize that <BR><BR>f!<BR> <BR>n!<BR><BR>can be done all in one operation via:<BR> p = 1<BR> For i = n+1 To f<BR> p = p * i<BR> Next<BR><BR>Do you see why?<BR><BR>suppose f is 7 and n is 3.<BR><BR>7! = 7 * 6 * 5 * 4 * 3 * 2 * 1<BR><BR>3! = 3 * 2 * 1<BR><BR>So if you just start at 4 and go to 7 in your building of the product, you have it.<BR><BR>Play with improving the number of loops, etc., in the Combin function and you should get it to work. There's no magic math formula to get the factorial of a number. It's all just hard work.<BR><BR><BR>

If you get *STACK* overflow...
...it is almost surely because you wrote your factorial function using recursion.<BR><BR>Tch. Doing factorial by recursion is a cute trick to demo how it works, but it's a horrible way to get a factorial in real life.<BR><BR>

Indeed, *do* look at that page...
http://www.lottery.state.mn.us/hypergeo.html<BR><BR>Look at the example at the bottom, where they reduce the combinatorials to the *actual* multiplies needed! For example, instead of having to calculate 44! and 42!, they end up just multiplying 44*43  TA DA.<BR><BR>If you write your own COMBIN function to pull those kinds of tricks, it will work in most any *real* case.<BR><BR>
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

