[Rd] bug(?) in chisq.test

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Mar 9 16:30:22 MET 2004


`Ripley' has already corrected the R sources: from NEWS

    o   chisq.test(simulate.p.value = TRUE) was returning slightly
	incorrect p values, notably p = 0 when the data gave the most
	extreme value.

Note that all the p values were incorrect as one needs to be added to both 
numerator and denominator, but the difference is unimportant in other 
cases.

On Tue, 9 Mar 2004, Graves wrote:

>       This is a message for whoever maintains "chisq.test":  For an 
> outcome more extreme than 2000 simulations, a Monte Carlo p-value of "< 
> 2.2e-16" was printed.  Ripley said the proper p-value for such cases 
> should be 1/(B+1) = 1/2001.  This can be easily fixed by adding 
> "if(PVAL==0)PVAL <- 1/(B+1)" right after the following line in the code 
> for chisq.test (in R 1.8.1 for Windows): 
> 
> >             PVAL <- sum(tmp$results >= STATISTIC)/B
> 
>       Thanks for all your hard work for the R Project. 
>       Best Wishes,
>       spencer graves

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list