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> > dput(fisher.test(junk$score, junk$group, simulate.p.value=TRUE)$p.value)1 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) x86_64-apple-darwin9.8.0 locale: [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 U.S.A.
>>>>> Jacob Wegelin <jacobwegelin at fastmail.fm> >>>>> on Thu, 4 Mar 2010 11:15:51 -0500 (EST) writes:> 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 >> >> dput(fisher.test(junk$score, junk$group, >> simulate.p.value=TRUE)$p.value) > 1 > In this particular case, specifying a simulated p value > solved the problem. But is there a reliable way to avoid > p>1 in general? Yes, using the very latest version of R-devel (svn revision >= 51204) :-) "Of course", the above is just the result of rounding error propagation in an extreme case. I've now simply replaced PVAL by max(0, min(1, PVAL)) in the one place it seems sensible. Martin Maechler, ETH Zurich >> sessionInfo() > R version 2.10.1 (2009-12-14) x86_64-apple-darwin9.8.0 > locale: [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 U.S.A.
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.00000000000012Hi 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-these-numbers-are-equal_003f -- Bernardo Rangel Tura, M.D,MPH,Ph.D National Institute of Cardiology Brazil