[R] fisher.test gives p>1
(Ted Harding)
Ted.Harding at manchester.ac.uk
Thu Mar 4 21:33:07 CET 2010
On 04-Mar-10 19:27:16, Bernardo Rangel Tura wrote:
> On Thu, 2010-03-04 at 11:15 -0500, Jacob Wegelin wrote:
>> The purpose of this email is to
>>
>> (1) report an example where fisher.test returns p > 1
>> (2) ask if there is a reliable way to avoid p>1 with fisher.test.
>>
>> If one has designed one's code to return an error when it finds a
>> "nonsensical" probability, of course a value of p>1 can cause havoc.
>>
>> Example:
>>
>> > junk<-data.frame(score=c(rep(0,14), rep(1,29), rep(2, 16)))
>> > junk<-rbind(junk, junk)
>> > junk$group<-c(rep("DOG", nrow(junk)/2), rep("kitty", nrow(junk)/2))
>> > table(junk$score, junk$group)
>>
>> DOG kitty
>> 0 14 14
>> 1 29 29
>> 2 16 16
>> > dput(fisher.test(junk$score, junk$group)$p.value)
>> 1.00000000000012
>
> Hi jacob,
>
> I think this is cover in R FAQ 7.31, but look this command
> all.equal(dput(fisher.test(matrix(c(14,14,29,29,16,16),byrow=T,ncol=2))$
> p.value),1)
> 1.00000000000012
> [1] TRUE
>
> P.S
> R FAQ 7.31 -
> http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-the
> se-numbers-are-equal_003f
>
> --
> Bernardo Rangel Tura, M.D,MPH,Ph.D
> National Institute of Cardiology
> Brazil
This is yet another example where the advice (in my posting
in the "precision" thread), that if an anomaly occurs it is
is useful to check the magnitude of the anomaly, applies.
Then:
a <- 68.08 ; b <- a-1.55 ; a-b == 1.55
# [1] FALSE
(a-b) - 1.55
# [1] -2.88658e-15
Here (as Jakob found for himself):
p = 1.00000000000012
Or, more precisely (using Jakob's data):
fisher.test(junk$score, junk$group)$p.value -1
# [1] 5.728751e-14
(which is not quite the same, but makes the same point).
The presence of a discrepancy of the order of 1e-14 or 1e-15
(or smaller) is always a strong clue that errors due to the
accumulation of imprecise binary representations may have
occurred.
Martin's replacement with max(0, min(1, PVAL)) will remove
such anomalies (which still will not guarantee that a result
of 0.9999999999999974 is exact, but that is probably not
important; what is important is that it does not break the
logic of probability.
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 04-Mar-10 Time: 20:33:03
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list