fisher.test(x, y=NULL, node.stack.dim=1001, value.stack.dim=10000, hybrid=F)
Conversely, if x and y are present, and either x or y is not a factor or category object (and x is not a matrix), it will be coerced to one implicitly. In this case pairs (x[i],y[i]) containing NAs will be removed, but not pairs with Infs. Coercion of x and y in this manner is intended for datasets of mode numeric, whose elements are typically small integers; data in the form of character vectors should first be made into factor or category objects.
The algorithm used in fisher.test is based on theory from Mehta and Patel (1983, 1986) and Joe (1985, 1988). It involves a network algorithm together with matrix majorization results to find the maximum and minimum of a certain objective function at each node in the network that is processed. See Joe (1988).
Bishop, Y. M. M., Fienberg, S. J., and Holland, P. W. (1980). Discrete Multivariate Analysis: Theory and Practice, Cambridge, Mass.: The MIT Press.
Fleiss, J. L. (1981). Statistical Methods for Rates and Proportions, 2nd ed. New York: Wiley.
Zar, J. H. (1984). Biostatistical Analysis, 2nd ed. Englewood Cliffs: Prentice-Hall.
(b) Computer Algorithm
Joe, H. (1985). An Ordering of Dependence for Contingency Tables. Linear Algebra and its Applications 70, 89-103.
Joe, H. (1988). Extreme probabilities for contingency tables under row and column independence with application to Fisher's exact test. Communications in Statististics A, Theory and Methods 17, 3677-3685.
Mehta, C. R. and Patel, N. R. (1983). A network algorithm for performing Fisher's exact test in r*c contingency tables. Journal of the American Statistical Association 78, 427-434.
Mehta, C. R. and Patel, N. R. (1986). Algorithm 643. FEXACT: A Fortran subroutine for Fisher's exact test on unordered r*c contingency tables. ACM Transactions on Mathematical Software 12, 154-161.
Mehta, C. R. and Patel, N. R. (1986). A hybrid algorithm for Fisher's exact test in unordered r*c contingency tables. Communications in Statististics A, Theory and Methods 15, 387-404.
x # x and y are category objects [1] 1 1 2 1 2 1 1 2 2 attr(, "levels"): [1] "A" "A bar" table(x,y) # table from Fleiss, p. 25 B B bar A 2 3 A bar 4 0 fisher.test(x,y) fisher.test(table(x,y)) # same thing