[Rd] model.matrix metadata
ccberry at ucsd.edu
Fri Oct 17 18:43:40 CEST 2014
Patrick O'Reilly <patrick.a.oreilly <at> gmail.com> writes:
> As far as I am aware, the model.matrix function does not return
> perfect metadata on what each column of the model matrix "means".
> The columns are named (e.g. age:genderM), but encoding the metadata as
> strings can result in ambiguity. For example, the dummy variables
> created when the factors var0 = 0 and var = 00 both are named var00.
> Additionally, if a level of a factor variable contains a colon, this
> could be confused for an interaction.
> While a human can generally work out the meaning of each column
> somewhat manually, I am interested in achieving this programmatically.
Why don't you just retain the terms.object?
my.terms <- terms( my.formula, data=my.data.frame )
my.model.matrix <- model.matrix( my.terms, data= my.data.frame )
See ?terms, ?terms.object, ?model.frame (which contains a terms.object)
More information about the R-devel