Skip to content
Prev 262507 / 398502 Next

Linear model - coefficients

Prof. Ripley, thank you very much for the answer but wanted to get
something else. There is an example and an explanation:

options(contrasts=c("contr.sum","contr.poly")) # contr.sum uses ?sum
to zero contrasts?
Y <- c(6,3,5,2,3,1,1,6,6,6,7,4,1,6,6,6,6,1)
X <- structure(list(x1 = c(2L, 3L, 1L, 3L, 3L, 2L, 1L, 1L, 3L, 2L,
3L, 2L, 1L, 1L, 2L, 1L, 2L, 3L), x2 = c(3L, 3L, 2L, 3L, 1L, 3L,
2L, 3L, 2L, 1L, 2L, 2L, 3L, 1L, 2L, 1L, 1L, 1L), x3 = c(1L, 1L,
1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L
), x4 = c(1L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 1L, 2L), x5 = c(1L, 1L, 2L, 2L, 3L, 3L, 3L, 2L, 2L,
2L, 1L, 3L, 3L, 1L, 1L, 1L, 2L, 3L)), .Names = c("x1", "x2",
"x3", "x4", "x5"), row.names = c(NA, 18L), class = "data.frame")

reg <- lm( Y ~ factor(X$x1) + factor(X$x2) + factor(X$x3) +
factor(X$x4) + factor(X$x5)   )
coef(reg)

and e.g. I get two coefficients for variable x1 (3-levels variable)
but I would like to get the third. Of course I can calculate a3=
-(a1+a2) where a1 and a2 are coefficients of the variable x1.

I hope that I manage to explain my problem.

Robert

2011/6/12 Prof Brian Ripley <ripley at stats.ox.ac.uk>: