[R] Function to compute the multinomial beta function?
Robin Hankin
rksh1 at cam.ac.uk
Tue Jul 6 09:31:15 CEST 2010
It's usually better to build vectorization in to functions:
> beta3<- function (n1, n2, n3)
exp(lgamma(n1)+lgamma(n2)+lgamma(n3)-lgamma(n1+n2+n3))
> f <- function(x){exp(sum(lgamma(x))-lgamma(sum(x)))}
> beta3(5,3,8)
[1] 1.850002e-07
> f(c(5,3,8))
[1] 1.850002e-07
>
rksh
On 07/06/2010 01:54 AM, Robert A LaBudde wrote:
> At 05:10 PM 7/5/2010, Gregory Gentlemen wrote:
>> Dear R-users,
>>
>> Is there an R function to compute the multinomial beta function? That
>> is, the normalizing constant that arises in a Dirichlet distribution.
>> For example, with three parameters the beta function is
>> Beta(n1,n2,n2) = Gamma(n1)*Gamma(n2)*Gamma(n3)/Gamma(n1+n2+n3)
>
> > beta3<- function (n1, n2, n3)
> exp(lgamma(n1)+lgamma(n2)+lgamma(n3)-lgamma(n1+n2+n3))
> > beta3(5,3,8)
> [1] 1.850002e-07
>
--
Robin K. S. Hankin
Uncertainty Analyst
University of Cambridge
19 Silver Street
Cambridge CB3 9EP
01223-764877
More information about the R-help
mailing list