MarginalMatrix              package:cmm              R Documentation

_M_a_r_g_i_n_a_l_M_a_t_r_i_x

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

     Returns marginal matrix; i.e., matrix required to obtained
     marginal frequencies

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

     MarginalMatrix(var, marg, dim, SubsetCoding="Identity")

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

     var: character or numeric vector containing variables

    marg: list of character or numeric indicating marginals

     dim: numeric vector indicating the dimension of 'var'

SubsetCoding: allows a (character) type or a matrix to be assigned to
          variables for each element of 'suffconfigs', see examples and
          'DesignMatrix'

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

     Gives the matrix which, multiplied by a probability vector, gives
     the marginal probabilities. The probability vector is assumed to
     be a vectorized form of the probabilities in a table, such that
     the last variable changes value fastest, then the before last
     variable, etc. For example, the cells of a 2 x 3 table are
     arranged in vector form as (11,12,13,21,22,23). To achieve this,
     the appropriate way to vectorize a data frame 'dat' is using
     'c(t(ftable(dat)))'.

     Special case of transposed 'DesignMatrix':


      MarginalMatrix <- function(var,marg,dim,SubsetCoding="Identity")

     t(DesignMatrix(var,marg,dim,SubsetCoding=SubsetCoding,MakeSubsets=FALSE))

     Allows weighted sums of probabilities using 'SubsetCoding'

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

     matrix

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

     W. P. Bergsma w.p.bergsma@lse.ac.uk

_R_e_f_e_r_e_n_c_e_s:

     Bergsma, W. P. (1997). _Marginal models for categorical data_.
     Tilburg, The Netherlands: Tilburg University Press. <URL:
     http://stats.lse.ac.uk/bergsma/pdf/bergsma_phdthesis.pdf>

     Bergsma, W. P., Croon, M. A., & Hagenaars, J. A. P. (2009).
     Marginal models for dependent, clustered, and longitudunal
     categorical data. Berlin: Springer.

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

     'ConstraintMatrix', 'DesignMatrix', 'DirectSum'

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

     # Computing marginal frequencies
     n <- c(1:6)  #example list of frequencies
     var <- c("A","B")
     marg <- list(c("A"),c("B"))
     dim <- c(2,3)
     at <- MarginalMatrix(var,marg,dim)
     # list of marginal frequencies:
     at 

     # identitymatrix: several ways of specifying:
     marg <- c("A","B")
     MarginalMatrix(var,marg,dim)
     MarginalMatrix(var,marg,dim,SubsetCoding=list(c("A","B"),list("Identity","Identity")))
     MarginalMatrix(var,marg,dim,SubsetCoding=list(c("A","B"),list(rbind(c(1,0),c(0,1)),rbind(c(1,0,0),c(0,1,0),c(0,0,1)))))

     # omit second category of first variable
     at <- MarginalMatrix(var,marg,dim,SubsetCoding=list(c("A","B"),list(rbind(c(1,0)),"Identity")))
     at 

