set.seed(4444) x = sample(7, 1e2, replace=T) cf = c(0,2,-2,3,1,-1,1.5) yrate= exp(2+cf[x]) y = rpois(1e2, yrate) > aggregate(y, list(x), mean) Group.1 x 1 1 8.272727 2 2 53.666667 3 3 1.363636 4 4 152.750000 5 5 18.875000 6 6 2.666667 7 7 35.400000 > summary(y) Min. 1st Qu. Median Mean 3rd Qu. Max. 0.0 3.0 22.5 33.7 46.5 186.0 > fram = cbind.data.frame(x=factor(x),y=y) round(rbind(cf, glm(y~x, data=fram, family=poisson)$coef),3) (Intercept) x2 x3 x4 x5 x6 x7 cf 0.000 2.00 -2.000 3.000 1.000 -1.000 1.500 2.113 1.87 -1.803 2.916 0.825 -1.132 1.454 > x2 = factor(x); contrasts(x2) = contr.sum(x2, contrasts=F) fram2 = cbind.data.frame(x2,y=y) tmp = glm(y~x, data=fram2, family=poisson) round(rbind(cf, glm(y~x, data=fram2, family=poisson)$coef),3) > contrasts(factor(1:7)) 2 3 4 5 6 7 1 0 0 0 0 0 0 2 1 0 0 0 0 0 3 0 1 0 0 0 0 4 0 0 1 0 0 0 5 0 0 0 1 0 0 6 0 0 0 0 1 0 7 0 0 0 0 0 1 > contr.sum(7) [,1] [,2] [,3] [,4] [,5] [,6] 1 1 0 0 0 0 0 2 0 1 0 0 0 0 3 0 0 1 0 0 0 4 0 0 0 1 0 0 5 0 0 0 0 1 0 6 0 0 0 0 0 1 7 -1 -1 -1 -1 -1 -1 > contr.sum(7)[c(7,1:6),] [,1] [,2] [,3] [,4] [,5] [,6] 7 -1 -1 -1 -1 -1 -1 1 1 0 0 0 0 0 2 0 1 0 0 0 0 3 0 0 1 0 0 0 4 0 0 0 1 0 0 5 0 0 0 0 1 0 6 0 0 0 0 0 1