[Rd] matching predictors and dummies

Jeroen Ooms j.c.l.ooms at uu.nl
Fri Jul 11 16:21:14 CEST 2008

I am trying to make a little web interface for the lm() function. It
calculates both anova F-tests and parameters and returns it in a nice table.
However, I have a problem with matching the Anova predictors with the
regression coefficients: For numeric predictors there is no problem: the
coefficients have the same names as the predictors. However, when a factor
IV is specified, lm() automatically converts this factor to dummy variables,
which (of course) have different names than the orriginal predictor. The lm
model that is returned contains a seperate parameter for every dummy

Then when you use anova(lm.model) the function seems to know which of the
parameters are dummies of one and the same factor, and takes these together
in the anova-test. The anova() function returns the variance explained by
the orriginal factor, which are all dummies. It does not show the seperate
dummy variables anymore. Of course, this is exactly what you want in an
analysis of variance.

My question is: where in the lm or glm object is stored which of the
parameters are dummies of the same factor? The only thing i could think of
was using lm.model$xlevels, however manipulating these names in the lm-model
did not confuse anova() at all, so I guess there is a better way.

An additional question is if it is possible to specify the names of the
dummy variables that lm/glm creates when a factor is specified as IV? 
View this message in context: http://www.nabble.com/matching-predictors-and-dummies-tp18405023p18405023.html
Sent from the R devel mailing list archive at Nabble.com.

More information about the R-devel mailing list