s-news
[Top] [All Lists]

Re: [S] Re: Factorials in S-PLUS: over-under

To: Steve Bousquin <sbous@lamar.colostate.edu>, Snews <s-news@wubios.wustl.edu>
Subject: Re: [S] Re: Factorials in S-PLUS: over-under
From: Vadim A Kutsyy <kutsyy@umich.edu>
Date: Tue, 24 Mar 1998 09:52:13 -0500
References: <35168A3A.6F945FBA@lamar.colostate.edu> <3516E8E3.184559F9@lamar.colostate.edu>
Sender: owner-s-news@wubios.wustl.edu
Just write it:

> bin.coef<-function(n,k) gamma(n+1)/(gamma(k+1)*gamma(n-k+1))
> bin.coef(5,2)
[1] 10
> bin.coef(50,30)
[1] 4.712921e+13

But better would be:
> bin.coef<-function(n,k) exp(lgamma(n+1)-lgamma(k+1)-lgamma(n-k+1))
> bin.coef(5,2)
[1] 10
> bin.coef(50,30)
[1] 4.712921e+13

in this case it can handle larger n


Steve Bousquin wrote:
> 
> I was talking about the notation for binomial coefficients (C(n,k))where
> n is over k and they are in parentheses.  That part of the question was
> supposed to ask whether a function existed that would let one enter n
> and k and get (n!/k!(n-k)!).
> 
> Steve Bousquin wrote:
> >
> > I can't seem to find an operator in the manuals for calculating
> > factorials.  I mean !, not experiments.  Also, is there a way to work
> > with the over-under type of notation?
> >
> > Steve Bousquin
> 
> --
> 
> ==============================================
> Steve Bousquin
> 
> Colorado State University
> Department of Rangeland Ecosystem Science/GDPE
> NR209
> Fort Collins, CO 80523
> USA
> 
> sbous@lamar.colostate.edu
> ==============================================
> -----------------------------------------------------------------------
> This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
> send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
> message:  unsubscribe s-news

-- 
Vadim Kutsyy
kutsyy@umich.edu
http://www.stat.lsa.umich.edu/~kutsyy
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>