简体   繁体   English

R中的线性对比和方差分析

[英]Linear Contrasts and Anova in R

I'm trying to understand this question (my teacher is on vacation) and I would appreciate some help. 我正在尝试理解这个问题(我的老师正在休假),并且希望获得一些帮助。

Using the “contr.sum” contrasts option, conduct a two-way analysis of variance (ANOVA) that includes Time and Area as main effects and an interaction between the two main effects. 使用“ contr.sum”对比度选项,进行双向方差分析(ANOVA),其中包括时间和面积作为主要影响,以及两个主要影响之间的相互作用。

I'm not really sure how to use contrasts to do ANOVA. 我不太确定如何使用对比进行方差分析。 My answers seem to be separate. 我的答案似乎是分开的。 I have created a model like so 我已经创建了一个像这样的模型

modelCO1 = aov(CO~Time+Area+(Time*Area), data = WorkplaceCO)

But this has nothing to do with linear contrasts. 但这与线性对比无关。 Whenever I try to use this code 每当我尝试使用此代码

modelCO1$contrasts$Time

I get an output that just says 我得到的输出只是说

"contr.sum"

Which doesn't really tell me anything. 真的什么也没告诉我。 Alternatively, I have done this 或者,我已经做到了

options(contrasts=c("contr.sum", "contr.poly"))

contrasts(WorkplaceCO$Area)
contrasts(WorkplaceCO$Time)

Which gave me an output of 这给了我输出

> contrasts(WorkplaceCO$Area)
           [,1]
Nonsmoking    1
Smoking      -1
> contrasts(WorkplaceCO$Time)
        [,1] [,2] [,3] [,4] [,5]
7:00am     1    0    0    0    0
10:00am    0    1    0    0    0
11:00am    0    0    1    0    0
1:20pm     0    0    0    1    0
4:20pm     0    0    0    0    1
7:00pm    -1   -1   -1   -1   -1

But again, where does ANOVA fit in? 但是,方差分析又适合哪里呢? Much obliged. 多谢。

Setting contrasts needs to be done before you fit the model. 在拟合模型之前,需要进行对比设置。 So if you run options(contrasts=c("contr.sum", "contr.poly")) before the call to aov() then you will get the model you want. 因此,如果在调用aov()之前运行options(contrasts=c("contr.sum", "contr.poly")) ,那么您将获得所需的模型。 Note that the options() call changes the defaults for future calls to contrasts() ; 请注意, options()调用更改了以后对contrasts()调用的默认值; if you don't want that you can set contrasts on a factor without changing the defaults like this: 如果您不希望在不改变默认值的情况下就可以设置一个因子的对比度,例如:

contrasts(WorkplaceCO$Area) <- contr.sum
contrasts(WorkplaceCO$Time) <- contr.sum

Whichever way you do it, it needs to be done before aov() . 无论采用哪种方式,都需要在aov()之前完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM