coindep_test               package:vcd               R Documentation

_T_e_s_t _f_o_r (_C_o_n_d_i_t_i_o_n_a_l) _I_n_d_e_p_e_n_d_e_n_c_e

_D_e_s_c_r_i_p_t_i_o_n:

     Performs a test of (conditional) independence of 2 margins in a
     contingency table by simulation from the marginal distribution of
     the input table under (conditional) independence.

_U_s_a_g_e:

     coindep_test(x, margin = NULL, n = 1000, 
       indepfun = function(x) max(abs(x)), aggfun = max,
       alternative = c("greater", "less"),
       pearson = TRUE)

_A_r_g_u_m_e_n_t_s:

       x: a contingency table.

  margin: margin index(es) or corresponding name(s) of the conditioning
          variables. Each resulting conditional table has to be a 2-way
          table.

       n: number of (conditional) independence tables to be drawn.

indepfun: aggregation function capturing independence in (each
          conditional) 2-way table.

  aggfun: aggregation function aggregating the test statistics computed
          by 'indepfun'.

alternative: a character string specifying the alternative hypothesis;
          must be either '"greater"' (default) or '"less"' (and may be
          abbreviated.)

 pearson: logical. Should the table of Pearson residuals under
          independence be computed and passed to 'indepfun' (default)
          or the raw table of observed frequencies?

_D_e_t_a_i_l_s:

     If 'margin' is 'NULL' this computes a simple independence
     statistic in a 2-way table. Alternatively, 'margin' can give 
     several conditioning variables and then conditional independence
     in the resulting conditional table is tested.

     By default, this uses a (double) maximum statistic of Pearson
     residuals. By changing 'indepfun' or 'aggfun' a (maximum of)
     Pearson Chi-squared statistic(s) can be computed or just the usual
     Pearson Chi-squared statistics and so on. Other statistics can be
     computed by changing 'pearson' to 'FALSE'.

     The function uses 'r2dtable' to simulate the distribution of the
     test statistic under the null.

_V_a_l_u_e:

     A list of class '"coindep_test"' inheriting from '"htest"' with
     following components:  

statistic: the value of the test statistic.

 p.value: the p value for the test.

  method: a character string indicating the type of the test.

data.name: a character string giving the name(s) of the data.

observed: observed table of frequencies

  expctd: expected table of frequencies

residuals: corresponding Pearson residuals

  margin: the 'margin' used

    dist: a vector of size 'n' with simulated values of the
          distribution of the statistic under the null.

   qdist: the corresponding quantile function (for computing  critical
          values).

   pdist: the corresponding distribution function (for computing p
          values).

_A_u_t_h_o_r(_s):

     Achim Zeileis Achim.Zeileis@R-project.org

_S_e_e _A_l_s_o:

     'chisq.test', 'fisher.test', 'r2dtable'

_E_x_a_m_p_l_e_s:

     TeaTasting <- matrix(c(3, 1, 1, 3), nr = 2,
                          dimnames = list(Guess = c("Milk", "Tea"),
                                          Truth = c("Milk", "Tea"))
     )
     ## compute maximum statistic
     coindep_test(TeaTasting)
     ## compute Chi-squared statistic
     coindep_test(TeaTasting, indepfun = function(x) sum(x^2))
     ## use unconditional asymptotic distribution
     chisq.test(TeaTasting, correct = FALSE)
     chisq.test(TeaTasting)

     data(UCBAdmissions)
     ## double maximum statistic
     coindep_test(UCBAdmissions, margin = "Dept")
     ## maximum of Chi-squared statistics
     coindep_test(UCBAdmissions, margin = "Dept", indepfun = function(x) sum(x^2))
     ## Pearson Chi-squared statistic
     coindep_test(UCBAdmissions, margin = "Dept", indepfun = function(x) sum(x^2), aggfun = sum)
     ## use unconditional asymptotic distribution
     loglm(~ Dept * (Gender + Admit), data = UCBAdmissions)

