I'm trying to run a Tukey test on mortality data, where I want to test whether mortality is influenced by the amount of copper (in an one-way ANOVA) and the combination of copper and temperature (in a two-way ANOVA). These are my formulas:
lm2<-lm(Mortality~Cu)
anova(lm2)
TukeyHSD(aov(Mortality~Cu))
lm2<-lm(Mortality~Cu+Temp+Cu:Temp)
anova(lm2)
TukeyHSD(aov(Mortality~Cu+Temp+Cu:Temp))
The ANOVA is no problem, but for both Tukey's, I get the following error message:
Error in TukeyHSD.aov(aov(Mortality ~ Cu + Temp + Cu:Temp)) :
no factors in the fitted model
In addition: Warning messages:
1: In replications(paste("~", xx), data = mf) : non-factors ignored: Cu
2: In replications(paste("~", xx), data = mf) : non-factors ignored: Temp
3: In replications(paste("~", xx), data = mf) :
non-factors ignored: Cu, Temp
I've read on other posts that there should be a factor somewhere, but all my data are numbers! I'm quite baffled and have no idea what to do next.
Thanks in advance for your help!
Lundill
TukeyHSD
only works with categorical variables so it's looking for factors in your formula. Are the values of Cu
discrete bust just coded as numeric values? If so then use
fCu<-factor(Cu)
TukeyHSD(aov(Mortality~fCu))
Or are the observations continuous? Then you must break it into intervals to turn it into a factor. You could do
fCu<-cut(Cu, breaks=4)
TukeyHSD(aov(Mortality~fCu))
If only a subset of variables on the right side of the equation are factors, you must specify those explicitly in the which
parameter of the TukeyHSD
. So if you use the categorical fCu
and Temp
is a continuous numeric variable, you can do
TukeyHSD(aov(Mortality~fCu+Temp), which="fCu")
though it still issues a warning about the other columns so i'm not sure how to interpret the results