[R] fisher.test gives p>1

Jacob Wegelin jacobwegelin at fastmail.fm
Thu Mar 4 17:15:51 CET 2010

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.


> 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)
> dput(fisher.test(junk$score, junk$group, simulate.p.value=TRUE)$p.value)

In this particular case, specifying a simulated p value solved the problem. But is there a reliable way to avoid p>1 in general?

> sessionInfo()
R version 2.10.1 (2009-12-14) 

[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] tools_2.10.1

Thanks for any insight

Jacob A. Wegelin
Assistant Professor
Department of Biostatistics
Virginia Commonwealth University
730 East Broad Street Room 3006
P. O. Box 980032
Richmond VA 23298-0032

More information about the R-help mailing list