contr.Treatment(n, base = 1, contrasts = TRUE)
contr.Sum(n, contrasts = TRUE)
contr.Helmert(n, contrasts = TRUE)
contrasts
is FALSE
.n
rows and k
columns, with k = n - 1
if contrasts
is TRUE
and k = n
if contrasts
is FALSE
.n
levels.
The returned value contains the computed contrasts. If the argument contrasts
is FALSE
then a square matrix is returned.
Several aspects of these contrast functions are controlled by options set via the options
command:
[object Object],[object Object],[object Object],[object Object],[object Object]
Note that there is no replacement for contr.poly
in the base
package (which produces
orthogonal-polynomial contrasts) since this function already constructs easy-to-read contrast names.contr.treatment
, contr.sum
,
contr.helmert
, contr.poly
# contr.Treatment vs. contr.treatment in the base package:
data(Prestige)
lm(prestige ~ (income + education)*type, data=Prestige,
contrasts=list(type="contr.Treatment"))
## Call:
## lm(formula = prestige ~ (income + education) * type, data = Prestige,
## contrasts = list(type = "contr.Treatment"))
##
## Coefficients:
## (Intercept) income education
## 2.275753 0.003522 1.713275
## type[T.prof] type[T.wc] income:type[T.prof]
## 15.351896 -33.536652 -0.002903
## income:type[T.wc] education:type[T.prof] education:type[T.wc]
## -0.002072 1.387809 4.290875
lm(prestige ~ (income + education)*type, data=Prestige,
contrasts=list(type="contr.treatment"))
## Call:
## lm(formula = prestige ~ (income + education) * type, data = Prestige,
## contrasts = list(type = "contr.treatment"))
##
## Coefficients:
## (Intercept) income education
## 2.275753 0.003522 1.713275
## typeprof typewc income:typeprof
## 15.351896 -33.536652 -0.002903
## income:typewc education:typeprof education:typewc
## -0.002072 1.387809 4.290875
Run the code above in your browser using DataLab