

   C {base}                                     R Documentation

   SSeettss CCoonnttrraassttss ffoorr aa FFaaccttoorr

   DDeessccrriippttiioonn::

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

   UUssaaggee::

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

   AArrgguummeenntts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Deettaaiillss::

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

   VVaalluuee::

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

   AAuutthhoorr((ss))::

        B.D. Ripley

   SSeeee AAllssoo::

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

   EExxaammppllees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)

