From welinder at rentec.com  Fri May  2 11:03:23 2003
From: welinder at rentec.com (Morten Welinder)
Date: Fri May  2 16:03:41 2003
Subject: [Rd] qbeta hang (PR#2894)
In-Reply-To: <x265oujomh.fsf@biostat.ku.dk> (message from Peter Dalgaard BSA
	on 02 May 2003 00:20:06 +0200)
References: <200305012044.h41Ki02b017789@pubhealth.ku.dk>
	<x265oujomh.fsf@biostat.ku.dk>
Message-ID: <200305021403.h42E3NcU001790@robbie.rentec.com>


Ok, I can confirm that it does not, in fact, loop forever.  Just a close
approximation.

> Morten: the gcc version is often crucial in these cases.

Sorry.  gcc-2.7.2 (both -O2 and -O0) on Solaris 2.9 / sparc.

The problems seem to be...

1. The initial guess underflows to zero.

2. That guess is replaced by the truly awful guess 0.5.

3. The root finding algorithm ignores all the nice properties of pbeta
   -- such as it being monotonically increasing and bounded.

> and you're trying to solve pbeta(x, 1e-8, 0.5,, TRUE, FALSE) == 0.1

Not quite.  What I was trying to do was the see what would happen with an
insanely small alpha.  Actually doing that would involve getting the
arguments right, of course, :-)  The not-quite-hang was an unplesant side
effect of swapping the args.

I notice things like

    r = sqrt(-log(a * a));

in the code.  I fail to see why that isn't just

    r = sqrt(-2 * log (a))

which ought to be faster and more accurate.  Then later

    ...log((1. - a) * qq)...

which might be better as

    ...(log1p(-a) + log (qq))...

if a is close to zero.

There are lots of other places that worry me with respect to cancellation
errors, for example

    r = 1 - pp;
    t = 1 - qq;

Morten


[Rd] qbeta hang (PR#2894)
Morten Welinder