2

是什么解释了aov以下两者之间的区别:

a = c(0.04875,0.13725,0.28350,0.50975,0.77425,0.94700,0.05325,0.14050,0.29725,0.51525,0.79000,0.95400,0.04625,0.15250,0.29000,0.53300,0.79825,0.95225,0.05025,0.14625,0.28800,0.52625,0.78200,0.95925,0.04700,0.14225,0.30325,0.53500,0.79325,0.95875,0.04775,0.13850,0.28675,0.54250,0.78300,0.95175,0.05150,0.12725,0.30175,0.54725,0.79475,0.96275,0.05375,0.14100,0.30050,0.53275,0.78100,0.96175,0.05450,0.15300,0.29650,0.52850,0.80100,0.95675,0.05425,0.13975,0.30875,0.56025,0.80575,0.96100,0.05100,0.15350,0.31175,0.53300,0.78900,0.96000,0.04650,0.13525,0.29600,0.53625,0.78475,0.96375,0.05375,0.13900,0.29600,0.53725,0.78700,0.95800,0.05075,0.14350,0.29225,0.54525,0.80275,0.95800,0.05050,0.13200,0.29850,0.52700,0.80525,0.96150,0.05150,0.14050,0.29450,0.54375,0.79450,0.96375,0.05375,0.13525,0.30475,0.55250,0.79425,0.96025,0.04950,0.14500,0.29425,0.52250,0.78475,0.95650,0.05225,0.14425,0.29225,0.53150,0.80425,0.95375)
b = c(4,4,4,4,4,4,6,6,6,6,6,6,8,8,8,8,8,8,10,10,10,10,10,10,12,12,12,12,12,12,14,14,14,14,14,14,16,16,16,16,16,16,18,18,18,18,18,18,20,20,20,20,20,20,22,22,22,22,22,22,24,24,24,24,24,24,26,26,26,26,26,26,28,28,28,28,28,28,30,30,30,30,30,30,32,32,32,32,32,32,34,34,34,34,34,34,36,36,36,36,36,36,38,38,38,38,38,38,40,40,40,40,40,40)
c = c(1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6)


summary(lm(a~b*as.factor(c)))
summary(lm(a~b*c))

这是否意味着c在使用 as.factor 时被视为非序数?

4

2 回答 2

2

在这两种情况下,您都在探索和它们a的相互作用。 bc

当您强制c使用一个因子时,将为每个不同的值计算虚拟变量c (实际上每个级别c,但在这种情况下,所有级别都存在,因此它们是相同的)c因此,所探索的交互作用是在with的每个值之间b

否则,所探索的交互是数值变量的交互。

c如果有更剧烈的价值差异,差异可能会更明显,即

c = c(1, 17, 2, 5, 131, 1, 4, 5, 2, 11, 17, 7, 1, 1, 17, .... etc)   

另外,在学习时要注意R,避免c用作变量名。它也是一个频繁使用的函数的名称,它会很快使代码变得不可读并导致可能的混淆

于 2013-07-30T19:06:53.677 回答
0

您可以通过查看它们的 model.matrix() 结果来检查创建的模型的结构,因为model.matrix函数是lm函数用于从公式的 RHS 构造数据进行分析的函数:

> dim(model.matrix(~b*as.factor(c)))
[1] 114  12
> dim( model.matrix(~b*c))
[1] 114   4

> colnames(model.matrix(~b*as.factor(c)))
 [1] "(Intercept)"     "b"               "as.factor(c)2"   "as.factor(c)3"  
 [5] "as.factor(c)4"   "as.factor(c)5"   "as.factor(c)6"   "b:as.factor(c)2"
 [9] "b:as.factor(c)3" "b:as.factor(c)4" "b:as.factor(c)5" "b:as.factor(c)6"
> colnames( model.matrix(~b*c))
[1] "(Intercept)" "b"           "c"           "b:c"  

第二个模型中“c”变量的列名没有像第一个模型中那样分成不同的级别。'b:c' 列将是 'b' 和 'c' 的乘积:

> describe(b*c)
b * c 
      n missing  unique    Mean     .05     .10     .25     .50     .75     .90 
    114       0      67      77    12.0    16.6    30.5    62.0   111.5   160.0 
    .95 
  190.7 

lowest :   4   6   8  10  12, highest: 200 204 216 228 240 
> describe(model.matrix(~b*c)[, "b:c"])
model.matrix(~b * c)[, "b:c"] 
      n missing  unique    Mean     .05     .10     .25     .50     .75     .90 
    114       0      67      77    12.0    16.6    30.5    62.0   111.5   160.0 
    .95 
  190.7 

lowest :   4   6   8  10  12, highest: 200 204 216 228 240 
于 2013-07-30T19:18:24.753 回答