[英]Tukey HSD for categorical and continuous variables in R
I want to do a post-hoc test for a significant ANOVA I've done successfully.我想对我成功完成的重要方差分析进行事后测试。
I have 5 conditions (target_onset) across which I want to compare reaction times (key_resp.rt) in a df called data_clean.我有 5 个条件(target_onset),我想在一个名为 data_clean 的 df 中比较反应时间(key_resp.rt)。 target_onset and key_resp.rt are columns.
target_onset 和 key_resp.rt 是列。
This is how I did the ANOVA, which worked fine:这就是我做方差分析的方法,效果很好:
cond.aov <- aov(data_clean$target_onset ~ data_clean$key_resp.rt)
summary(cond.aov)
Next, I want to see what a post-hoc test says to find out which differences between the 5 conditions are significant.接下来,我想看看事后测试是怎么说的,以找出这 5 个条件之间的哪些差异是显着的。
I know that TukeyHSD only takes factors.我知道 TukeyHSD 只考虑因素。 So I factorized my columns of interest:
所以我分解了我感兴趣的列:
data_clean$target_onset <- factor(data_clean$target_onset)
data_clean$key_resp.rt <- factor(data_clean$key_resp.rt)
TukeyHSD(aov(data_clean$target_onset ~ data_clean$key_resp.rt))
However, when I run this code, I get the following error:但是,当我运行此代码时,出现以下错误:
Error in class(y) <- oldClass(x): adding class "factor" to an invalid object In addition: Warning messages: 1: In model.response(mf, "numeric"): using type = "numeric" with a factor response will be ignored 2: In Ops.factor(y, z$residuals): '-' not meaningful for factors
类(y)<-oldClass(x)中的错误:将 class“因子”添加到无效的 object 此外:警告消息:1:在 model.response(因子响应将被忽略 2: 在 Ops.factor(y, z$residuals): '-' 对因子没有意义
Any suggestions would be helpful.任何的意见都将会有帮助。 Thanks in advance.
提前致谢。
EDIT first time through I missed the fact you had the formula backwards as well!第一次编辑我错过了你也有公式倒退的事实!
You need to make target_onset
a factor before issuing the aov
function.在发布
aov
function之前,您需要将target_onset
作为一个因素。 You do not want to make key_resp.rt
a factor at all.您根本不想让
key_resp.rt
成为一个因素。
So the sequence should be...所以顺序应该是...
data_clean$target_onset <- factor(data_clean$target_onset)
cond.aov <- aov(key_resp.rt ~ target_onset, data = data_clean)
summary(cond.aov)
TukeyHSD(cond.aov)
The dependent variable (the response time goes on the left of the tilde and the independent grouping variable to the right.因变量(响应时间在波浪号的左侧,独立的分组变量在右侧。
If you don't make the condition/grouping variable a factor
aov
which actually do an lm
using the numbers you have in the grouping column you can see that reflected in the degrees of freedom for the cond.aov
.如果您没有使条件/分组变量成为
aov
factor
,它实际上使用分组列中的数字执行lm
,您可以看到它反映在cond.aov
的自由度中。
As long as you already have an aov
object might as well make the call to TukeyHSD
as simple as possible只要您已经有一个
aov
object 就可以尽可能简单地调用TukeyHSD
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.