[R] cca with repeated measures

Gavin Simpson gavin.simpson at ucl.ac.uk
Fri Nov 18 11:01:40 CET 2011

On Fri, 2011-11-18 at 10:25 +0100, René Mayer wrote:
> Dear all,
> How can I run a constrained correspondence analysis with
> the following data:
> 15 animals were measured repeatedly month-wise (over to 2 years)  
> according to ther diet composition (8 food categories).
> our data.frame looks like this:
> food 1  2 ... 8  sex season year animal
> freq 12 8 ... 1  0   summer 2011 1
> freq 0  7 ... 0  1   winter 2011 1
> ...
> freq 0  7 ... 0  1   spring 2011 15
> We want to find out if season and sex influences diet composition.
> My experience with CCA is limited, but in repeated measures ANOVA,  
> e.g. with aov()
> on has to define the between (animal) error term in order to deal with  
> the pseudoreplication.
> Do I have to restructure or reshape the data in order to deal with  
> pseudoreplication
> the data? Or do I have to define an error strata?
> I suspect I cannot simply run:
> library(vegan)
> model=cca(food ~ season*sex+year+animal, data)

You could do that although the analysis would be i) focussed on those
particular animals in those years, and ii) you could only test the terms
season, sex and season:sex in a sequential manner (i.e. dependent upon
how the terms enter the model), so season, then sex after season is in
the model, then their interaction after both main terms are included in
the model.

ii) is done by adding `by = "terms"` to the call to the `anova method
for "cca" objects; examples are in `?anova.cca`

That corresponds to a fixed effects formulation of the ANOVA (assuming I
have my terminology right). The alternative is to adjust the permutation
scheme used to reflect the clustering in your data. In that case, using
`strata = animal` would be OK. Ideally one would want to control for
temporal dependence so you would want cyclic shifts *within* `strata =
animal` but vegan can not yet do this sort of permutation. It is coming;
the actual code to generate those permutations is available in the
permute package (upon which vegan depends), but as yet we have not
hooked this into the vegan ordination functions (it is on the TODO
list). That said, season should be accounting for much of the temporal
dependence, so I think you might get away with just specifying strata
(the permutation test itself is permuting residuals from the model so if
the model is capturing the seasonal variation then the simple permuting
within animal should be OK, but you can check by extracting the
residuals using the resid() method and plotting them out by time and



> I would be grateful for any help.
> Thanks in advance,
> René
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

 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