# Analysis of community ecology data in R

David Zelený

### Site Tools

en:monte_carlo_r

Section: Ordination analysis

## Monte Carlo permutation test in constrained ordination

### R functions

• permutest (library vegan) - the core function in vegan conducting Monte Carlo permutation test for rda, cca and other constrained ordination methods. See anova below for details.
• anova.cca (library vegan) - is a convenience function for permutest, offering more user friendly interface. It can test the significance of constrained ordination (and different parts of it, e.g. ordination axes or individual explanatory variables), and it can be also used for model selection (comparing two nested constrained ordinations). Important arguments include:
• by decides what is tested; default is the global model, i.e. all variables included in the analysis. The test can be also done on variation explained by individual constrained axes (by = “axis”), with the test done sequentially from the first to the last (this is done by using samples scores on the n-th axis as explanatory variables, while using scores of the axis 1, 2, ... n as covariables), by individual terms (explanatory variables) added sequentially in order in which they appear in the formula or data frame (by = “terms”; note that this variation depends on the order of variables in which they enter the model); or by individual explanatory variables after removing variation of all other variables in the model (by = “margin”; here the variation does not depend on the order of variables in the model).
• permutations decides on the number of permutations and (in case of restricted permutations) on the permutation schema (defined by function how from the package permute, see details below). The function anova does by default 999 permutations (if you run permutest directly, that one is set to default of 99 permutations).
• how (library permute, implemented in vegan; see also Example 3) helps to specify the details how randomization among cases should be done (and also how many of them, by argument nperm, and whether the complete set of randomization for exact P-values should be produced, by logical argument complete). There are three hierarchical levels at which we can manipulate individual cases (samples): samples, which group into plots, and these group into blocks. Blocks are the highest level, and the rule is that cases between blocks are never randomized. Plots are intermediate levels, and cases between plots can (but do not have to) be randomized. Plots represent “whole-plots” in split-plot-like design, and in the same context samples represent “split-plots”. Randomization of samples within each of the three levels can be modified separately by arguments within, plots and blocks (cases are never randomized between blocks):
• the argument within defines how samples are permuted within plots, and the argument plots define how plots are permuted among each other. To define randomization of samples within plots and the randomization of plots among each other, there are two respective convenience functions, Within (with capital W) and Plots (with capital P), both having similar set of arguments:
• type of permutation - free, series, grid or none;
• mirror (logical) - whether the randomization schemas should be mirrored or not (applies for linear transects series, and rectangular grids),
• ncol and nrow (numeric) specifying the number of columns and rows in the grid, respectively;
• constant (logical, for Within only) defining whether the same constant order of permutation of cases should be used among different strata (e.g. for a set of time series with cases in different series recorded at the same time);
• strata (factor, for Plots only) defining strata for permutation of plots.
• the argument blocks define what is the block (as samples within blocks are never randomized, the setting is easy).
• shuffle and shufleSet (from library vegan) helps to generate set of randomizations defined in argument control by function how'. While shuffle generates one set of randomizations, shuffleSet is a convenience function to repeatedly call shuffle and generate nset of randomizations.
• permustats (library vegan) belongs to a set of functions which can extract, analyze and display results of the permutation tests; the function can be applied on the result of anova, and extracts the values of test statistic for all permutations done by the test (including the observed value on unpermuted data); these can then be summarized by function summary and visualized by function densityplot (drawing density plot of test-statistics and also position of the observed value against the null distribution).

Further reading: for more details check the excellent overview by Gavin Simpson (together with Jari Oksanen the author of most functions in vegan) in relatively recent (2020) online lecture (with video on youtube and online slides), and possibly also in an older (2014) blog post.