[R] Why is model.matrix creating 2 columns for boolean?

Ben Bolker bolker at ufl.edu
Sat Nov 17 18:51:02 CET 2007




Ross Boylan wrote:
> 
> I have a data frame "reading" that includes a logical variable "OLT"
> along with response variable "Reading" and predictor "True" (BOTH are
> numeric variables; it's "True" as in the true value).
> 
> When I suppress the intercept, model.matrix gives me OLTTRUE and
> OLTFALSE columns.  Why?  Can I do anything to prevent it?
> 
> 

 I guess I don't understand the question -- this seems to be the
right behavior ... if you fitted the model Reading~OLT-1, you
need two coefficients, one to predict the value of cases where
OLT=FALSE and one to predict the value where OLT=TRUE.
You can parameterize the model as (value when FALSE,
difference between FALSE and TRUE) or (value when TRUE,
difference between TRUE and FALSE) or (value when TRUE,
value when FALSE) -- but however you do it you'll need two
variables in the model matrix -- right?  Adding a continuous
predictor shouldn't matter.

 If you don't want the extra column you can always drop
it with mm[,-1] ...

  Ben Bolker

-- 
View this message in context: http://www.nabble.com/Why-is-model.matrix-creating-2-columns-for-boolean--tf4817540.html#a13811570
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list