How to use the NetworkExtinction Package

M.Isidora Avila-Thieme and Derek Corcoran

2019-10-27

Introduction

The objectives of the NetworkExtinction package is to analyze and visualize the topology of food webs and its responses to the simulated extinction of species.

The main indexes used for these analyzes are:

  1. Number of nodes: Total number of species in the network (Dunne, Williams, and Martinez 2002).

  2. Number of links: Number of trophic relationships represented in the food web (Dunne, Williams, and Martinez 2002).

  3. Connectance: Proportion of all possible trophic links that are completed (Dunne, Williams, and Martinez 2002).

  4. Primary removals: It occurs when the researcher intentionally removes one species, simulating a single extinction.

  5. Secondary extinctions: A secondary extinction occurs when a non basal species loses all of its prey items due to the removal of another species. In this context, basal species can experience primary removal, but not secondary extinctions (Dunne, Williams, and Martinez 2002).

  6. Total extinctions: The sum of primary removal and secondary extinctions in one simulation.

This package was built with a total of six functions. There are four functions to analyze the cascading effect of extinctions in a food web, one function to plot the results of any of the extinction analysis, and another to analize the degree distribution in the network.

Functions to analyze the cascading effect of extinctions are the following:

The function to plot results is:

The function to analize the degree distribution is:

How to install the package

As any package in cran the install.packages function can be used to intall de NetworkExtinction package as shown in the following code.

How to represent a food web in R

The first step to make any analysis in the NetworkExtinction package is to build a representation of a food web, using the network package (Butts and others 2008).

In order to create a network object you can start with a matrix or an edgelist object (for more details see the network package vignette).

As an example of how to build a food web we will explain how to create the network shown in figure 1.

Figure 1. Food-web to be contructed in R

Figure 1. Food-web to be contructed in R

This network has ten nodes where each node represents one species. Here, four nodes are basal species (primary producers, from sp.1 to sp.4), three nodes are intermediate (primary consumers, from sp.5 to sp.7), and the remaining three are top predators (from sp.8 to sp.10).

In order to build an interaction matrix (Figure 2) that represent the food web, we create a square matrix with a column and a row representing each species. Columns represent the consumers and the rows the resources, where 1 represents a trophic interaction and 0 its absence. Note that in the columns, the first four species only have zeros because they are not consumers. For example, if we look at species 7, it feeds on species 4 and 3. In order to represent that, we would go to column 7 and put a 1 in rows 3 and 4.

Figure 2. Matrix representation of the food web

Figure 2. Matrix representation of the food web

The following code is an example of how to build the matrix in figure 2 using R:

Once the matrix is ready, we use the as.network function from the network package to build a network object.

Functions

Extinctions functions

Extinctions from most to less conected species in the network

The Mostconnected function sorts the species from the most connected node to the least connected node, using total degree. Then, it removes the most connected node in the network, simulating its extinction, and recalculates the topological indexes of the network and counts how many species have indegree 0 (secondary extinction), not considering primary producers. Then, it removes the nodes that were secondarily extinct in the previous step and recalculates which node is the new most connected species. This step is repeated until the number of links in the network is zero (Sole and Montoya 2001; Dunne, Williams, and Martinez 2002; Dunne and Williams 2009).

#> [1] 1
#> [1] 2
#> [1] 3
#> [1] 4
Table 1: The resulting dataframe of the Mostconnected function
Spp nodesS linksS Conectance LinksPerSpecies Secondary_extinctions Predation_release isolated_nodes AccSecondaryExtinction NumExt TotalExt
6 9 7 0.0864198 0.7777778 1 0 1 1 1 2
7 7 4 0.0816327 0.5714286 0 2 2 1 2 3
5 6 2 0.0555556 0.3333333 1 3 3 2 3 5
2 4 0 0.0000000 0.0000000 1 3 4 3 4 7

The result of this function is the dataframe shown in table 1. The first column called Spp indicates the order in which the species were removed simulating an extinction. The column Secondary_extinctions represents the numbers of species that become extinct given that they do not have any food items left in the food web, while the AccSecondaryExtinction column represents the accumulated secondary extinctions. (To plot the results, see function ExtinctionPlot.)

Figure 3. The graph shows the number of accumulated secondary extinctions that occur when removing species from the most to the least connected species

Figure 3. The graph shows the number of accumulated secondary extinctions that occur when removing species from the most to the least connected species

Extinctions using a customized order

The ExtinctionOrder function takes a network and extinguishes nodes using a customized order. Then, it calculates the topological network indexes and the secondary extinctions.

Table 2: The resulting dataframe of the ExtinctionOrder function
Spp nodesS linksS Conectance Secondary_extinctions Predation_release AccSecondaryExtinction NumExt TotalExt
2 9 8 0.0987654 1 0 1 1 2
4 7 5 0.1020408 1 0 2 2 4
7 5 3 0.1200000 0 1 2 3 5
Figure 4. The graph shows the number of accumulated secondary extinctions that occur when removing species in a custom order. In this example species 2 is removed followed by 4 and lastly species 7 is removed

Figure 4. The graph shows the number of accumulated secondary extinctions that occur when removing species in a custom order. In this example species 2 is removed followed by 4 and lastly species 7 is removed

The results of this function are a dataframe with the topological indexes of the network calculated from each extinction step (Table 2), and a plot that shows the number of accumulated secondary extinctions that occured with each removed node (Figure 4).

Random extinction

The RandomExtinctions function generates n random extinction orders, determined by the argument nsim. The first result of this function is a dataframe (table 3). The column NumExt represents the number of species removed, AccSecondaryExtinction is the average number of secondary extinctions for each species removed, and SdAccSecondaryExtinction is its standard deviation. The second result is a graph (figure 5), where the x axis is the number of species removed and the y axis is the number of accumulated secondary extinctions. The solid line is the average number of secondary extinctions for every simulated primary extinction, and the red area represents the mean \(\pm\) the standard deviation of the simulations.

Table 3: The resulting dataframe of the RandomExtinctions function
NumExt SdAccSecondaryExtinction AccSecondaryExtinction
1 0.4184520 0.220000
2 0.7623808 0.520000
3 0.9691149 0.860000
4 1.0821370 1.180000
5 1.1383841 1.530612
6 1.1946852 1.933333
7 1.1407225 2.176471
8 1.0681880 1.846154
9 1.3038405 1.800000
Figure 5. The resulting graph of the RandomExtinctions function

Figure 5. The resulting graph of the RandomExtinctions function

Comparison of Null hypothesis with other extinction histories

The RandomExtinctons function generates a null hypothesis for us to compare it with either an extinction history generated by the ExtinctionOrder function or the Mostconnected function. In order to compare the expected extinctions developed by our null hypothesis with the observed extinction history, we developed the CompareExtinctions function. The way to use this last function is to first create the extinction history and the null hypothesis, and then the CompareExtinctins function to compare both extinction histories.

The first result will be a graph (Figue 6) with a dashed line showing the observed extinction history and a solid line showing the expected value of secondary extinctions randomly generated.

The second result will be a Test object which will show the goodness of fit statistics of the comparison. In this case, since the p value is 0.22 which is larger than 0.05, we consider that the generated extinction history is significantly different than the null hypothesis.

Figure 6. The resulting graph of the CompareExtinctions function, where the dashed line shows the observed extinction history, and a solid line shows the expected value of secondary extinctions originated at random

Figure 6. The resulting graph of the CompareExtinctions function, where the dashed line shows the observed extinction history, and a solid line shows the expected value of secondary extinctions originated at random

Plotting the extinction histories of a network

The ExtinctionPlot function takes a NetworkTopology class object and plots the index of interest after every extinction. By default, the function plots the number of accumulated secondary extinctions after every primary extinction (Figure 7), but any of the indexes can be ploted with the function by changing the Variable argument (Figure 8).

Figure 7. Example of the use of the ExtinctionPlot function showing the accumulated secondary extinctions against number of extinctions

Figure 7. Example of the use of the ExtinctionPlot function showing the accumulated secondary extinctions against number of extinctions

Figure 8. Another example of the use of the ExtinctionPlot function showing the number of links per species against number of extinctions

Figure 8. Another example of the use of the ExtinctionPlot function showing the number of links per species against number of extinctions

Degree distribution function

The degree_distribution function calculates the cumulative distribution of the number of links that each species in the food network has (Estrada 2007). Then, the observed distribution is fitted to the exponential, power law and truncated power law distribution models.

The results of this function are shown in figure 9 and table 4. The graph shows the observed degree distribution in a log log scale fitting the three models mentioned above, for this example we use an example dataset of Chilean litoral rocky shores (Kéfi et al. 2015). The table shows the fitted model information ordered by descending AIC, that is, the model in the first row is the most probable distribution, followed by the second an finally the third distribution in this case (Table 3), the Exponential distribution would be the best model, followed by the Power law and finally the Truncated power law model.

Figure 9: Fitted vs observed values of the degree distribution. The black line and points show the observed values, the red, green and blue lines show the fitted values for the Exponential, power law and trucated distribution, respectively

Figure 9: Fitted vs observed values of the degree distribution. The black line and points show the observed values, the red, green and blue lines show the fitted values for the Exponential, power law and trucated distribution, respectively

Table 4: Model selection analysis
logLik AIC BIC model Normal.Resid
83.147529 -160.295059 -153.636536 Exp No
5.420293 -6.840586 -2.461276 Power No
-9.281940 26.563879 35.322498 LogTruncated No
-27.482221 60.964443 67.533407 LogExp No
-45.321942 94.643884 99.023194 Truncated No
-80.841717 167.683433 174.252397 LogPower No

The main objective of fitting the cumulative distribution of the degrees to those models, is to determine if the vulnerability of the network to the removal of the most connected species is related to their degree distribution. Networks that follow a power law distribution are very vulnerable to the removal of the most connected nodes, while networks that follow exponential degree distribution are less vulnerable to the removal of the most connected nodes (Albert and Barabási 2002; Dunne, Williams, and Martinez 2002; Estrada 2007; Santana et al. 2013).

Bibliography

Albert, Réka, and Albert-László Barabási. 2002. “Statistical Mechanics of Complex Networks.” Reviews of Modern Physics 74 (1). APS: 47.

Butts, Carter T, and others. 2008. “Network: A Package for Managing Relational Data in R.” Journal of Statistical Software 24 (2): 1–36.

Dunne, Jennifer A, and Richard J Williams. 2009. “Cascading Extinctions and Community Collapse in Model Food Webs.” Philosophical Transactions of the Royal Society B: Biological Sciences 364 (1524). The Royal Society: 1711–23.

Dunne, Jennifer A, Richard J Williams, and Neo D Martinez. 2002. “Food-Web Structure and Network Theory: The Role of Connectance and Size.” Proceedings of the National Academy of Sciences 99 (20). National Acad Sciences: 12917–22.

Estrada, Ernesto. 2007. “Food Webs Robustness to Biodiversity Loss: The Roles of Connectance, Expansibility and Degree Distribution.” Journal of Theoretical Biology 244 (2). Elsevier: 296–307.

Kéfi, Sonia, Eric L Berlow, Evie A Wieters, Lucas N Joppa, Spencer A Wood, Ulrich Brose, and Sergio A Navarrete. 2015. “Network Structure Beyond Food Webs: Mapping Non-Trophic and Trophic Interactions on Chilean Rocky Shores.” Ecology 96 (1). Wiley Online Library: 291–303.

Santana, Charles N de, Alejandro F Rozenfeld, Pablo A Marquet, and Carlos M Duarte. 2013. “Topological Properties of Polar Food Webs.” Marine Ecology Progress Series 474: 15–26.

Sole, Ricard V, and M Montoya. 2001. “Complexity and Fragility in Ecological Networks.” Proceedings of the Royal Society of London B: Biological Sciences 268 (1480). The Royal Society: 2039–45.