contrast                package:base                R Documentation

_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:

     Return a matrix of contrasts.

_U_s_a_g_e:

     contr.helmert(n, contrasts = TRUE)
     contr.poly(n, contrasts = TRUE)
     contr.sum(n, contrasts = TRUE)
     contr.treatment(n, base = 1, contrasts = TRUE)

_A_r_g_u_m_e_n_t_s:

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

contrasts: a logical indicating whether contrasts should be computed.

    base: an integer specifying which group is considered the baseline
          group.

_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
     an additional column of ones is prepended to the matrix.

     Note that as from R version 0.62.2, `contr.poly' returns contrasts
     based on orthogonal (rather than raw) polynomials.

_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'.

_S_e_e _A_l_s_o:

     `contrasts', `C', and `aov', `glm', `lm'.

_E_x_a_m_p_l_e_s:

     (cH <- contr.helmert(4))
     apply(cH, 2,sum)# column sums are 0!
     crossprod(cH)# diagonal -- columns are orthogonal

     (cT <- contr.treatment(5))
     all(crossprod(cT) == diag(4))# TRUE: even orthonormal

     (cP <- contr.poly(3))# Linear and Quadratic
     zapsmall(crossprod(cP), dig=15) # orthonormal up to fuzz

