HronnE wrote on 09/27/2011 06:27:38 AM:
> 
> Hi all
> 
> This is probably a simple problem but somehow I am having much trouble 
with
> finding a solution, so I seek your help!
> 
> I have a data-set with continuous response variables. The explanatory
> variably is 4xpH treatments (so 8.08, 7.94, 7.81 and 7.71)  so  also
> continuous and not technically factorial. 
> 
> However I have decided to do Anova's (as well as regression) to explore 
the
> effect of pH.
> 
> What I don't understand is why the anova done in such a way:
> 
> summary(aov(BioMass~pH))
> 
> ... gives me completely different p-values if I define the pH as factor 
or
> not. And what would be the correct approach?
> 
> Help on this subject would be much appreciated!
> 
> Hronn


If pH is a numeric variable (see ?class) then your formula is instructing 
aov() to include it as a linear term with one degree of freedom, just like 
lm() does if you're fitting a regression.  If you want to treat pH as a 
categorical variable, then you must make sure that it is included in the 
model as a factor.  Then you will see that it uses three degrees of 
freedom.

BioMass <- rnorm(100)
pH <- sample(c(8.08, 7.94, 7.81, 7.71), size=100, replace=TRUE)
pH.f <- as.factor(pH)

summary(aov(BioMass ~ pH))
summary(lm(BioMass ~ pH))

summary(aov(BioMass ~ pH.f))
summary(lm(BioMass ~ pH.f))


Jean
	[[alternative HTML version deleted]]

