Reputation: 31
I have a data frame which looks like this:
table1
SNo. C1 C2 C3 C4 C5
1. A*01 17 116 78 141
2. A*02 30 1 65 256
3. A*03 --------------
4. A*04 --------------
5.----------------------
For each row I want to calculate Odds ratio and 95% Confidence Interval using fisher.test()
function which requires 2x2 table. When I provide numbers manually to do the test it works fine: fisher.test(matrix(c(17, 116,78, 141), ncol = 2, byrow = TRUE))
But when I do fisher.test(matrix(c(table1[1,2:5]), ncol=2, byrow=T))
it gives me this error:
all entries of 'x' must be nonnegative and finite
Please suggest what am I doing wrong
Upvotes: 0
Views: 90
Reputation: 93813
You're not passing the right input to the function. When you do so, it works fine. E.g.:
dat <- read.table(text="SNo. C1 C2 C3 C4 C5
1. A*01 17 116 78 141
2. A*02 30 1 65 256",header=TRUE)
apply(
dat[-(1:2)],
1,
function(x) fisher.test(matrix(x,nrow=2,byrow=TRUE))
)
#[[1]]
#
# Fisher's Exact Test for Count Data
#...
#odds ratio
# 0.2658521
#
#
#[[2]]
#
# Fisher's Exact Test for Count Data
#...
#odds ratio
# 116.4649
Upvotes: 2