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. target_onset and key_resp.rt are columns.
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.
I know that TukeyHSD only takes factors. 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
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 theaov
function. You do not want to makekey_resp.rt
a factor at all.So the sequence should be...
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 anlm
using the numbers you have in the grouping column you can see that reflected in the degrees of freedom for thecond.aov
.As long as you already have an
aov
object might as well make the call toTukeyHSD
as simple as possible