Message |
William Chesters writes: > Benjamin Janes writes: > > we don't have lgamma, there is > > GAMMADIST for VC++, but I'm not willing to learn that just yet, so could NB gammadist sounds more like the density function of a gamma distribution---which is not the right thing > > you as stated send an approximation, for the Beta Dist. or the Gamma > > Dist, or even Log Gamm Dist. > yep, I'll look that up for you Here it is from Numerical Recipes. It is actually very accurate. But don't mess up those magic numbers when you translate it into VB :-). If you want to check it: you should get exp(log(gamma(x))) = (x-1)! , for instance exp(log(gamma(6))) = 5! = 120. // computes log(gamma(x)) to a close approximation double lgamma_lanczos(const double x) { double y, tmp, ser; static const double cof[6] = { 76.18009172947146, -86.50532032941677, 24.01409824083091, -1.231739572450155, 0.1208650973866179e-2, -0.5395239384953e-5 }; y = x; tmp = x + 5.5; tmp -= (x + 0.5) * log(tmp); ser = 1.000000000190015; for (int j = 0; j <= 5; j++) ser += cof[j] / ++y; return -tmp + log(2.5066282746310005 * ser/x); } // computes log(beta(x, y)) to a close approximation double lbeta_lanczos(const double x, const double y) { return lgamma_lanczos(x) + lgamma_lanczos(y) - lgamma_lanczos(x + y); } > > I take it that the lgamma computes log to the base e? er yes, sorry
|