[R] Design matrix not identity
John Fox
jfox at mcmaster.ca
Wed May 12 20:26:47 CEST 2004
Dear Patrick,
Try model.matrix(~ factor - 1).
I hope this helps,
John
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Patrik Waldmann
> Sent: Wednesday, May 12, 2004 11:34 AM
> To: 'r-help at stat.math.ethz.ch'
> Subject: [R] Design matrix not identity
>
> Hello again,
>
> I was too quick before. What I was looking for was a function
> that constructs the design (or incidence) matrix (X in a
> linear model) from a factor. Uwe Ligges suggested using
> model.matrix and this does almost what I want, but it is
> first necessary to construct a data variable. It also asigns
> ones to all rows of the first column (because this is set to
> be the contrast, not really what I want - see below). Maybe
> time for a function that just converts a factor into a design matrix?
>
> I have a factor
> factor<-as.factor(c(1,1,2,2,3,3,3))
>
> and I want a matrix
> 1 0 0
> 1 0 0
> 0 1 0
> 0 1 0
> 0 0 1
> 0 0 1
> 0 0 1
>
>
> Patrik Waldmann###########################################
>
More information about the R-help
mailing list