[Rd] Re: [R-SIG-Mac] Bug running pbinom() in R-GUI?

From: Simon Urbanek <urbanek_at_research.att.com>
Date: Sat 12 Feb 2005 - 06:26:37 EST

On Feb 10, 2005, at 7:38 PM, George W. Gilchrist wrote:

> Today I was running a graduate level stats lab using R and we
> encountered a
> major problem while using the current build of the Cocoa GUI:
>
>> From the GUI:
>> system.time(pbinom(80, 1e5, 806/1e6))
> [1] 14.37 4.94 30.29 0.00 0.00
>>
>
>> From the command line on the same machine:
>> system.time(pbinom(80, 1e5, 806/1e6))
> [1] 0.02 0.00 0.02 0.00 0.00
>>
>
> I've tried the CRAN version and the latest build of the R-GUI and both
> deliver the same terrible performance. It seems as if this only occurs
> for
> certain arguments, but we saw this on ~15 different machines today.
> And it
> seems to only be when running the Cocoa GUI. No problems at all with
> this
> under Windoze. Any ideas?

The cause is pbeta_raw calling (indirectly via R_CheckUserInterrupt) R_ProcessEvents for every iteration - and for small p the number of iterations goes really high (e.g. for the case above n=99919). R_ProcessEvents is not a cheap operation, because it enters system event loop and processes any pending events. A quick fix could be the following patch, which checks for break only after several iterations (including the first one, just in case this is part of a sequence that may need user interaction).

Index: src/nmath/pbeta.c


after this patch has been applied I get in the GUI:

 > system.time(pbinom(80, 1e5, 806/1e6)) [1] 0.02 0.00 0.08 0.00 0.00

Cheers,
Simon



R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat Feb 12 05:31:36 2005

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 09:02:51 EST