[R] ANOVA from imported data has only 1 degree of freedom

Ben Bolker bbolker at gmail.com
Mon Oct 10 04:08:02 CEST 2011


shardman <samuelhardman <at> hotmail.com> writes:

> 
> Hi,
> 
> I'm trying to analyse some data I have imported into R from a .csv file but
> when I carry out the aov command the results show only one degree of freedom
> when there should be 14. Does anyone know why? I'd really appreciate some
> help, the data is pasted below.
> 
> /The imported table looks ike this this:/
> 
>         Order Transect Sample Abundance
> 1  Coleoptera        1      1        13
[snip]
> 15 Coleoptera        3      5        29
> 
> /The command I am using is this:/
> 
> anova2<-aov(Abundance~Transect,data=beetle)
> 

I was going to tell you to read up on the distinction between
factors and numeric variables in statistical models, but I can't
immediately find a reference on line (this is bound to be
in Peter Dalgaard's book or any other basic-stats-with-R
text).

str() will tell you whether the columns are numeric or factors.

Try

beetle <- transform(beetle,Transect=factor(Transect))

[or ?read.csv and use colClasses explicitly to specify
the classes of the columns]

before running your anova.



More information about the R-help mailing list