Contrasts                package:car                R Documentation

_F_u_n_c_t_i_o_n_s _t_o _C_o_n_s_t_r_u_c_t _C_o_n_t_r_a_s_t_s

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

     These are substitutes for similarly named functions in the base
     package  (note the uppercase letter starting the second word in
     each function name). The only difference is that the contrast
     functions from the car package produce easier-to-read names for
     the contrasts when they are used in statistical models. 

     The functions and this documentation are adapted from the base
     package.

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

     contr.Treatment(n, base = 1, contrasts = TRUE)

     contr.Sum(n, contrasts = TRUE)

     contr.Helmert(n, contrasts = TRUE)

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

       n: a vector of levels for a factor, or the number of levels.

    base: an integer specifying which level is considered the baseline
          level.  Ignored if 'contrasts' is 'FALSE'.

contrasts: a logical indicating whether contrasts should be computed.

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

     These functions are used for creating contrast matrices for use in
     fitting analysis of variance and regression models.  The columns
     of the resulting matrices contain contrasts which can be used for
     coding a factor with 'n' levels.  The returned value contains the
     computed contrasts. If the argument 'contrasts' is 'FALSE' then a
     square matrix is returned.

     Several aspects of these contrast functions are controlled by
     options set via the 'options' command:

     '_d_e_c_o_r_a_t_e._c_o_n_t_r_a_s_t_s' This option should be set to a 2-element
          character vector containing the prefix and suffix characters
          to surround contrast names. If the option is not set, then
          'c("[", "]")' is used. For example, setting
          'options(decorate.contrasts=c(".", ""))' produces contrast
          names that are separated from factor names by a period.
          Setting 'options(decorate.contrasts=c("", ""))' reproduces
          the behaviour of the R base contrast functions. 

     '_d_e_c_o_r_a_t_e._c_o_n_t_r._T_r_e_a_t_m_e_n_t' A character string to be appended to
          contrast names to signify treatment contrasts; if the option
          is unset, then '"T."' is used.

     '_d_e_c_o_r_a_t_e._c_o_n_t_r._S_u_m' Similar to the above, with default '"S."'.

     '_d_e_c_o_r_a_t_e._c_o_n_t_r._H_e_l_m_e_r_t' Similar to the above, with default
          '"H."'. 

     '_c_o_n_t_r._S_u_m._s_h_o_w._l_e_v_e_l_s' Logical value: if 'TRUE' (the default if
          unset),  then level names are used for contrasts; if 'FALSE',
          then numbers are used, as in 'contr.sum' in the 'base'
          package. 

     Note that there is no replacement for 'contr.poly' in the 'base'
     package (which produces  orthogonal-polynomial contrasts) since
     this function already constructs easy-to-read contrast names.

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

     A matrix with 'n' rows and 'k' columns, with 'k = n - 1' if
     'contrasts' is 'TRUE'  and 'k = n' if 'contrasts' is 'FALSE'.

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

     John Fox jfox@mcmaster.ca

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

     'contr.treatment', 'contr.sum',  'contr.helmert', 'contr.poly'

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

     # contr.Treatment vs. contr.treatment in the base package:

     data(Prestige)
     lm(prestige ~ (income + education)*type, data=Prestige, 
         contrasts=list(type="contr.Treatment"))

     ##  Call:
     ##  lm(formula = prestige ~ (income + education) * type, data = Prestige,
     ##      contrasts = list(type = "contr.Treatment"))
     ##  
     ##  Coefficients:
     ##          (Intercept)                  income               education  
     ##              2.275753                0.003522                1.713275  
     ##          type[T.prof]              type[T.wc]     income:type[T.prof]  
     ##              15.351896              -33.536652               -0.002903  
     ##      income:type[T.wc]  education:type[T.prof]    education:type[T.wc]  
     ##              -0.002072                1.387809                4.290875  

     lm(prestige ~ (income + education)*type, data=Prestige, 
         contrasts=list(type="contr.treatment"))    

     ##  Call:
     ##  lm(formula = prestige ~ (income + education) * type, data = Prestige,
     ##      contrasts = list(type = "contr.treatment"))
     ##  
     ##  Coefficients:
     ##      (Intercept)              income           education  
     ##          2.275753            0.003522            1.713275  
     ##          typeprof              typewc     income:typeprof  
     ##          15.351896          -33.536652           -0.002903  
     ##      income:typewc  education:typeprof    education:typewc  
     ##          -0.002072            1.387809            4.290875      

