An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120703/9ff444ab/attachment.pl>
design matrix creation in R
5 messages · mmstat at comcast.net, David Winsemius, Duncan Murdoch +1 more
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120703/8bdef42d/attachment.pl>
On Jul 3, 2012, at 4:10 PM, mmstat at comcast.net wrote:
Hello, I want to create a design matrix using R. Can you explain the code which creates the following please? I understand the first part.
What first part if the next part is ... this ?
b=g1(?) does what?
That's just generating a factor variable.
dd <- data.frame(a = gl(3,4), b = gl(4,1,12)) # balanced 2-way dd a b 1 1 1 2 1 2 3 1 3 4 1 4 5 2 1 6 2 2 7 2 3 8 2 4 9 3 1 10 3 2 11 3 3 12 3 4 I am using the tree dataset in R. I want to form a reparameterized design matrix in ones, zeroes and minus ones. The dataframe dd is very important here. Can anyone assist here? Thanks in advance.
Something like this?
model.matrix(~a+b, data= dd, contrasts = list(a="contr.sum",
b="contr.sum") )
(Intercept) a1 a2 b1 b2 b3
1 1 1 0 1 0 0
2 1 1 0 0 1 0
3 1 1 0 0 0 1
4 1 1 0 -1 -1 -1
5 1 0 1 1 0 0
6 1 0 1 0 1 0
7 1 0 1 0 0 1
8 1 0 1 -1 -1 -1
9 1 -1 -1 1 0 0
10 1 -1 -1 0 1 0
11 1 -1 -1 0 0 1
12 1 -1 -1 -1 -1 -1
attr(,"assign")
[1] 0 1 1 2 2 2
attr(,"contrasts")
attr(,"contrasts")$a
[1] "contr.sum"
attr(,"contrasts")$b
[1] "contr.sum"
David Winsemius, MD West Hartford, CT
On 03/07/2012 4:10 PM, mmstat at comcast.net wrote:
Hello, I want to create a design matrix using R. Can you explain the code which creates the following please? I understand the first part. b=g1(?) does what?
That is gl, not g1 (i.e. gee ell not gee one). See ?gl for a description. Duncan Murdoch
dd <- data.frame(a = gl(3,4), b = gl(4,1,12)) # balanced 2-way dd a b 1 1 1 2 1 2 3 1 3 4 1 4 5 2 1 6 2 2 7 2 3 8 2 4 9 3 1 10 3 2 11 3 3 12 3 4 I am using the tree dataset in R. I want to form a reparameterized design matrix in ones, zeroes and minus ones. The dataframe dd is very important here. Can anyone assist here? Thanks in advance. Mary A. Marion [[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120703/714d18b6/attachment.pl>