Next: convolve() Up: MacAnova Help File Previous: console()   Contents

contrast()

Usage:
contrast(Term,Coefs [,Byvar] [,errorTerm:ErrorTerm] [,silent:T]), Term a
  factor in the most recent GLM model or a character SCALAR or positive
  integer specifying a term and ErrorTerm a CHARACTER scalar or positive
  integer, Coefs REAL, Byvar a factor in the most recent GLM or a
  CHARACTER scalar specifying such a factor



Keywords: glm, anova, comparisons
contrast(Term,Coefs) computes the estimated value, sum of squares, and
standard error for the contrast in the levels of the term specified by
Term.  The term specified must be made up exclusively of factor
variables in the model used by the most recent GLM (generalized linear
or linear model) command such as anova() or poisson().

Term is usually a CHARACTER scalar or quoted string such as "a" or
"b.c".  When the term contains just one factor, you can use just the
unquoted factor name.  Instead of a name, Term can be an integer between
1 and the number of terms in the model, counting CONSTANT if it is in
the model.  For example, after anova("a+b+a.b"), contrast(b,Coefs),
contrast("b",Coefs) and contrast(3,Coefs) are equivalent.

When any of the variables in the model are of the form {expr}, where
expr is a MacAnova expression, you must specify the variable in Term in
the same way or by number.  See topic 'models'.

The result is a structure with components 'estimate', 'ss', and 'se'.
For example, when factor a in a model has 5 levels, contrast("a",
vector(2,2,2,-3,-3)/6) compares the average effect of the first 3 levels
of factor a with the average effect of the last 2.

When Term contains more than one factor (for example "a.b"), Coefs must
be an array with dimensions matching the number of levels in the factors
of Term.  The contrast coefficients must sum to zero, but MacAnova does
not check to see if the contrast lies in any particular subspace.

You can use outer() to create multidimensional contrast coefficients
that are products of one dimensional contrasts.  For example, if factors
a and b have 2 and 3 levels, respectively, after anova("y = a*b"),

  Cmd> contrast("a.b", outer(vector(1,-1), vector(2,-1,-1)))

compute results for a product contrast that forms part of the a.b sum
of squares.  See outer().

contrast(Term,Coefs,Byvar) computes the contrast, sum of squares, and
standard error separately for each level of the factor variable (the
"byvariable") given in the CHARACTER or quoted string variable Byvar.

For example, after anova("y=a*b"), where a has three levels,
contrast("a",vector(-1,0,1),b) computes the indicated contrast for each
level of b.  Byvar can be specified by a quoted name but not by a
positive integer.

contrast(Term, Coefs [,Byvar], errorterm:ErrTerm) does the same except
the mean square error used in computing standard errors comes from the
term specified by ErrTerm.  ErrTerm can either be a positive integer
specifying a term number, or a CHARACTER scalar or quoted string
containing the name of a term in the model ("a.b.c", for example).

contrast(Term, Coefs, [,Byvar] [, errorterm:ErrTerm], silent:T) does the
same, except that certain warning or advisory messages are suppressed.
The default value of 'silent' is False unless the value of option'
'warnings' is False.

Function contrast() does not work after screen() or after any GLM
command with 'coefs:F' as an argument.

For unbalanced models, contrasts are computed as follows.

No byvariable:
  When Term corresponds to a term in the current anova model, the sum of
  squares is that for removal of the contrast degree of freedom from the
  complete model.  It is actually computed as a linear combination of
  the non-aliased coefficients associated with the term.

  When Term is not present in the model, the sum of squares is the
  incremental sum of squares obtained when adding the contrast df to the
  complete model, that is, the contrast is adjusted for all terms in the
  model.

Byvariable specified:
  The contrast is unadjusted for any other terms in the model, that is,
  it is computed as if the contrast degree of freedom at that level of
  the byvariable is the only degree of freedom in the model).

In all three cases, the MSE used in computing the standard error is the
error mean square (or other mean square as specified by 'errorterm')
from the most recent GLM command.

After logistic(), probit(), poisson(), and other GLMs fit iteratively by
glmfit() (but not robust()), contrast() computes the estimated value and
the deviance associated with the contrast based on full model weights.
Key word 'byvar' may not be used, but deviances are otherwise computed
as after anova().  Standard errors are computed using a scale parameter
of 1, or the value specified by keyword 'scale' on the GLM command.
Instead of 'ss', the second component of the result has name 'deviance'.

After robust(), the contrast value is computed based on coefficients
from the full model.  The "ss" computed is the square of the ratio of
the estimated contrast to its estimated standard error multiplied by the
error mean square.  Keyword 'byvar' cannot be used.

Contrast() does not work following fastanova(), ipf(), or screen() or
after a GLM command with coefs:F.

Example:
  Cmd> anova("y=a+b+a.b")
  Cmd> contrast("b",vector(-1,1,0)) # assumes b has 3 levels
  Cmd> contrast("b",vector(-1,1,0),"a") # a is byvariable
  Cmd> contrast("a.b",matrix(vector(-1,1,0,0,1,-1),2))# assumes 2 by 3

See also coefs(), secoefs(), modelinfo(), popmodel(), pushmodel()


Gary Oehlert 2003-01-15