mnason@Niaid.nih.gov
2005-Apr-20 23:31 UTC
[Rd] negative p-values from fisher's test (PR#7801)
Full_Name: Martha Nason Version: 2.0.1 OS: Windows XP Submission from: (NULL) (137.187.154.154) I am running simulations using fisher's test on 2 x c tables and a very small p.value from fisher's test (<2.2e-16) is returned as a negative number. Code follows.> set.seed(0) > nreps.outer <-7 > pvalue.fisher <- rep(NA,nreps.outer) > > population1 <- c( rep("A",300),seq(1:100)) > > population2 <- c( rep("A",100),seq(101:200)) > > > for (j in 1:nreps.outer){+ n1 <- sample(30:100,1) + n2 <- sample(30:100,1) + + group1 <- sample(population1, n1, replace=T) + group2 <- sample(population2, n2, replace=T) + + pvalue.fisher[j] <- fisher.test(table(c(group1,group2),c(rep("group1",n1),rep("group2",n2))))$p.value + + print(c(j,pvalue.fisher[j])) + + } [1] 1.000000e+00 3.581362e-05 [1] 2.0000000 0.1424779 [1] 3.0000000 0.1196600 [1] 4.000000000 0.004222897 [1] 5.000000e+00 3.234016e-07 [1] 6.000000000 0.003240286 [1] 7.000000e+00 -3.847298e-05> > fisher.test(table(c(group1,group2),c(rep("group1",n1),rep("group2",n2))))Fisher's Exact Test for Count Data data: table(c(group1, group2), c(rep("group1", n1), rep("group2", n2))) p-value < 2.2e-16 alternative hypothesis: two.sided> fisher.test(table(c(group1,group2),c(rep("group1",n1),rep("group2",n2))))$p.value[1] -3.847298e-05
>>>>> mnason writes:> Full_Name: Martha Nason > Version: 2.0.1 > OS: Windows XP > Submission from: (NULL) (137.187.154.154)> I am running simulations using fisher's test on 2 x c tables and a > very small p.value from fisher's test (<2.2e-16) is returned as a > negative number. Code follows.>> set.seed(0) >> nreps.outer <-7 >> pvalue.fisher <- rep(NA,nreps.outer) >> >> population1 <- c( rep("A",300),seq(1:100)) >> >> population2 <- c( rep("A",100),seq(101:200)) >> >> >> for (j in 1:nreps.outer){ > + n1 <- sample(30:100,1) > + n2 <- sample(30:100,1) > + > + group1 <- sample(population1, n1, replace=T) > + group2 <- sample(population2, n2, replace=T) > + > + pvalue.fisher[j] <- > fisher.test(table(c(group1,group2),c(rep("group1",n1),rep("group2",n2))))$p.value > + > + print(c(j,pvalue.fisher[j])) > + > + } > [1] 1.000000e+00 3.581362e-05 > [1] 2.0000000 0.1424779 > [1] 3.0000000 0.1196600 > [1] 4.000000000 0.004222897 > [1] 5.000000e+00 3.234016e-07 > [1] 6.000000000 0.003240286 > [1] 7.000000e+00 -3.847298e-05>> >> fisher.test(table(c(group1,group2),c(rep("group1",n1),rep("group2",n2))))> Fisher's Exact Test for Count Data> data: table(c(group1, group2), c(rep("group1", n1), rep("group2", n2))) > p-value < 2.2e-16 > alternative hypothesis: two.sided>> fisher.test(table(c(group1,group2),c(rep("group1",n1),rep("group2",n2))))$p.value > [1] -3.847298e-05Thanks. This comes from L300: /* Process node with new PASTP */ if (pastp <= obs3) { /* Update pre */ *pre += (double) ifreq * exp(pastp + drn); in f2xact which (e.g. by adding REprintf("pre: %f %d %f \n", *pre, ifreq, (double) ifreq * exp(pastp + drn)); shows that ifreq may have negative values. Now ifreq comes from ifrq which has IFRQ - Vector of length LDSTP containing the past path frequencies. (in/out) so I am not sure whether we should have negative values here (we migth be indexing something one off) ... Does anyone know how the algorithm works in detail? -k