Consider the following dataframe:
df1
# bacteria sample Number_x Number_y
#1 A HM_001 100 30
#2 B HM_001 50 60
#3 C HM_001 300 10
#4 D A2_HM_001 400 20
#5 E A2_HM_001 22 11
#6 F HM_002 23 35
#7 G HM_002 120 46
#8 H HM_003 50 51
# … with 1,342 more rows
Grouped by samples, I wish to perform a row-wise two-sided Fisher exact test for each bacteria. (e.g. HM_001 is shown below).
HM_001 | Number_x | Number_y |
---|---|---|
A | 100 | 30 |
Others (B and C in this case) | 350 | 70 |
HM_001 | Number_x | Number_y |
---|---|---|
B | 50 | 60 |
Others (A and C in this case) | 400 | 40 |
and so forth, essentially generating a p-value for each of the 1350 rows in the dataframe.
Below is my attempt:
Fisher_result <- df1 %>%
group_by(sample) %>%
row_wise_fisher_test(as.matrix(df1[,c(3,4)]), p.adjust.method = "BH")
But it didn't work, outputing the following error message:
Error in row_wise_fisher_test(., as.matrix(df1[, c(3, 4)]), :
A cross-tabulation with two columns required
Any pointers will be greatly appreciated!