contr                 package:memisc                 R Documentation

_C_o_n_v_e_n_i_e_n_c_e _M_e_t_h_o_d_s _f_o_r _S_e_t_t_i_n_g _C_o_n_t_r_a_s_t_s

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

     This package provides modified versions of 'contr.treatment' and
     'contr.sum'. 'contr.sum' gains an optional 'base' argument, analog
     to the one of 'contr.treatment', furthermore, the 'base' argument
     may be the name of a factor level.

     'contr' returns a function that calls either 'contr.treatment',
     'contr.sum', etc., according to the value given to its first
     argument.

     The 'contrasts' method for '"item"' objects returns a contrast
     matrix or a function to produce a contrast matrix for the factor
     into which the item would be coerced via 'as.factor' or
     'as.ordered'. This matrix or function can be specified by using
     'contrasts(x)<-value'

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

     contr(type,...)
     contr.treatment(n, base=1,contrasts=TRUE)
     contr.sum(n,base=NULL,contrasts=TRUE)
     ## S4 method for signature 'item':
     contrasts(x,contrasts=TRUE)
     ## S4 replacement method for signature 'item':
     contrasts(x,how.many) <- value
     # These methods are defined implicitely by making 'contrasts' generic.
     ## S4 method for signature 'ANY':
     contrasts(x,contrasts=TRUE)
     ## S4 replacement method for signature 'ANY':
     contrasts(x,how.many) <- value

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

    type: a character vector, specifying the type of the contrasts.
          This argument should have a value such that, if e.g.
          'type="something"', then there is a function
          'contr.something' that produces a contrast matrix. 

     ...: further arguments, passed to 'contr.treatment', etc. 

       n: a number of factor levels or a vector of factor levels names,
          see e.g. 'contr.treatment'.

    base: a number of a factor level or the names of a factor level,
          which specifies the baseline category, see e.g.
          'contr.treatment' or NULL. 

contrasts: a logical value, see  'contrasts'

how.many: the number of contrasts to generate, see 'contrasts'

       x: a factor or an object of class "item"

   value: a matrix, a function or the name of a function

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

     'contr' returns a funtion that calls one of 'contr.treatment',
     'contr.sum,...'. 'contr.treatment' and 'contr.sum' return contrast
     matrices. 'contrasts(x)' returns the "contrasts" attribute of an
     object, which may be a function name, a function, a contrast
     matrix or NULL.

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

     ctr.t <- contr("treatment",base="c")
     ctr.t
     ctr.s <- contr("sum",base="c")
     ctr.h <- contr("helmert")
     ctr.t(letters[1:7])
     ctr.s(letters[1:7])
     ctr.h(letters[1:7])

     x <- factor(rep(letters[1:5],3))
     contrasts(x)
     x <- as.item(x)
     contrasts(x)
     contrasts(x) <- contr.sum(letters[1:5],base="c")
     contrasts(x)
     missing.values(x) <- 5
     contrasts(x)
     contrasts(as.factor(x))

     # Obviously setting missing values after specifying
     # contrast matrix breaks the contrasts.
     # Using the 'contr' function, however, prevents this:

     missing.values(x) <- NULL
     contrasts(x) <- contr("sum",base="c")
     contrasts(x)
     missing.values(x) <- 5
     contrasts(x)
     contrasts(as.factor(x))

