[R] Question about factor that is numeric, in aov()

David Winsemius dwinsemius at comcast.net
Sun May 9 16:36:16 CEST 2010

On May 9, 2010, at 8:36 AM, Ravi Kulkarni wrote:

> I notice something curious about how aov() treats a numeric factor:
> "score" is a dependent variable and "group" is a factor in a one-way  
> But "group" contains numeric codes and is not a factor (checked with
> is.factor). An ANOVA done using:
>> aov(score~factor(group), data=mydata)
> gives the right answers. But
>> aov(score~group, data=mydata)
> also produces an ANOVA table, with incorrect entries. My question  
> is: what
> exactly is R doing when I did not specify that "group" was a factor?

Since you have not shown us the table we can only guess. My guess: It  
is treating that variable as continuous and estimating a single  
parameter. That may or may not be interpretable. If those codes have a  
meaningful order and scale, you may be getting what is sometimes  
called a trend test. If they are arbitrary, then the result is very  
probably nonsense.

> Ravi Kulkarni
> -- 

David Winsemius, MD
West Hartford, CT

More information about the R-help mailing list