Ecologists have long debated the relationship between species diversity and stability. One key question in this debate is how the individual components of a community (e.g., species in species-rich communities) affect the stability of aggregate properties of the whole community (e.g., biomass production). It is increasingly recognized that unstable species populations may still maintain stable community productivity if a decrease in one species is compensated for by an increase in another. In a time series, this should be reflected by a pattern in which species negatively covary or fluctuate asynchronously while total community stability remained relatively stable.

`codyn`

includes a function to characterize community stability, `community_stability`

, and three metrics to characterize species covariance and asynchrony:

`variance_ratio`

characterizes species covariance (Schluter 1984; Houlahan et al. 2007), and includes a null-modeling approach to test significance (Hallett et al. 2014).`synchrony`

has two options. The first compares the variance of the aggregated community with the variance of individual components (Loreau and Mazancourt 2008). The second compares the average correlation of each individual species with the rest of the aggregated community (K. Gross et al. 2014).

To illustrate each function, `codyn`

uses a dataset of plant composition from an annually burned watershed at the Konza Prairie Long-Term Ecological Research site in Manhattan, KS. The `knz_001d`

dataset spans 24 years and includes 20 replicate subplots.

```
library(codyn)
library(knitr)
data(knz_001d)
kable(head(knz_001d))
```

species | year | subplot | abundance |
---|---|---|---|

achillea millefolium | 1986 | A_1 | 0.5 |

ambrosia psilostachya | 1988 | A_1 | 0.5 |

ambrosia psilostachya | 1990 | A_1 | 3.0 |

ambrosia psilostachya | 1995 | A_1 | 3.0 |

ambrosia psilostachya | 1991 | A_1 | 3.0 |

ambrosia psilostachya | 1998 | A_1 | 15.0 |

The `community_stability`

function aggregates species abundances within replicate and time period, and uses these values to calculate community stability as the temporal mean divided by the temporal standard deviation (Tilman 1999). It includes an optional argument to calculate community stabilty across multiple replicates, which returns a data frame with the name of the replicate column and the stability value.

```
KNZ_stability <- community_stability(knz_001d,
time.var = "year",
abundance.var = "abundance",
replicate.var = "subplot")
kable(head(KNZ_stability))
```

subplot | stability |
---|---|

A_1 | 4.12 |

A_2 | 3.99 |

A_3 | 6.51 |

A_4 | 4.32 |

A_5 | 3.42 |

B_1 | 4.48 |

If `replicate.var`

is left as `NA`

, the function will aggregate all values within a time period and return an integer value.

```
KNZ_A1_stability <- community_stability(df = subset(knz_001d, subplot=="A_1"),
time.var = "year",
abundance.var = "abundance")
KNZ_A1_stability
```

[1] 4.12

The variance ratio was one of the first metrics to characterize patterns of species covariance (Schluter 1984) and was used in an early synthesis paper of species covariance in long time series (Houlahan et al. 2007). The metric compares the variance of the community (\(C\)) as a whole relative to the sum of the individual population (\(x_i\)) variances:

\[ VR = \frac{Var(C)}{\sum_{i}^{N} Var(x_i)} \]

where:

\[ Var(C) = \sum_{i = 1}^{N} Var(x_i) + 2\left(\sum_{i = 1}^{N - 1} \sum_{j = i + 1}^{N} Covar(x_i, x_j)\right) \]

If species vary independently then the variance ratio will be close to 1. A variance ratio < 1 indicates predominately negative species covariance, whereas a variance ratio > 1 indicates that species generally positively covary.

The variance ratio remains widely used but has been subject to a number of criticisms. Importantly, early uses of the variance ratio either did not include significance tests, or tested significance by comparing observed values to those returned by scrambling each species’ time series. Null models using fully-scrambled species time series can generate spurious null expectations of covariance because the process disrupts within-species autocorrelation. Phase-scrambling (Grman et al. 2010) and cyclic shifts (Hallett et al. 2014; adapted from Harms et al. 2001) have been used to address this issue.

`variance_ratio`

uses a cyclic shift permutations to conduct null modeling for significance tests. In this method a starting time point is randomly selected for each species’ time series. This generates a null community matrix in which species abundances vary independently but within-species autocorrelation is maintained (for each species, the time series is disrupted only once).

If a replicate column is specified, the default `variance_ratio`

setting calculates a null variance ratio for each replicate in the dataset, averages these values, and repeats as many times as specified by `bootnumber`

. This vector of averaged, null variance ratios is then sampled for lower and upper confidence intervals, which are returned along with the average observed variance ratio.

```
KNZ_variance_ratio <- variance_ratio(df = knz_001d,
species.var = "species",
time.var = "year",
abundance.var = "abundance",
bootnumber = 10,
replicate.var = "subplot")
kable(KNZ_variance_ratio)
```

Alternatively, if a replicate column is specified and `average.replicates`

is set to `FALSE`

, the function will return a vector of null variance ratios for each replicate in the dataset, and return the subsequent confidence intervals and observed variance ratios for each replicate.

```
KNZ_variance_ratio_avgrep <- variance_ratio(knz_001d,
time.var = "year",
species.var = "species",
abundance.var = "abundance",
bootnumber = 10,
replicate.var = "subplot",
average.replicates = FALSE)
kable(head(KNZ_variance_ratio_avgrep))
```

If `replicate.var`

is left as `NA`

the function assumes that there is a single observation for each species within a given time period.

```
KNZ_A1_variance_ratio <- variance_ratio(df = subset(knz_001d, subplot=="A_1"),
time.var = "year",
species.var = "species",
abundance.var = "abundance",
bootnumber = 10)
kable(KNZ_A1_variance_ratio)
```

`codyn`

also includes the option to apply a cyclic shift permutation on other test statistics:

`cyclic_shift`

returns an S3 object of test statistics from a user-specified function when applied to a null community generated via a cyclic shift permutation. It requires a dataframe with a`species.var`

,`time.var`

and`abundance.var`

column, and optional`replicate.var`

column. The user-specified function should operate on a community matrix (e.g.,`cov`

).

The length of the “out” param in the object is the number of null iterations as specified by `bootnumber`

). If multiple replicates are specified, null values are averaged among replicates for each interation, but a different cyclic shift permutation is applied to each replicate within an interation.

`confint`

returns the confidence intervals from the S3 object produced by`cyclic_shift`

.

A second criticism of the variance ratio is that it is sensitive to species richness. This is a particular concern when the metric is used to compare communities that have different levels of species richness. The most conservative approach is to restrict use of the variance ratio to two-species communities (Hector et al. 2010). Comparing the effect size of the observed versus null variance ratio can also account for richness differences between communities. Two alternative metrics that quantify species asynchrony have been developed in part to respond to this issue.

Loreau and de Mazancourt (2008) developed a metric of species synchrony that compares the variance of aggregated species abundances with the summed variances of individual species:

\[ Synchrony = \frac{{\sigma_(x_T)}^{2}}{({\sum_{i} \sigma_(x_i)})^{2}}\]

where:

\[ x_T(t) = {\sum_{i=1}^{N} x_i(t))} \]

This measure of synchrony is standardized between 0 (perfect asynchrony) and 1 (perfect synchrony). A virtue of this metric is that it can be applied across communities of variable species richness. It can also be applied not only to species abundance but also population size and per capita growth rate. However, unlike the variance ratio it does not lend itself to significance testing. In addition, it will return similar values for communities shaped by different processes – for example, even if species vary independently, the synchrony metric may be affected by the number of species and individual species variances (K. Gross et al. 2014).

In `codyn`

, this is the default metric for the `synchrony`

function and can be easily calculated for multiple replicates in a dataset.

```
KNZ_synchrony_Loreau <- synchrony(df = knz_001d,
time.var = "year",
species.var = "species",
abundance.var = "abundance",
replicate.var = "subplot")
kable(head(KNZ_synchrony_Loreau))
```

subplot | synchrony |
---|---|

A_1 | 0.114 |

A_2 | 0.123 |

A_3 | 0.040 |

A_4 | 0.117 |

A_5 | 0.143 |

B_1 | 0.107 |

If there are no replicates within the dataset allow the `replicate.var`

argument to default to `NA`

.

```
KNZ_A1_synchrony_Loreau <- synchrony(df = subset(knz_001d, subplot=="A_1"),
time.var = "year",
species.var = "species",
abundance.var = "abundance")
KNZ_A1_synchrony_Loreau
```

[1] 0.114

Gross et al. (2014) developed a metric of synchrony that compares the average correlation of each individual species with the rest of the aggregated community:

\[ Synchrony = (1/N){{\sum_{i}Corr(x_i, \sum_{i\neq{j}}{x_j})}}\]

This measure of synchrony is standardized from -1 (perfect asynchrony) to 1 (perfect synchrony) and is centered at 0 when species fluctuate independently. A virtue of this metric is it not sensitive to richness and has the potential for null-model significance testing. It may under-perform on short time series because it is based on correlation, and care should be taken when applying it to communities that contain very stable species (i.e., whose abundances do not change throughout the time series).

In `codyn`

, this metric is calculated with the `Gross`

option in the `synchrony`

function and can be easily calculated for multpile replicates in a dataset. If a species does not vary over the course of the time series `synchrony`

will issue a warning and will remove that species from the calculation.

```
KNZ_synchrony_Gross <- synchrony(df = knz_001d,
time.var = "year",
species.var = "species",
abundance.var = "abundance",
metric = "Gross",
replicate.var = "subplot")
```

```
## Warning in FUN(X[[i]], ...): One or more species has non-varying abundance
## within a subplot and has been omitted
```

`kable(head(KNZ_synchrony_Gross))`

subplot | synchrony |
---|---|

A_1 | -0.019 |

A_2 | 0.031 |

A_3 | 0.011 |

A_4 | 0.009 |

A_5 | 0.069 |

B_1 | -0.023 |

If there are no replicates within the dataset allow the `replicate.var`

argument to default to `NA`

.

```
KNZ_A1_synchrony_Gross <- synchrony(df = subset(knz_001d, subplot=="A_1"),
time.var = "year",
species.var = "species",
abundance.var = "abundance",
metric = "Gross")
KNZ_A1_synchrony_Gross
```

[1] -0.0194

Qualititively, the degree to which the synchrony metrics calculated by `Loreau`

versus `Gross`

will differ depends on the abundance distributions of the species in a community. The `Loreau`

method and the variance ratio are both based on variances, and are therefore more heavily influenced by abundant species. In contrast, the `Gross`

method is based on correlation and consequently weights species equally.

Grman, Emily, Jennifer A. Lau, Donald R. Schoolmaster, and Katherine L. Gross. 2010. “Mechanisms Contributing to Stability in Ecosystem Function Depend on the Environmental Context.” *Ecology Letters* 13 (11): 1400–1410. doi:10.1111/j.1461-0248.2010.01533.x.

Gross, Kevin, Bradley J. Cardinale, Jeremy W. Fox, Andrew Gonzalez, Michel Loreau, H. Wayne Polley, Peter B. Reich, and Jasper van Ruijven. 2014. “Species Richness and the Temporal Stability of Biomass Production: A New Analysis of Recent Biodiversity Experiments.” *The American Naturalist* 183 (1): 1–12. doi:10.1086/673915.

Hallett, Lauren M., Joanna S. Hsu, Elsa E. Cleland, Scott L. Collins, Timothy L. Dickson, Emily C. Farrer, Laureano A. Gherardi, et al. 2014. “Biotic Mechanisms of Community Stability Shift Along a Precipitation Gradient.” *Ecology* 95 (6): 1693–1700. http://www.esajournals.org/doi/abs/10.1890/13-0895.1.

Harms, Kyle E., Richard Condit, Stephen P. Hubbell, and Robin B. Foster. 2001. “Habitat Associations of Trees and Shrubs in a 50-Ha Neotropical Forest Plot.” *Journal of Ecology* 89 (6). http://onlinelibrary.wiley.com/doi/10.1111/j.1365-2745.2001.00615.x/full.

Hector, A., Y. Hautier, P. Saner, L. Wacker, R. Bagchi, J. Joshi, M. Scherer-Lorenzen, et al. 2010. “General Stabilizing Effects of Plant Diversity on Grassland Productivity Through Population Asynchrony and Overyielding.” *Ecology* 91 (8): 2213–20. http://www.esajournals.org/doi/abs/10.1890/09-1162.1.

Houlahan, J. E., D. J. Currie, K. Cottenie, G. S. Cumming, S. K. M. Ernest, C. S. Findlay, S. D. Fuhlendorf, et al. 2007. “Compensatory Dynamics Are Rare in Natural Ecological Communities.” *Proceedings of the National Academy of Sciences* 104 (9): 3273–7. http://www.pnas.org/content/104/9/3273.short.

Loreau, Michel, and Claire de Mazancourt. 2008. “Species Synchrony and Its Drivers: Neutral and Nonneutral Community Dynamics in Fluctuating Environments.” *The American Naturalist* 172 (2): E48–E66. doi:10.1086/589746.

Schluter, Dolph. 1984. “A Variance Test for Detecting Species Associations, with Some Example Applications.” *Ecology* 65 (3): 998–1005. doi:10.2307/1938071.

Tilman, D. 1999. “The Ecological Consequences of Changes in Biodiversity: A Search for General Principles.” *Ecology* 80 (5): 1455–74. doi:10.1890/0012-9658(1999)080[1455:TECOCI]2.0.CO;2.