C                   package:stats                   R Documentation

_S_e_t_s _C_o_n_t_r_a_s_t_s _f_o_r _a _F_a_c_t_o_r

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

     Sets the '"contrasts"' attribute for the factor.

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

     C(object, contr, how.many, ...)

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

  object: a factor or ordered factor

   contr: which contrasts to use. Can be a matrix with one row for each
          level of the factor or a suitable function like 'contr.poly'
          or a character string giving the name of the function

how.many: the number of contrasts to set, by default one less than
          'nlevels(object)'.

     ...: additional arguments for the function 'contr'.

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

     For compatibility with S, 'contr' can be 'treatment', 'helmert',
     'sum' or 'poly' (without quotes) as shorthand for
     'contr.treatment' and so on.

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

     The factor 'object' with the '"contrasts"' attribute set.

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

     Chambers, J. M. and Hastie, T. J. (1992) _Statistical models._
     Chapter 2 of _Statistical Models in S_ eds J. M. Chambers and T.
     J. Hastie, Wadsworth & Brooks/Cole.

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

     'contrasts', 'contr.sum', etc.

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

     ## reset contrasts to defaults
     options(contrasts=c("contr.treatment", "contr.poly"))
     data(warpbreaks)
     attach(warpbreaks)
     tens <- C(tension, poly, 1)
     attributes(tens)
     detach()
     ## tension SHOULD be an ordered factor, but as it is not we can use
     aov(breaks ~ wool + tens + tension, data=warpbreaks)

     ## show the use of ...  The default contrast is contr.treatment here
     summary(lm(breaks ~ wool + C(tension, base=2), data=warpbreaks))

     data(esoph) # following on from help(esoph)
     model3 <- glm(cbind(ncases, ncontrols) ~ agegp + C(tobgp, , 1) +
          C(alcgp, , 1), data = esoph, family = binomial())
     summary(model3)

