ivar                   package:mra                   R Documentation

_E_x_p_a_n_d _I_n_d_i_v_i_d_u_a_l-_v_a_r_y_i_n_g _c_o_v_a_r_i_a_t_e_s _i_n _m_o_d_e_l_s

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

     Expands a vector of individual-varying values into a 2-d matrix 
     of the appropriate size for use in MRA model formulas.

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

     ivar(x, ns=attr(x,"ns"), drop.levels=1)

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

       x: The vector of individual varying values to expand.  This can
          be  a factor (see 'as.factor'). It is assumed that
          'length(x)' =  number of individuals.  If not, an error will
          occur in whatever routine  called this function (e.g.,
          'F.3d.model.matrix'). 

      ns: Number of sampling occasions. Default is to use the 'ns'
          attribute  of 'x'.  If 'ns' is not specifed or is not an
          attribute of 'x',  an error is thrown. 

drop.levels: A vector of integers specifying which levels of a factor 
          to drop.  Only applicable if 'x' is a factor.  By default,
          the  first level of all factors is dropped. 
          'drop.levels=length(levels(x))' does the SAS thing and drops
          the last level of a factor.  Specifying a vector  will drop
          all levels in the vector.  E.g., 'drop.levels=c(1,2,7)' drops
           the 1st, 2nd, and 7th levels of the factor, whatever they
          are.  First level  of a factor is first element of
          'levels(x)'.  Second level  of a factor is second element of
          'levels(x)', and so on.  Setting   'drop.levels' to 0, a
          negative number, or a number greater than the number  of
          levels will not drop any levels (this is so-called cell mean
          coding). 

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

     A 2-d matrix of size 'length(x)' x 'ns' suitable for passing to
     the  Fortran DLL of MRA for estimation.  Values within rows are
     contant, values  across rows vary according to 'x'. If 'x' is a
     factor, this matrix  contains 0-1 indicator functions necessary to
     fit the factor. 

     If 'x' is a factor, attributes of the returned matrix are 
     "levels" = levels of the factor and "contr" = contrasts used in
     the coding (always 'contr.treatment').  For other contrast coding
     of factors, make your own  2-d matrix with a call to the
     appropriate function (like 'contr.poly').

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

     Trent McDonald, WEST-INC, tmcdonald@west-inc.com

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

     'F.cjs.estim', 'tvar'

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

     nan <- 30
     ns <- 5
     age <- as.factor(sample( c("J","S1","S2","Adult"), size=nan, replace=TRUE ))
     attr(age,"ns") <- ns
     age.mat <- ivar(age, drop=4) # level S2 is the reference
     dim(age.mat) <- c(nan,ns,length(levels(age))-1)
     print(age.mat)  # each page is the 2-d matrix used in the fit.
     print(age.mat[1,,])

     age.mat <- ivar(age, drop=c(3,4))  # level S1 and S2 are combined and are the reference

