[R] adonis (vegan package) and subsetted factors

tyler tyler.smith at mail.mcgill.ca
Thu Apr 10 16:18:56 CEST 2008


Hi,

I'm trying to use adonis on a subset of data from a dataframe. The
actual data is in columns 5:118, and the first four columns are various
factors. There are 3 levels of the factor Habitat, and I want to examine
differences among only two of them. So I started with:

> CoastNear = subset(gel_data, Habitat != "I")

The resulting data.frame has three levels for Habitat, but only two of
those levels have any records. Then I run:

> adonis(CoastNear[,5:118]~Habitat, data = CoastNear,permutations=1000,
+ method='jaccard')

Call:
adonis(formula = CoastNear[, 5:118] ~ Habitat, data = CoastNear,
permutations = 1000, method = "jaccard") 

                  Df  SumsOfSqs    MeanSqs    F.Model     R2 Pr(>F)
Habitat    2.0000000  0.0092966  0.0046483  2.0549327 0.0707  0.005
Residuals 54.0000000  0.1221491  0.0022620            0.9293       
Total     56.0000000  0.1314457                       1.0000       

This appears to be wrong - with only two Habitat levels I should only
have 1 Df, shouldn't I? I checked by forcibly excising the third factor
level:

> CoastNear$Habitat <- as.factor(as.character(CoastNear$Habitat))
> adonis(CoastNear[,5:118]~Habitat, data = CoastNear,permutations=1000,
+ method='jaccard')

Call:
adonis(formula = CoastNear[, 5:118] ~ Habitat, data = CoastNear,
permutations = 1000, method = "jaccard") 

                  Df  SumsOfSqs    MeanSqs    F.Model     R2 Pr(>F)
Habitat    1.0000000  0.0092966  0.0092966  4.1859740 0.0707  0.003
Residuals 55.0000000  0.1221491  0.0022209            0.9293       
Total     56.0000000  0.1314457                       1.0000       

This appears to be correct. Subsetting factors is something I always
struggle with in R, but, based on previous experience with lda(), it
seems that R generally does the right thing. Am I doing something wrong
here, or is there a problem in adonis?

Thanks,

Tyler

ps. Sorry for not supplying a reproducible bit of code. The data.frame
is quite large. The general layout is:

> head(gel_data) # additional data columns trimmed for email
  Site Habitat Plot Concate A01 A02 A03 A04 A05 A06 A07 A08 A09 A10 
1   PE       C    1    PEC1   1   1   1   1   1   1   1   1   1   1 
2   PE       C    3    PEC3   1   1   1   1   0   1   1   1   1   1 
3   PE       C    4    PEC4   1   1   1   1   0   1   1   1   1   1 
4   PE       C    6    PEC6   1   1   1   1   0   1   1   1   1   1 
5   PE       C   12   PEC12   1   1   1   1   0   1   1   1   1   1 
6   PE       C   13   PEC13   1   1   1   1   0   1   1   1   1   1



More information about the R-help mailing list