contrast.lm             package:contrast             R Documentation

_G_e_n_e_r_a_l _C_o_n_t_r_a_s_t_s _o_f _R_e_g_r_e_s_s_i_o_n _C_o_e_f_f_i_c_i_e_n_t_s

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

     This function computes one or more contrasts of the estimated
     regression coefficients in a fit from one of the functions in
     Design, along with standard errors, confidence limits, t or Z
     statistics, P-values.

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

     contrast(fit, ...)
     ## S3 method for class 'lm':
     contrast(fit, ...)
     ## S3 method for class 'gls':
     contrast(fit, ...)
     ## S3 method for class 'lme':
     contrast(fit, ...)
     ## S3 method for class 'geese':
     contrast(fit, ...)

     ## S3 method for class 'contrast':
     print(x, X=FALSE, fun=function(u)u, ...)

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

     fit: a fit of class '"lm"', '"glm"', etc. 

     ...: arguments to pass to the computational code. The arguments
          are listed in the Details section below.

       x: result of 'contrast'

       X: set 'X=TRUE' to  print design matrix used in computing the
          contrasts (or the average contrast) 

     fun: a function to transform the contrast, SE, and lower and upper
          confidence limits before printing.  For example, specify
          'fun=exp' to anti-log them for logistic models. 

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

     These functions mirror 'contrast.Design'. 

     There are some between-package inconsistencies regarding degrees
     of freedom in some models. See the package vignette for more
     details.

     Fold changes are calculated for each hypothesis. When 'fcType =
     "simple"', the ratio of the 'a' group predictions over the 'b'
     group predictions are used. When 'fcType = "signed"', the ratio is
     used if it is greater than 1; otherwise the negative inverse
     (e.g., '-1/ratio') is returned.

     Arguments to the contast functions are: *'a'*:  a list containing
     settings for all predictors that you do not wish to set to default
     (adjust-to) values.  Usually you will specify two variables in
     this list, one set to a constant and one to a sequence of values,
     to obtain contrasts for the sequence of values of an interacting
     factor.  The 'gendata' function will generate the necessary
     combinations and default values for unspecified predictors.

     *'a'*: another list that generates the same number of observations
     as 'a', unless one of the two lists generates only one
     observation.  In that case, the design matrix generated from the
     shorter list will have its rows replicated so that the contrasts
     assess several differences against the one set of predictor
     values.  This is useful for comparing multiple treatments with
     control, for example.  If 'b' is missing, the design matrix
     generated from 'a' is analyzed alone.

     *'covType'*:  a string matching the method for estimating the
     covariance matrix. The default value produces the typical
     estimate. See 'vcovHC' for options.

     *'cnames'*:  vector of character strings naming the contrasts when
     'type="individual"'.  Usually 'cnames' is not necessary as
     'contrast.Design' tries to name the contrasts by examining which
     predictors are varying consistently in the two lists.  'cnames'
     will be needed when you contrast "non-comparable" settings, e.g.,
     you compare 'list(treat="drug", age=c(20,30))' with
     'list(treat="placebo"), age=c(40,50)'

     *'type'*:  set 'type="average"' to average the individual
     contrasts (e.g., to obtain a Type II or III contrast)

     *'weights'*:  a numeric vector, used when 'type="average"', to
     obtain weighted contrasts

     *'conf.int'*: confidence level for confidence intervals for the
     contrasts

     *'env'*: environment in which evaluate fit

     *'fcFun'*: a function to transform the numerator and denominator
     of fold changes

     *'fcType'*:  a character string: "simple", "log" or "signed"

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

     a list of class '"contrast.Design"' containing the elements
     'Contrast', 'SE', 'Z', 'var', 'df.residual' 'Lower', 'Upper',
     'Pvalue', 'X', 'cnames', which denote the contrast estimates,
     standard errors, Z or t-statistics, variance matrix, residual
     degrees of freedom (this is 'NULL' if the model was not 'ols'),
     lower and upper confidence limits, 2-sided P-value, design matrix,
     and contrast names (or 'NULL').

     Also, an element called 'foldChange'.

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

     'contrast.Design', 'vcovHC'

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

     library(nlme)
     Orthodont2 <- Orthodont
     Orthodont2$newAge <- Orthodont$age - 11
     fm1Orth.lme2 <- lme(distance ~ Sex*newAge, data = Orthodont2, random = ~ newAge | Subject)
     summary(fm1Orth.lme2)

     contrast(
        fm1Orth.lme2,
        a = list(Sex = levels(Orthodont2$Sex), newAge = 8 - 11),
        b = list(Sex = levels(Orthodont2$Sex), newAge = 10 - 11))

