help with gamma function

Status
Not open for further replies.
I'm afraid my math in this area is a bit deficient, but what I am trying to do is see if there's a way to simplify the function:
Code:
Gamma(x)/Gamma(x-0.5)
or alternatively,
Code:
log(Gamma(x)) - log(Gamma(x-0.5))
so that I can actually calculate the results when x is large (>1000, for example).

For the first function above, that's (AFAIK) equivalent to:
Code:
( x! * (4^(x-1)) * (x-1)! ) / ( (2*(x-1))! * sqrt(pi) )
but I never really learned how to manipulate factorials algebraically, so I'm not sure how to proceed. Of course, it may not even be possible to do what I'm looking for, in which case it'd be nice to know that, too, so I can try to implement one of the various approximations out there instead of the "full" function.

Longer-term, I'd really be interested in a way to calculate the following function (from Hotelling, 1953) for large x (see function f3 on page 2 here): Sun & Wong (2007), if anyone has any suggestions (the function above is a part of this larger function). Any advice is appreciated, thanks.
 
Well, that's embarrassing. I spent the last two days looking for a solution, then right after posting I find that the solution already appears to be implemented in my stats package of choice (R) via the lgamma function.

That bit at least gets me up to an x of ~1000 with no problems, which is likely to be adequate for most applications. Still, if anyone has any idea on a more complete solution for calculating f3 from the linked article for large sample sizes, it would be useful.
 

CS

Ars Praetorian
528
If I understand correctly, the G function in f3 is the hypergeometric function 2F1. There appears to be a package to calculate this in R -- look for "hypergeo" with function:
Code:
hypergeo(A, B, C, z, tol = 0, maxiter = 2000)
The hypergeo reference document calls this 1F2, but that might be a typo since the definition is consistent with 2F1 (generalized hypergeometric functions are of the form pFq for some p and q; THE hypergeometric function is p=2, q=1). I am not an R user, so you might want to double check that documentation yourself.

Depending on how large n is, it is probably best to take the logarithm of all of f3, sum the terms, then take the exponential, though it seems like you might already be thinking of doing this.
 

OperaMalenky

Ars Tribunus Militum
2,169
CS":9akxrn9b said:
If I understand correctly, the G function in f3 is the hypergeometric function 2F1. There appears to be a package to calculate this in R -- look for "hypergeo" with function:
Code:
hypergeo(A, B, C, z, tol = 0, maxiter = 2000)
The hypergeo reference document calls this 1F2, but that might be a typo since the definition is consistent with 2F1 (generalized hypergeometric functions are of the form pFq for some p and q; THE hypergeometric function is p=2, q=1). I am not an R user, so you might want to double check that documentation yourself.

Depending on how large n is, it is probably best to take the logarithm of all of f3, sum the terms, then take the exponential, though it seems like you might already be thinking of doing this.

Yep, that's actually exactly what I ended up doing (right down to the logs), and it all works great. At least, it worked well enough to allow me to test the basic approach for my intended use case.

Unfortunately, further testing suggests doing this in R is too slow for reasonable use (I'm using it as part of a larger function in a MCMC algorithm), so now I'm going to see if I can implement it in C++ (I could do it easily enough using the GSL, but that's unfeasible right now due to #$@! org policies, so it looks like I'll need to try to write my own hypergeometric function. Crap.)
 
Status
Not open for further replies.