model.matrix.multiple         package:Zelig         R Documentation

_D_e_s_i_g_n _m_a_t_r_i_x _f_o_r _m_u_l_t_i_v_a_r_i_a_t_e _m_o_d_e_l_s

_D_e_s_c_r_i_p_t_i_o_n:

     Use 'model.matrix.multiple' after 'parse.formula' to create a
     design matrix for multiple-equation models.

_U_s_a_g_e:

     model.matrix.multiple(object, data, shape = "compact", eqn = NULL, ...)

_A_r_g_u_m_e_n_t_s:

  object: the list of formulas output from 'parse.formula'

    data: a data frame created with 'model.frame.multiple'

   shape: a character string specifying the shape of the outputed
          matrix.  Available options are 

        "_c_o_m_p_a_c_t" (default) the output matrix will be an n x v, where v
             is the number of unique variables in all of the equations
             (including the intercept term)

        "_a_r_r_a_y" the output is an n x K x J array where J is the total
             number of equations and K is the total number of
             parameters across all the equations.  If a variable is not
             in a certain equation, it is observed as a vector of 0s.

        "_s_t_a_c_k_e_d" the output will be a 2n x K matrix where K is the
             total number of  parameters across all the equations.

     eqn: a character string or a vector of character strings
          identifying the equations from which to  construct the design
          matrix. The defaults to 'NULL', which only uses the
          systematic parameters (for which 'DepVar = TRUE' in the
          appropriate 'describe.model' function)

     ...: additional arguments passed to 'model.matrix.default'

_V_a_l_u_e:

     A design matrix or array, depending on the options chosen in
     'shape', with appropriate terms  attributes.

_A_u_t_h_o_r(_s):

     Kosuke Imai <kimai@princeton.edu>; Gary King <king@harvard.edu>;
     Olivia Lau <olau@fas.harvard.edu>; Ferdinand Alimadhi
     <falimadhi@iq.harvard.edu>

_S_e_e _A_l_s_o:

     'parse.par', 'parse.formula' and the full Zelig manual at <URL:
     http://gking.harvard.edu/zelig>

_E_x_a_m_p_l_e_s:

     # Let's say that the name of the model is "bivariate.probit", and
     # the corresponding describe function is describe.bivariate.probit(),
     # which identifies mu1 and mu2 as systematic components, and an
     # ancillary parameter rho, which may be parameterized, but is estimated
     # as a scalar by default.  Let par be the parameter vector (including
     # parameters for rho), formulae a user-specified formula, and mydata
     # the user specified data frame.

     # Acceptable combinations of parse.par() and model.matrix() are as follows:
     ## Setting up
     ## Not run:  
     data(sanction)
     formulae <- cbind(import, export) ~ coop + cost + target
     fml <- parse.formula(formulae, model = "bivariate.probit")
     D <- model.frame(fml, data = sanction)
     terms <- attr(D, "terms")

     ## Intuitive option
     Beta <- parse.par(par, terms, shape = "vector", eqn = c("mu1", "mu2"))
     X <- model.matrix(fml, data = D, shape = "stacked", eqn = c("mu1", "mu2")  
     eta <- X 

     ## Memory-efficient (compact) option (default)
     Beta <- parse.par(par, terms, eqn = c("mu1", "mu2"))
     X <- model.matrix(fml, data = D, eqn = c("mu1", "mu2"))   
     eta <- X 

     ## Computationally-efficient (array) option
     Beta <- parse.par(par, terms, shape = "vector", eqn = c("mu1", "mu2"))
     X <- model.matrix(fml, data = D, shape = "array", eqn = c("mu1", "mu2"))
     eta <- apply(X, 3, '
     ## End(Not run)

