fluxweb: An R package to easily estimate energy fluxes in food webs
Abstract
- Understanding how changes in biodiversity will impact the stability and functioning of ecosystems is a central challenge in ecology. Food web approaches have been advocated to link community composition with ecosystem functioning by describing the fluxes of energy among species or trophic groups. However, estimating such fluxes remain problematic because current methods become unmanageable as network complexity increases.
- We developed a generalization of previous indirect estimation methods assuming a steady-state system (Hunt et al., 1987, 1995, 2018); the model estimates energy fluxes in a top-down manner assuming system equilibrium; each node's losses (consumption and physiological) balances its consumptive gains. Jointly, we provide theoretical and practical guidelines to use the fluxweb R package (available on CRAN at https://cran.rproject.org/web/packages/fluxweb/index.html). We also present how the framework can merge with the allometric theory of ecology (Brown, Gillooly, Allen, Savage, & West, 2004; to calculate fluxes based on easily obtainable organism-level data (i.e., body masses and species groups—e.g., plants, animals), opening its use to food webs of all complexities. Physiological losses (metabolic losses or losses due to death other than from predation within the food web) may be directly measured or estimated using allometric relationships based on the metabolic theory of ecology, and losses and gains due to predation are a function of ecological efficiencies that describe the proportion of energy that is used for biomass production.
- The primary output is a matrix of fluxes among the nodes of the food web. These fluxes can be used to describe the role of a species, a function of interest (e.g., predation; total fluxes to predators), multiple functions, or total energy flux (system throughflow or multitrophic functioning). Additionally, the package includes functions to calculate network stability based on the Jacobian matrix, providing insight into how resilient the network is to small perturbations at steady state.
- Overall, fluxweb provides a flexible set of functions that greatly increase the feasibility of implementing food web energetic approaches to more complex systems. As such, the package facilitates novel opportunities for mechanistically linking quantitative food webs and ecosystem functioning in real and dynamic natural landscapes.
1 INTRODUCTION
In recent years, there have been multiple calls for the reconciliation of food web structure and ecosystem functioning, to better understand how changes to ecological networks will influence the stability and functioning of ecosystems (Duffy et al., 2007, 2012, 2015). Energetic food web approaches can be used to quantify a key aspect of ecosystem functioning, energy flux, as a way of characterizing ecological processes that are driven by trophic interactions among nodes in food webs (O’Neill, 1969, 1987, 2014). As such, energy fluxes can be used to quantify functions such as herbivory or productivity. They can also be integrated into the classical framework of Lotka–Volterra equations to estimate stability (Neutel et al., 2007, 2017).
Despite interest in using quantitative networks (Berlow et al., 2004, 2009, 2010), they are still rarely employed for describing natural communities. This is, in part, because quantifying interaction strengths or fluxes in food webs remains a deceptively difficult problem, often requiring intensive experimental and observational efforts. A viable solution is to use mathematical proxies for system, and/or organismal level parameters for calculating energy fluxes through networks based on easily accessible parameters, rather than attempting to measure flux through the whole network. At the system level, for example, inverse matrix reconstruction (commonly referred to as “ecological network analysis”) (Vézina & Piatt, 1988, 2014), or the “food web energetics approach” (Hunt et al., 1987, 1995, 2018) have gained some support. These approaches, which are both based on the same steady-state assumption (i.e., populations are at equilibrium densities), require reasonable knowledge of the focal system such as network topology. However, a major difference relates to the solution provided by these two methods. The ecological network analysis produces an infinite number of solutions and requires an a posteriori selection function. In contrast, the web energetic approach assumes that fluxes are driven by a top-down effect (energetic demand of predators drive their ingoing fluxes) to guarantee a unique solution for each dataset. Previously, however, scientists using the “food web energetics” approach (de Ruiter et al., 1995, 2014, 2016), have manually calculated fluxes, which can become exceedingly unmanageable as the complexity of the food web increases. Therefore, there is urgent need for a generalized automation of this method.
Interaction strengths can also be quantified by focusing on organism-level parameters related to the metabolic theory of ecology (Brown et al., 2004). Generalized allometric approaches utilize general patterns of functional responses that depend upon body size ratios between consumers and their resources (Vucic-Pestic, Rall, Kalinkat, & Brose, 2010, 2011), opening ways for determining interaction strengths in response to commonly available data such as the abundances and body masses. Allometric rules have been successfully applied to predict fluxes in simplified systems with a few species (Brose et al., 2008). However, these results have not yet been generalized for use in complex networks.
Here, we present the methodological and mathematical framework that underlies the food web energetics approach and provide theoretical and practical guidelines for using the fluxweb R package. We then show how the framework presented here can easily merge with the allometric theory to estimate energy fluxes in complex natural food webs. In doing so, we support proposals to create a framework allowing for the estimation of energy fluxes in trophic networks using widely available ecological information such as biomass, metabolic demand, ecological efficiencies, or network topology (Hines et al., 2015).
2 THE UNDERLYING MODEL




- Efficiencies depending on predator identity
F is the vector such that Fi describes the sum of ingoing fluxes to species i, e is the vector of feeding efficiencies, such that ei describes the efficiency of a predator i (see related paragraph in Section 3 for more precise definitions of feeding efficiencies) with ei = 0 if i is basal. W is the matrix such that Wij sets the proportion of ingoing fluxes to species j from species i and X is the vector defining the sum of energetic losses for each species.
(5)
- Efficiencies depending on prey identity
In this case, e is the vector such that ei expresses a prey-related efficiency.
(6)
is a vector such that bi is equal to 1 if species i is basal, 0 if it is not basal. The addition of this last vector is needed to solve the system. Ecologically, it simulates the addition of a nutrient node on which all basal species feed with an efficiency of 1.
- Efficiencies depending on link identity (both prey and predator)
Here,
(7)
is a vector of ones, U is the matrix defined by the element-wise multiplication of matrices W and e: Uij = Wijeij. e is a matrix such that eij is the assimilation efficiency of species j feeding on species i.
3 DEFINING THE PARAMETERS
A great advantage of the food web energetics method is that it offers a flexible quantitative framework that can be used to test many different ecological hypotheses related to fluxes in networks (Moore & de Ruiter, 2012, 2018). Parameters used to configure the model can be taken from the literature, estimated from direct field measurement or assessed from general scaling relationships using easily accessible species (e.g., body size) and/or environmental (e.g., temperature) information. Therefore, the fluxweb package is a tool that is highly applicable for both experimental/empirical approaches aiming to describe natural systems and for theoretical approaches requiring generic solutions.
In the following section, we will describe the different parameters needed and how they can be estimated (see Table 1 for examples). Physiological losses (Xi): Depending on user assumptions and choices, different ecological processes can be used. Classical choices are often:
Symbol | Parameter name | Description | Unit used in the case studies |
---|---|---|---|
X i | Physiological losses | Total amount of energy loss related to physiology for population i | J/year |
e ij | Feeding efficiencies | Dimensionless (proportion) | |
B i | Total biomass of populations i | g | |
F ij | Energy flux from species i to species j | J/year | |
w ij | Absolute preference of species j for species i | Dimensionless | |
W ij | Scaled preference of species j for species i | Sum over j of wij equals 1. Can be scaled or not with prey abundances | Dimensionless (proportion) |

Efficiencies (e): fluxweb offers the possibility to use a variety of input parameters that define energetic losses, for which different aspects of ecological efficiency must be employed. If the metabolic rate is used to parameterize energetic loss, then the assimilation efficiency must also be provided (i.e., the proportion of consumed energy that is assimilated for respiration and biomass production). If mass-specific death rates are used in place of metabolism (sensu (Moore et al., 2012)), users should use the product of assimilation efficiency and production efficiency (percentage of assimilated energy that is used for biomass production). The fluxweb package offers three different options for defining ecological efficiencies: consumer-defined, resource-defined, or link-defined (considering both predator and prey identity) efficiencies. These options correspond, respectively, to the values pred, prey, and link.specific for the ef.level argument. If, within a single study, each consumer has a relatively homogeneous resource pool (i.e., consumers are trophic specialists such as strict herbivores or strict carnivores), defining efficiencies at the consumer level could be the standard option. However, if a single consumer node draws on a variety of resource nodes (e.g., plants, detritus, and animals), efficiencies can be defined at the resource level to account for differences in resource quality ingested by a consumer species. For this last approach, efficiency values that relate to the different groups of organisms can be found in the literature (Lang, Ehnes, Brose, & Rall, 2017).

Species biomasses (B): Biomasses are used (depending on user choices) to scale losses (if they are provided per biomass unit) and preferences. It is therefore an optional parameter.
4 FLUXWEB FUNCTIONALITIES
Above we presented the theoretical background used by fluxweb to determine fluxes in food webs with the fluxing function. However, the package offers several other possibilities (Table 2). Under the steady-state assumption, it is quite straightforward to relate estimated fluxes to the equilibrium state of a set of ordinary differential equations depicting population dynamics (Lotka–Volterra systems of equations). This offers the possibility to gain insight into network stability using the methods established for such equation systems (Neutel et al., 2007). Thus, the fluxweb package offers the stability.value and make.stability functions using the concept of resilience to quantify the stability of a network with fluxes (see Supporting Information II for more explanations and the mathematical derivation). The second functionality provided is a sensitivity analysis of outputs regarding the parameters. The sensitivity function allows one to assess how the outputs of functions from the package are sensitive to a specified parameter.
Function | Description | Arguments |
---|---|---|
fluxing | Compute energy fluxes in networks | Interaction matrix (including preferences if provided) |
Physiological losses | ||
Feeding efficiencies | ||
Species biomasses (optional) | ||
stability.value | Return stability of the network of flux (resilience) | Interaction matrix of fluxes |
Species biomasses | ||
Physiological losses | ||
Feeding efficiencies | ||
Growth rate | ||
make.stability | Return the smallest multiplicative scalar of losses insuring network stability (i.e., producing negative resilience) | Interaction matrix of fluxes |
Species biomasses | ||
Physiological losses | ||
Feeding efficiencies | ||
Growth rate | ||
sensitivity | Compute the sensitivity of a function to an argument | Function to analyse |
Parameter to analyse | ||
Interval of uncertainty for the parameter | ||
Number of replicates to use | ||
Set of parameters needed by the function |
5 USING FLUXWEB
The package can be installed from CRAN using the install.packages(’fluxweb’) command and more information is accessible on CRAN at https://cran.rproject.org/web/packages/fluxweb/index.html. Development version is available on Github at https://github.com/gauzens/fluxweb. Within the fluxweb package, we provide three complete case studies corresponding to different levels of trophic complexity (Figure 1). The first example consists of a network of 62 nodes resolved to the species level and 573 edges depicting trophic interactions among soil mesofauna in a German beech forest (for details see Digel, Curtsdotter, Riede, Klarner, & Brose, 2014). As is often the case for species-level resolved networks, we only have a binary description of interactions (neither weight of trophic links nor feeding preferences are available). The network corresponding to the intermediate level of complexity is a version of the species-level network where species were aggregated in trophic groups using a group detection method (Gauzens, Thébault, Lacroix, & Legendre, 2015). Reducing complexity by forming aggregated groups can be used to gain basic estimates of predator foraging preferences. Here, preferences were estimated by the aggregation process: the foraging preference of a trophic group j on a trophic group i is defined as the number of predation links from species of group j on species of group i. The simple case corresponds to a mesocosm of four species (one resource, two herbivores, and a consumer of the two herbivores) assembled from the Chesapeake Bay river estuary (Lefcheck et al., 2015). Data used for the species-level food web, the group-level food web, and the simple case can be accessed using the species.level, groups.level, and simple.case lists respectively. Each of these lists contains all the necessary information to estimate fluxes. They are automatically loaded with the package.
5.1 Species-level network
The different parameters of this dataset are:

- The network binary adjacency matrix: value of line i and column j is 1 if species j feeds on species i, 0 otherwise: species.level$mat
- The vector of total species biomasses (g): species.level$biomasses
- The vector of average species body masses (g): species.level$bodymasses
- The vector of assimilation efficiencies: species.level$efficiencies
We used species metabolic rates to define energetic losses related to physiology (eq. 8), with parameter x0 = 0.71 and b = −0.25 according to (Brown et al., 2004). Values obtained are in joules per second and then scaled to joules per year.
5.2 Group-level network
Data provided here are similar to the ones used for the species.level list. Body mass of a group is defined as the average body mass of species belonging to this group. group biomass is defined as the sum of species biomass from the group. In addition, the list contains the species.tgs data frame indicating the identity of species in each trophic group.
5.3 Simple-case network
- The network binary adjacency matrix: value of line i and column j is 1 if species j feeds on species i, 0 otherwise: simple.case$mat
- The vector of species biomasses (g): simple.case$biomasses
- The vector of species metabolic rates (j.year): simple.case$metabolic.rates
- The vector of assimilation efficiencies: simple.case$efficiencies
5.4 Fluxweb function examples
The different datasets can be loaded using the load() function and elements can thereafter be directly accessed after a use of the attach() function. For the species and group level examples, species metabolic losses (per unit of biomass) have to first be estimated with eq. 8:
For these three cases, the matrix of fluxes is simply computed through the call to the fluxing function:
Here, bioms.prefs = TRUE specifies that species preferences depend on prey abundances (eq. 9). The bioms.losses argument is set to TRUE to compute metabolic losses for species populations (as they are provided per unit biomass). For the example from the mesocosm experiment, as metabolic rates were directly measured, this has to be switched to FALSE. The ef.level argument is set to prey as efficiencies provided in these datasets depends on prey identities.
In the same way, the stability of the food web of fluxes is returned by the stability.value function: with the addition of a vector of growth rates for basal species (parameter growth.rates), determined using the classic allometric equation (eq. 8).
6 FROM DATA SAMPLING TO FUNCTIONS
As a very simple example how to convert community data into quantitative fluxes, we propose guidelines for experimental ecologists who want to use fluxweb under the assumptions of the metabolic theory of ecology.
6.1 Preparing the data
- a matrix defining the set of trophic interactions between each species pair of the ecological system considered (hereafter called food.web).
- A vector with the average body masses of species (in g, hereafter called bodymasses).
- A vector with the total biomass of each population (in g, hereafter called biomasses).
- A vector with the organism type (i.e., plant, animal or detritus) of each species (hereafter called org.types).
Then, a vector of metabolic types (as defined in Table 3) of each species (thereafter called met.types) is not mandatory to calculate fluxes but is a set of easily accessible information that can increase the precision of metabolic rate estimations.
Metabolic type | Intercept(x0) | Exponent (b) |
---|---|---|
Ectotherm vertebrates | 18.18 | −0.29 |
Endotherm vertebrates | 19.5 | −0.29 |
Invertebrates | 17.17 | −0.29 |
All of these details will allow the definition the mandatory arguments needed to calculate the fluxes: the food web (the matrix food.web), the physiological losses (vector losses), and the efficiencies (vector efficiencies).
6.1.1 food.web
Information about the food web is the first parameter required by the fluxing function. It should be a matrix (thereafter called mat) of n rows and n columns, where n is the total number of species involved in the study. The order of species should be identical between rows and columns. A non-zero value at the intersection of line i and column j in the food web matrix means that predator j consumes prey i. The values used to fill this matrix can be either binary (0/1) assuming that predators’ foraging preferences on their prey are unknown, or real values, defining these foraging preferences.
6.1.2 losses


It is possible to obtain a more precise estimation of species metabolic rates, considering the parameters of Table 3 defined for each entry of the vector met.types. Then, the definition of the vector losses containing species’ metabolic rates can be achieved with:
It is important to note that the calculation of metabolic rates using the equations from the metabolic theory of ecology (8) leads to values were units are per-gram of biomass, they do not correspond to the total energetic losses of the entire populations (which can be obtained by multiplied the per-gram of biomass rates by the total biomass of the population). It is quite common in food webs to have nodes such as “detritus” or “dissolved organic matter.” Values for the metabolic rates of such nodes can be set to NA if they are basal and zero in any case.
6.1.3 efficiencies
The last parameter needed to estimate fluxes is the vector of feeding efficiencies. Because species’ physiological losses were estimated using metabolic rates, assimilation efficiencies should be used (assimilation efficiency defines the proportion of eaten biomass that can be used for biomass production plus metabolism (Lang et al., 2017). These efficiencies can be defined using basic information on organism types. Indeed, the efficiency with which a predator will assimilate energy from a prey can be defined by the type of prey eaten. Considering a vector org.type defining the organism types of food web nodes as “animal,” “plant,” or “detritus,” efficiency values for these three categories are respectively 0.906, 0.545, and 0.158 (Lang et al., 2017). The vector of efficiencies can be created like:
6.2 Calculating fluxes

- bioms.pref = TRUE will scale the species diet preferences (i.e., the values from the food web matrix mat) to the biomasses of their prey, according to this equation:
where Wi,j is the scaled preference of predator j on prey i
(10)
- bioms.losses = TRUE will calculate the total losses of species as the product of the term by term product of the vectors losses and biomasses. Thus, setting this option to TRUE corresponds to a dataset were species’ metabolic losses where defined per unit of biomass. If species losses where directly measured at the population scale (using some respiration measurement for example), this parameter should be set to FALSE.
- ef.level = "prey" will assume that the species efficiencies are defined according to prey (i.e., for each species, it is the efficiency with which it will be assimilated once it has been preyed upon).
Using this methodology to compute fluxes with the species.level example (Figure 2) dataset would lead to the following lines of code:

6.3 From fluxes to functions
Once the matrix of fluxes is obtained, it is possible to estimate some ecosystem functions such as herbivory, detritivory, or carnivory. In the following, we will define them as the sum of fluxes outgoing from plant, detritus, and animal nodes respectively. It is important to note that the fluxes estimated by the fluxing function correspond to energy loss from resource nodes. They differ from the energy assimilated by consumer nodes due to assimilation efficiencies. Thus, functions from the species.level example (Figure 3) can be estimated by simple sum operations on the mat.fluxes:

7 CONCLUSION
The R package fluxweb provides a set of methods allowing the calculation of energy fluxes in food webs based on the conceptual framework of the “food web energetics” approach (de Ruiter et al., 1995, 2014, 2016, 2018). Fluxes within a system, which have typically been estimated in highly aggregated compartments, can now be quickly calculated at the species level or grouped as appropriate by users to match their objectives. This provides an advance to mechanistically understand how changes in biodiversity may impact ecosystem functioning (Thompson et al., 2012), and is timely given the increasing amount and complexity of ecological network data being collected over environmental and disturbance gradients (Gauzens, Legendre, Lazzaro, & Lacroix, 2016, 2017).
Under the assumption of biomass equilibrium, multiple aspects of ecosystem function can be investigated owing to the package's flexibility in the processes represented by parameters, their units, and how the outputs are interpreted. Function parameters can be estimated from general allometric relationships suitable for abstract models or tuned accordingly to precise measurement of specific systems depending on the users’ aims and on the availability of project-specific measurements or system-specific literature values. It is also possible to drop the hypothesis of equilibrium in case of the use of temporal dataset by adding changes of species biomass in time to the loss parameter. The impact of these estimations on ecological inferences can be assessed with the sensitivity function (Supporting Information III).
Several ecosystem functions can easily be estimated. For example, primary production can be defined as the sum of fluxes outgoing from plant species (Shaopeng & Ulrich, 2017) (because outgoing fluxes from plants must be balanced by ingoing fluxes, thus providing an indication for total uptake by plants). Hypotheses regarding the effect of network structure or community composition on a single function (or multiple single functions; multifunctionality) can also be tested, such as secondary production by herbivores or decomposition by detritivores (Barnes et al.,2014, 2018). Assessing such fluxes is important because they are directly linked to ecosystem services but may be mismatched with the standing-stock biomass of these species or trophic groups (Barnes et al., 2014). Additionally, whole-system flux, the sum of the entire fluxing matrix, can be used as a single value representing the emergent property of multitrophic functioning (Barnes et al., 2014).
The functions of fluxweb also offer several distinct but related ways to examine network stability that are important in the face of global changes and species loss. First, the biomass fluxes can be interpreted as link weights, and used to assess the distribution of interaction strengths in the network. Second, the stability function returns the network resilience, its ability to return to its equilibrium state following a small perturbation (see Supporting Information II). Overall, the fluxweb package thus offers important tools for research on quantitative food webs and ecosystem functioning in real and dynamic natural landscapes (Brose & Hillebrand, 2016).
ACKNOWLEDGEMENTS
M.J., D.P.G., and A.B. were supported by the German Research Foundation within the framework of the Jena Experiment (FOR 1451). M.J. acknowledge the Swiss National Science Foundation. U.B., A.B., D.P.G., J.H., B.R., S.W., and B.G. gratefully acknowledge the support of the German Centre for Integrative Biodiversity Research (iDiv) Halle-Jena-Leipzig funded by the German Research Foundation (FZT 118). B.G. thanks Stéphane Legendre for helpful discussions at the beginning of this project.
AUTHORS’ CONTRIBUTIONS
B.G. wrote the first draft of the manuscript and developed the fluxweb package. A.B. and B.G. designed the study. B.R., S.W., and B.G. developed the mathematical framework. All authors made substantial revisions and comments to the manuscript.
DATA ACCESSIBILITY
The code of the fluxweb package is accessible on both CRAN: cran.rproject.org/web/packages/fluxweb/index.html and Github for development version: github.com/gauzens/fluxweb