|
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) Thanks in advance for any assisstance. Regards, Greg [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
|
How about this?
mbeta <- function(...) { exp(sum(lgamma(c(...)))-lgamma(sum(c(...)))) } > gamma(5)*gamma(6)*gamma(7)/gamma(18) [1] 5.829838e-09 > mbeta(5,6,7) [1] 5.829838e-09 On Mon, 2010-07-05 at 17:10 -0400, 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) > > Thanks in advance for any assisstance. > > Regards, > Greg > > > > [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. Matthew S. Shotwell Graduate Student Division of Biostatistics and Epidemiology Medical University of South Carolina http://biostatmatt.com ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
|
In reply to this post by Gregory Gentlemen
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 ================================================================ Robert A. LaBudde, PhD, PAS, Dpl. ACAFS e-mail: [hidden email] Least Cost Formulations, Ltd. URL: http://lcfltd.com/ 824 Timberlake Drive Tel: 757-467-0954 Virginia Beach, VA 23464-3239 Fax: 757-467-2947 "Vere scire est per causas scire" ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
|
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 ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
| Powered by Nabble | Edit this page |
