[R] adonis (vegan package) and subsetted factors
Gavin Simpson
gavin.simpson at ucl.ac.uk
Thu Apr 10 17:47:44 CEST 2008
On Thu, 2008-04-10 at 11:18 -0300, tyler wrote:
> 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:
Hi Tyler,
This behaviour arises from the following, using the in-built dune data:
> example(dune)
dune> data(dune)
dune> data(dune.env)
> newdune.env <- subset(dune.env, Management != "NM")
> newdune.env$Management
[1] BF SF SF SF HF SF HF HF BF BF HF SF SF HF
Levels: BF HF NM SF
Notice this hasn't dropped the empty level "NM", and this is what is
catching out adonis --- it is not checking for empty levels in the
grouping factor, as this shows:
> newdune <- dune[which(dune.env$Management != "NM"), ]
> adonis(newdune ~ Management*A1, data=newdune.env, permutations=100)
Call:
adonis(formula = newdune ~ Management * A1, data = newdune.env,
permutations = 100)
Df SumsOfSqs MeanSqs F.Model R2 Pr(>F)
Management 3.00000 0.57288 0.19096 1.27735 0.2694 <0.01 ***
A1 1.00000 0.29851 0.29851 1.99672 0.1404 0.33
Management:A1 3.00000 0.35831 0.11944 0.79892 0.1685 0.87
Residuals 6.00000 0.89699 0.14950 0.4218
Total 13.00000 2.12669 1.0000
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
For now, forcibly remove empty factor levels as per your second example,
but I'll take a look at fixing adonis() --- it looks easy but that could
be deceptive! I've CC'd the maintainer (Jari Oksanen) here as well, as I
don't think Jari follows R-help too closely at the moment.
<snip/>
>
> Thanks,
>
> Tyler
>
> ps. Sorry for not supplying a reproducible bit of code. The data.frame
> is quite large. The general layout is:
It is often instructional to use one of the in-built data sets (as I
have here), even if just to prove to yourself that it isn't a problem
with your data.
All the best,
G
--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Dr. Gavin Simpson [t] +44 (0)20 7679 0522
ECRC, UCL Geography, [f] +44 (0)20 7679 0565
Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/
UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
More information about the R-help
mailing list