> data=data.frame(color=c("yellow","green"),sex=c("M","F"),time=c("1","2"),stringsAsFactors=TRUE)
> data
color sex time
1 yellow M 1
2 green F 2
> str(data)
'data.frame': 2 obs. of 3 variables:
$ color: Factor w/ 2 levels "green","yellow": 2 1
$ sex : Factor w/ 2 levels "F","M": 2 1
$ time : Factor w/ 2 levels "1","2": 1 2
model.matrix(~sex:color:time,data)
(Intercept) sexF:colorgreen:time1 sexM:colorgreen:time1 sexF:coloryellow:time1 sexM:coloryellow:time1 sexF:colorgreen:time2 sexM:colorgreen:time2 sexF:coloryellow:time2 sexM:coloryellow:time2
1 1 0 0 0 1 0 0 0 0
2 1 0 0 0 0 1 0 0 0
attr(,"assign")
[1] 0 1 1 1 1 1 1 1 1
attr(,"contrasts")
attr(,"contrasts")$sex
[1] "contr.treatment"
attr(,"contrasts")$color
[1] "contr.treatment"
attr(,"contrasts")$time
[1] "contr.treatment"
> model.matrix(~sex*color*time,data)
(Intercept) sexM coloryellow time2 sexM:coloryellow sexM:time2 coloryellow:time2 sexM:coloryellow:time2
1 1 1 1 0 1 0 0 0
2 1 0 0 1 0 0 0 0
attr(,"assign")
[1] 0 1 2 3 4 5 6 7
attr(,"contrasts")
attr(,"contrasts")$sex
[1] "contr.treatment"
attr(,"contrasts")$color
[1] "contr.treatment"
attr(,"contrasts")$time
[1] "contr.treatment"
> data=data.frame(color=c("yellow","green"),sex=c("M","F"),time=1:2,stringsAsFactors=TRUE)
> str(data)
'data.frame': 2 obs. of 3 variables:
$ color: Factor w/ 2 levels "green","yellow": 2 1
$ sex : Factor w/ 2 levels "F","M": 2 1
$ time : int 1 2
> model.matrix(~sex:color:time,data)
(Intercept) sexF:colorgreen:time sexM:colorgreen:time sexF:coloryellow:time sexM:coloryellow:time
1 1 0 0 0 1
2 1 2 0 0 0
attr(,"assign")
[1] 0 1 1 1 1
attr(,"contrasts")
attr(,"contrasts")$sex
[1] "contr.treatment"
attr(,"contrasts")$color
[1] "contr.treatment"
> model.matrix(~sex*color*time,data)
(Intercept) sexM coloryellow time sexM:coloryellow sexM:time coloryellow:time sexM:coloryellow:time
1 1 1 1 1 1 1 1 1
2 1 0 0 2 0 0 0 0
attr(,"assign")
[1] 0 1 2 3 4 5 6 7
attr(,"contrasts")
attr(,"contrasts")$sex
[1] "contr.treatment"
attr(,"contrasts")$color
[1] "contr.treatment"
>
~sex+color
Intercept Male Yellow
FG 1 0 0
FY 1 0 1
MG 1 1 0
MY 1 1 1
~sex*color
Intercept Male Yellow Male:Yellow
FG 1 0 0 0
FY 1 0 1 0
MG 1 1 0 0
MY 1 1 1 1
~-1+ sex*color
FG FY MG MY
FG 1 0 0 0
FY 0 1 0 0
MG 0 0 1 0
MY 0 0 0 1
Users browsing this forum: No registered users and 2 guests