I am running a Fisher Exact test on some contingency matrix in R. However, using this code:
for (class in 1:5) {
for (test in c("amp", "del")) {
prefisher <- read.table("prefisher.txt", sep="\t", row.names=1)
for (gene in rownames(prefisher)) {
genemat <- matrix(prefisher[gene,], ncol=2)
print(genemat)
result <- fisher.test(genemat)
write(paste(gene, result$estimate, result$p.value, sep = "\t"), "")
}
}
}
I am getting the following error:
[,1] [,2]
[1,] 1 0
[2,] 101 287
Error in fisher.test(genemat): all entries of 'x' must be nonnegative and finite
As you can see, the matrix genemat
is nonnegative and finite.
str(genemat)
returns:
List of 4
$ : int 1
$ : int 101
$ : int 0
$ : int 287
- attr(*, "dim")= int [1:2] 2 2
What am I doing wrong?
Thanks