Skip to content

Design matrix labels

2 messages · John Logsdon, Thomas Lumley

#
If I have two factors A and B with levels '1','2','3' and '1','4','6','8'
recpectively (note the gaps in the second one).  As factors, the levels
are named as above while of course the internal codes are (1,2,3) and
(1,2,3,4) respectively.

I want to make a design matrix of these as one would in a linear model
except I can't use lm or glm since the error distribution is not
tractable.  So I generate an overall factor as 10*A+B (for example) then
the internal codes and levels become 11,12,13,14,21,22,23,24,31,32,33,34.
I don't mind the internal codes, but is there a neater way of generating
the lm-type of factor levels a A*B to give the levels
'11','14','16','18','21','24','26','28','31','34','36','38'?

Better still would be to assign proper labels to the levels and get
factors a 'A1.B1','A1.B2' etc., basically mimicking the standard notation. 

Is there a proper way to do this other than for-looping and pasting? I
don't really want to create a hand-mapping because it is not robust to
changes. 

\John

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Mon, 25 Jan 1999, John Logsdon wrote:

            
You can still use model.frame() and model.matrix() to create design
matrices from formulas.

	mf<-model.frame(~A+B)
	mmat<-model.matrix(~A+B,mf)

If your factors A and B are in a data frame you can use the data= argument
to model.frame().

This is what glm() and lm() do internally.

Thomas Lumley
Assistant Professor, Biostatistics
University of Washington, Seattle


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._