The only mandatory argument is model
, which may include any number of factor or numeric predictors, and one offset. The simplest usage of this method, where no other argument is defined, calculates the adjusted mean of the model response variable, pooling over all the levels of factor predictors, and setting the numeric predictors (covariates and offset, ifany) to their average values in the model data frame.
The calculations will be done for the linear combinations of factor levels defined by levels
. This argument must be a list, with one element for each factor of the model that has to be manipulated (including factors of the intra-subjects design, if suitable). The factors that are not represented in this list will be pooled over, and elements that do not correspond to any factor of the model will be ignored with a warning. levels
may be a named list, where the name of each element identifies the represented factor, and its contents may be one of the following:
A character string of length 1 or 2, with the name of one or two factor levels. In the former case, the calculations will be restricted to this level of the factor, as in a simple main effects analysis; in the latter, a pairwise contrast will be calculated between both factor levels.
A numeric vector without names, as long as the number of levels in the factor. This will create a linear combination of factor levels, with the elements of the vector as coefficients. For instance, if the factor f
has three levels, an element f=c(0.5, 0.5, 0)
will average the two first levels, and f=c(0.5, 0.5, -1)
will contrast the average of the two first levels against the third one.
A numeric vector with names equal to some or all the levels of the factor. This is a simplification of the previous option, where some levels can be omitted, and the coefficient of each level is determined by the names of the vector, which do not have to follow a specific order. Omitted levels will automatically be set to zero.
A numeric matrix, as an extension of the two previous options for calculating several combinations at a time. Combinations are defined in columns, so if the matrix does not have row names, the number of rows must be equal to the number of levels in the factor, or if the matrix does have row names, they must coincide with the levels of the factor.
Alternatively, levels
may be a single formula or an unnamed list of formulas, of the type factorname ~ K1*level1 + K2*level2 ...
(see contrastCoefficients
for further details). Both types of lists (named list of string or numeric vectors and matrices, and unnamed lists of formulas) may be mixed.
The argument covariates
may be used for setting specific values of the model numeric predictors (covariates). It must be a vector of numeric values. If the elements of this vector have names, their values will be assigned to the covariates that match them; covariates of the model with names not represented in this vector will be set to their default value (the average in the model data frame), and elements with names that do not match with covariates will be ignored. On the other hand, if covariates
has no names, and its length is equal to the number of covariates of the model, the values will be assigned to those covariates in the same order as they occur in the model. If it has a different length, the vector will be trimmed or reclycled as needed to fit the number of covariates in the model; this feature may be used, for instance, to set all covariates to the same value, e.g. covariates = 0
. The argument offset
can likewise be used to define a specific value for the offset of the model.
To analyse terms other than the adjusted mean value of the response, use the argument terms.formula
. For instance, if the model has the covariates var1
, var2
, ..., the slopes of the response with respect to them may be added to the analysis by defining terms.formula
as ~var1 + var2 ...
. This formula may be used more generally, for analysing interactions, omitting the mean response, adding the main effects of factors, etc. A different analysis is done for each term of this formula, that must also be contained in the formula of model
. For instance, if terms.formula
is equal to ~ var1*var2
, the function will analyse the adjusted intercept, plus the terms var1
, var2
, and var1:var2
. The intercept stands for the mean value of the response, and terms formed by one or more covariates stand por the slope of the response with respect to the product of those covariates.
If any of the variables in the term is a factor, the function analyses a full set of contrasts for that factor of the remaining part of the term; for instance if var1
were a factor, the term var1
would stand for the contrasts of the intercept, and var1:var2
would stand for the contrasts of the slope var2
, across the levels of var1
. The set of contrasts used in the analysis is normally defined by the argument default.contrasts
: by default, if the factor is ordered it will be a set of “polynomial contrasts”, and otherwise “sum contrasts”; however, if inherit.contrasts
is TRUE
the contrasts will directly be copied from the ones used to define the model. Factors that have explicit contrasts defined in the model data frame will use those contrasts, regardless of the values defined for default.contrasts
and inherit.contrasts
. The analysis assumes that the contrasts are orthogonal to the intercept, which is the usual case if the default arguments are provided, and a warning will be issued if non-orthogonal contrasts are used; take special care of not using “treatment contrats” if inherit.contrasts
is set to TRUE
or default.contrasts
is changed.
In generalized linear models, the adjusted means represent the expected values of the response by default, but the expected value of the link function may be shown by setting the argument link=FALSE
. On the other hand, slope values and standard errors always refer to the link function.
For multivariate models, the arguments idata
, and icontrasts
may be used to define an intra-subjects model for multivariate repeated-measures data, as described for Anova
or linearHypothesis
in package car. Note, however, that the combinations of intra-subjects factor levels are defined in levels
, and other arguments defined in those functions like idesign
, imatrix
or iterms
will have no effect in testFactors
.
The significance of adjusted values is tested by a call to linearHypothesis
for each term, unless lht
is set to FALSE
. Extra arguments may be passed down to that function, for instance to specify the test statistic that will be evaluated.