From ccberry at ucsd.edu  Fri Oct 17 18:43:40 2014
From: ccberry at ucsd.edu (Charles Berry)
Date: Fri, 17 Oct 2014 16:43:40 +0000
Subject: [Rd] model.matrix metadata
References: <CA+BxRLaXUQX=gQfF26d0fcoT5Bg3tSbijtBzPMuR1Pugf7WcKw@mail.gmail.com>
Message-ID: <loom.20141017T183457-789@post.gmane.org>

Patrick O'Reilly <patrick.a.oreilly <at> gmail.com> writes:

> 
> Hi,
> 
> 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?

i.e

my.terms <- terms( my.formula, data=my.data.frame )
my.model.matrix <- model.matrix( my.terms, data= my.data.frame )

attributes(my.terms)


See ?terms, ?terms.object, ?model.frame (which contains a terms.object)


HTH,

Chuck



[Rd] model.matrix metadata
Charles Berry