R中的乘法设计矩阵

时间:2015-02-28 16:54:31

标签: r matrix linear-regression

R

model.matrix(~ Treatment + Time + Treatment*Time, table_design)

相当于

model.matrix(~ Treatment*Time, table_design)

感谢。

1 个答案:

答案 0 :(得分:1)

table_design<-data.frame(
    Treatment=rep(c("A","B"), each=10),
    Time=rpois(20,20)
)
all.equal(
  model.matrix(~ Treatment + Time + Treatment*Time, table_design), 
  model.matrix(~ Treatment*Time, table_design)
)
# [1] TRUE