bCrosstab               package:Matrix               R Documentation

_C_r_e_a_t_e _p_a_i_r_w_i_s_e _c_r_o_s_s_t_a_b_u_l_a_t_i_o_n

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

     Create the pairwise crosstabulation of two or more factors.

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

     bCrosstab(flist, reorder = TRUE)

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

   flist: A list of two or more factors.  All factors must have the
          same length.

 reorder: Logical flag determining if reordering of the factors is
          allowed.

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

     A list with two components, 

 'flist': a possibly reordered copy of the first argument, and

  'ctab': 

     , itself a list of all pairwise crosstabulation matrices.  These
     include the (diagonal) matrices of "interactions of a factor with
     itself", see the example.

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

     ':' for factor interaction, 'xtabs' for another cross tabulation
     function.

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

     str(esoph)
     bCrosstab(with(esoph,list(agegp, alcgp))) $ ctab

     grps <- with(esoph, list(age = agegp, alc = alcgp, tob = tobgp))
     bCn <- bCrosstab( grps, reorder = FALSE)
     stopifnot(all.equal(bCn$flist, grps))
     str(bC <- bCrosstab(grps))
     bC$ctab$"alc:age" # generally 4 obs. per cell, but not always:
     aa.m <- as(bC$ctab$"alc:age", "matrix")
     table(aa.m) # #(2,3,4) = (2, 4, 18)
     stopifnot(all.equal(as.vector(t(aa.m)),
                         as.vector(table(with(esoph, alcgp:agegp))), tol=0))

