CrossTable              package:gmodels              R Documentation

_C_r_o_s_s _T_a_b_u_l_a_t_i_o_n _w_i_t_h _T_e_s_t_s _f_o_r _F_a_c_t_o_r _I_n_d_e_p_e_n_d_e_n_c_e

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

     An implementation of a cross-tabulation function with output
     similar to S-Plus crosstabs() and SAS Proc Freq (or SPSS format)
     with Chi-square, Fisher and McNemar tests of the independence of
     all table factors.

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

     CrossTable(x, y, digits=3, max.width = 5, expected=FALSE, prop.r=TRUE, prop.c=TRUE,
                prop.t=TRUE, prop.chisq=TRUE, chisq = FALSE, fisher=FALSE, mcnemar=FALSE,
                resid=FALSE, sresid=FALSE, asresid=FALSE,
                missing.include=FALSE,
     format=c("SAS","SPSS")),...

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

       x: A vector or a matrix. If y is specified, x must be a vector

       y: A vector in a matrix or a dataframe

  digits: Number of digits after the decimal point for cell proportions

max.width: In the case of a 1 x n table, the default will be to print
          the output horizontally. If the number of columns exceeds
          max.width, the table will be wrapped for each successive
          increment of max.width columns. If you want a single column
          vertical table, set max.width to 1

expected: If 'TRUE', chisq will be set to 'TRUE' and expected cell
          counts from the Chi-Square will be included

  prop.r: If 'TRUE', row proportions will be included

  prop.c: If 'TRUE', column proportions will be included

  prop.t: If 'TRUE', table proportions will be included

prop.chisq: If 'TRUE', chi-square contribution of each cell will be
          included

   chisq: If 'TRUE', the results of a chi-square test will be included

  fisher: If 'TRUE', the results of a Fisher Exact test will be
          included

 mcnemar: If 'TRUE', the results of a McNemar test will be included

   resid: If 'TRUE', residual (Pearson) will be included

  sresid: If 'TRUE',  standardized residual will be included

 asresid: If 'TRUE', adjusted standardized residual will be included

missing.include: If 'TRUE', then remove any unused factor levels

  format: Either SAS (default) or SPSS, depending on the type of output
          desired.

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

     A summary table will be generated with cell row, column and table
     proportions and marginal totals and proportions. Expected cell
     counts can be printed if desired (if 'chisq = TRUE'). In the case
     of a 2 x 2 table, both corrected and uncorrected values will be
     included for appropriate tests. In the case of tabulating a single
     vector, cell counts and table proportions will be printed.

     Note: If 'x' is a vector and 'y' is not specified, no statistical
     tests will be performed, even if any are set to 'TRUE'.

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

     A list with multiple components including key table data and
     statistical test results, where performed.

     t:            An n by m matrix containing table cell counts

     prop.col:     An n by m matrix containing cell column proportions

     prop.row:     An n by m matrix containing cell row proportions

     prop.tbl:     An n by m matrix containing cell table proportions

     chisq:        Results from the Chi-Square test. A list with class
     'htest'. See ?chisq.test for details

     chisq.corr:   Results from the corrected Chi-Square test. A list
     with class 'htest'. See ?chisq.test for details. ONLY included in
     the case of a 2 x 2 table.

     fisher.ts:    Results from the two-sided Fisher Exact test. A list
     with class 'htest'. See ?fisher.test for details. ONLY included if
     'fisher' = TRUE.

     fisher.lt:    Results from the Fisher Exact test with HA = "less".
     A list with class 'htest'. See ?fisher.test for details. ONLY
     included if 'fisher' = TRUE and in the case of a 2 x 2 table.

     fisher.gt:    Results from the Fisher Exact test with HA =
     "greater". A list with class 'htest'. See ?fisher.test for
     details. ONLY included if 'fisher' = TRUE and in the case of a 2 x
     2 table.

     mcnemar:      Results from the McNemar test. A list with class
     'htest'. See ?mcnemar.test for details. ONLY included if 'mcnemar'
     = TRUE.

     mcnemar.corr: Results from the corrected McNemar test. A list with
     class 'htest'. See ?mcnemar.test for details. ONLY included if
     'mcnemar' = TRUE and in the case of a 2 x 2 table.

     resid/sresid/asresid: Pearson Residuals (from chi-square tests).

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

     Marc Schwartz mschwartz@medanalytics.com. Original version posted
     to r-devel on Jul 27, 2002.

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

     'xtabs', 'table', 'prop.table'

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

     # Simple cross tabulation of education versus prior induced abortions
     # using infertility data
     data(infert, package = "datasets")
     CrossTable(infert$education, infert$induced, expected = TRUE)
     CrossTable(infert$education, infert$induced, expected = TRUE, format="SAS")
     CrossTable(infert$education, infert$induced, expected = TRUE, format="SPSS")

