Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Bug in p-value calculations in adonis #120
The p-value calculated by adonis is sometimes wrong.
library("vegan") options(digits = 12) g = as.factor(c("Control","Control","Group1", "Group2", "Group2")) d = as.dist(matrix(c(0,3,7,2,1, 3,0,5,4,1, 7,5,0,2,6, 4,2,4,0,2, 1,1,6,2,0), ncol=5)) pp = adonis(d ~ g) pp
The p-value is wrong (only 24 permutations with high f instead of 39). The correct p-value can be computed from the definition to be
(rowSums(t(pp$f.perms >= pp$aov.tab$F.Model))+1) / (length(pp$f.perms) + 1)
which correctly returns
It looks like the bug is due to rounding. When comparing f.perms and F.mod, the value of f.perms is rounded but the value of F.mod is not (although it is rounded afterwards). This makes the >= comparison fail in this example because the value of f.perms is rounded down.