fisher.test              package:stats              R Documentation

_F_i_s_h_e_r'_s _E_x_a_c_t _T_e_s_t _f_o_r _C_o_u_n_t _D_a_t_a

_D_e_s_c_r_i_p_t_i_o_n:

     Performs Fisher's exact test for testing the null of independence
     of rows and columns in a contingency table with fixed marginals.

_U_s_a_g_e:

     fisher.test(x, y = NULL, workspace = 200000, hybrid = FALSE,
                 control = list(), or = 1, alternative = "two.sided",
                 conf.int = TRUE, conf.level = 0.95)

_A_r_g_u_m_e_n_t_s:

       x: either a two-dimensional contingency table in matrix form, or
          a factor object.

       y: a factor object; ignored if 'x' is a matrix.

workspace: an integer specifying the size of the workspace used in the
          network algorithm.

  hybrid: a logical indicating whether the exact probabilities
          (default) or a hybrid approximation thereof should be
          computed. In the hybrid case, asymptotic chi-squared
          probabilities are only used provided that the "Cochran"
          conditions are satisfied.

 control: a list with named components for low level algorithm control.

      or: the hypothesized odds ratio.  Only used in the 2 by 2 case.

alternative: indicates the alternative hypothesis and must be one of
          '"two.sided"', '"greater"' or '"less"'. You can specify just
          the initial letter.  Only used in the 2 by 2 case.

conf.int: logical indicating if a confidence interval should be
          computed (and returned).

conf.level: confidence level for the returned confidence interval. 
          Only used in the 2 by 2 case.

_D_e_t_a_i_l_s:

     If 'x' is a matrix, it is taken as a two-dimensional contingency
     table, and hence its entries should be nonnegative integers.
     Otherwise, both 'x' and 'y' must be vectors of the same length. 
     Incomplete cases are removed, the vectors are coerced into factor
     objects, and the contingency table is computed from these.

     In the one-sided 2 by 2 cases, p-values are obtained directly
     using the hypergeometric distribution.  Otherwise, computations
     are based on a C version of the FORTRAN subroutine FEXACT which
     implements the network developed by Mehta and Patel (1986) and
     improved by Clarkson, Fan & Joe (1993).  The FORTRAN code can be
     obtained from <URL: http://www.netlib.org/toms/643>.  Note this
     fails (with an error message) when the entries of the table are
     too large.

     In the 2 by 2 case, the null of conditional independence is
     equivalent to the hypothesis that the odds ratio equals one. 
     Exact inference can be based on observing that in general, given
     all marginal totals fixed, the first element of the contingency
     table has a non-central hypergeometric distribution with
     non-centrality parameter given by the odds ratio (Fisher, 1935).

_V_a_l_u_e:

     A list with class '"htest"' containing the following components: 

 p.value: the p-value of the test.

conf.int: a confidence interval for the odds ratio. Only present in the
          2 by 2 case.

estimate: an estimate of the odds ratio.  Note that the _conditional_
          Maximum Likelihood Estimate (MLE) rather than the
          unconditional MLE (the sample odds ratio) is used. Only
          present in the 2 by 2 case.

null.value: the odds ratio under the null, 'or'. Only present in the 2
          by 2 case.

alternative: a character string describing the alternative hypothesis.

  method: the character string '"Fisher's Exact Test for Count Data"'.

data.name: a character string giving the names of the data.

_R_e_f_e_r_e_n_c_e_s:

     Alan Agresti (1990). _Categorical data analysis_. New York: Wiley.
     Pages 59-66.

     Fisher, R. A. (1935). The logic of inductive inference. _Journal
     of the Royal Statistical Society Series A_ *98*, 39-54.

     Fisher, R. A. (1962). Confidence limits for a cross-product ratio.
     _Australian Journal of Statistics_ *4*, 41.

     Cyrus R. Mehta & Nitin R. Patel (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.

     Douglas B. Clarkson, Yuan-an Fan & Harry Joe (1993). A Remark on
     Algorithm 643: FEXACT: An Algorithm for Performing Fisher's Exact
     Test in r x c Contingency Tables. _ACM Transactions on
     Mathematical Software_, *19*, 484-488.

_S_e_e _A_l_s_o:

     'chisq.test'

_E_x_a_m_p_l_e_s:

     ## Agresti (1990), p. 61f, Fisher's Tea Drinker
     ## A British woman claimed to be able to distinguish whether milk or
     ##  tea was added to the cup first.  To test, she was given 8 cups of
     ##  tea, in four of which milk was added first.  The null hypothesis
     ##  is that there is no association between the true order of pouring
     ##  and the women's guess, the alternative that there is a positive
     ##  association (that the odds ratio is greater than 1).
     TeaTasting <-
     matrix(c(3, 1, 1, 3),
            nr = 2,
            dimnames = list(Guess = c("Milk", "Tea"),
                            Truth = c("Milk", "Tea")))
     fisher.test(TeaTasting, alternative = "greater")
     ## => p=0.2429, association could not be established

     ## Fisher (1962), Convictions of like-sex twins in criminals
     Convictions <-
     matrix(c(2, 10, 15, 3),
            nr = 2,
            dimnames =
            list(c("Dizygotic", "Monozygotic"),
                 c("Convicted", "Not convicted")))
     Convictions
     fisher.test(Convictions, alternative = "less")
     fisher.test(Convictions, conf.int = FALSE)
     fisher.test(Convictions, conf.level = 0.95)$conf.int
     fisher.test(Convictions, conf.level = 0.99)$conf.int

