contrasts                package:base                R Documentation

_G_e_t _a_n_d _S_e_t _C_o_n_t_r_a_s_t _M_a_t_r_i_c_e_s

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

     Set and view the contrasts associated with a factor.

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

     contrasts(x, contrasts = TRUE)
     contrasts(x, how.many) <- ctr

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

       x: a factor.

contrasts: logical. See Details.

how.many: How many contrasts should be made. Defaults to one less than
          the number of levels of `x'.  This need not be the same as
          the number of columns of `ctr'.

     ctr: either a matrix whose columns give coefficients for contrasts
          in the levels of `x', or the (quoted) name of a function
          which computes such matrices.

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

     If contrasts are not set for a factor the default functions from
     `options("contrasts")' are used.

     The argument `contrasts' is ignored if `x' has a matrix
     `contrasts' attribute set.  Otherwise it is passed to a contrasts
     function such as `contr.treatment'.  Those functions normally
     return a complete indicator matrix if `contrasts = FALSE' and the
     actual contrasts matrix if `contrasts = TRUE'.

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

     `C', `contr.helmert', `contr.poly', `contr.sum',
     `contr.treatment'; `glm', `aov', `lm'.

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

     example(factor)
     (fff <- factor(ff))
     contrasts(fff) # treatment contrasts by default
     contrasts(C(fff, sum))
     contrasts(fff, contrasts = FALSE) # the 5x5 identity matrix

     contrasts(fff) <- contr.sum(5); contrasts(fff)  # set sum contrasts
     contrasts(fff, 2) <- contr.sum(5); contrasts(fff)  # set 2 contrasts
     # supply 2 contrasts, compute 2 more to make full set of 4.
     contrasts(fff) <- contr.sum(5)[,1:2]; contrasts(fff) 

