library(MASS)
head(dta <- cats)
## Sex Bwt Hwt
## 1 F 2.0 7.0
## 2 F 2.0 7.4
## 3 F 2.0 9.5
## 4 F 2.1 7.2
## 5 F 2.1 7.3
## 6 F 2.1 7.6
coef(lm(Bwt~Sex,data=cats))
## (Intercept) SexM
## 2.3595745 0.5404255
coef(lm(Bwt ~ Sex, data = cats, contrasts = list(Sex = "contr.sum")))
## (Intercept) Sex1
## 2.6297872 -0.2702128
前者為dummy coding虛擬變數,為參照組(sex=F)的截距之平均=2.3595745,而迴歸係數為操弄組(SexM)之平均減截距=0.5404255。後者是以effect coding的方法,截距為未加權總平均數,迴歸係數為截距減去操弄組(SexM)的細格平均數。