Factor with Chosen Contrasts

DESCRIPTION:

Returns a factor or a bdFactor with a contrasts attribute.

USAGE:

C(object, contr, how.many) 

REQUIRED ARGUMENTS:

object
a factor, a bdFactor, or an ordered factor.

OPTIONAL ARGUMENTS:

contr
what contrasts to use. May be one of four standard names ( helmert, poly, treatment, or sum), a function, or a matrix with as many rows as there are levels to the factor or bdFactor. The standard names must not be quoted. The default is the first element of the contrasts option for factors or bdFactors, and the second element of the option for ordered factors.
how.many
the number of contrasts to be assigned to the factor or bdFactor. The default is k-1, where k is the number of levels.

VALUE:

a factor or bdFactor, with the contrasts attribute set as above.

DETAILS:

This may be used in a model formula or to create a new factor or bdFactor.
Note that setting how.many to be less than k-1 in a model formula is an assertion that the coefficients for the remaining factors or bdFactors are either known to be negligible or else should be aliased with other coefficients. The wafer example below is an example of aliasing the remaining contrasts.

SEE ALSO:

, , , , .

EXAMPLES:

# Use treatment contrasts for factor Cat:
aov(Yield ~ Conc * C(Cat, treatment), catalyst) 
# Only fit linear and quadratic effects:
aov(Defects ~ C(Reliability, poly, 2) * Type * Plant) 

# Partition spinsp into linear effect (the term with C) and 
#   the higher order contrasts (the term with spinsp).
#   note that the order of the terms is important 
aov(pre.mean ~ C(spinsp, poly, 1) + spinsp, data=wafer)