## Abstract

We release here the *fluxweb* package (https://github.com/gauzens/fluxweb.git) which merges allometric theory [1] with food web energetics methods [2, 3] to provide a set of functions that estimate energy fluxes in complex food webs based on easily accessible ecological informations. Overall, the *fluxweb* package offers some tools for research on quantitative food webs and ecosystem functions, which facilitates novel research on ecosystem functions 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 [4, 5, 6]. 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 [7, 2, 8]. Furthermore, energy fluxes can be used to quantify interaction strengths in food webs.

Despite interest in using quantitative networks [9, 10, 11] 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 example, at the system level inverse matrix reconstruction (commonly referred to as ‘ecological network analysis’), [12, 13] or the ‘food web energetics approach’ [2, 3] 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 like network topology. That is, some fluxes must be known for the inverse matrix approach, while the food web energetic assume a top down view (energetic need of predators drive their ingoing fluxes). A major difference relates to the solution provided by the methods. While ecological network analysis produces an infinite number of solutions and requires an a posteriori selection function, the method of the food web energetic approach guarantees a unique solution for each dataset. Previously, however, scientists using the ‘food web energetics’ approach [3, 8, 14], 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 important method.

Interaction strengths can also be quantified by focusing on organism-level parameters related to the metabolic theory of ecology [1]. Generalized allometric approaches utilize general patterns of functional responses that depend upon body size ratios [15, 16], opening ways for determining interaction strengths in response to commonly available data such as the abundances and body masses of resources and consumers. Allometric rules were successfully applied to predict fluxes in simplified systems with a few species [17]. However, these results have not yet been generalized for use in complex webs. Here we release the *fluxweb* R package (https://github.com/gauzens/fluxweb.git), which merges allometric theory [1] with food web energetics methods to provide a set of functions that estimate energy fluxes in complex food webs. In doing so, we support proposals to create a framework allowing the estimation of energy fluxes in trophic networks using widely available ecological information such as for example, biomass, metabolic demand, efficiencies or network topology [6].

## 2 The underlying model

The model assumes a steady state hypothesis. It implies that *L _{i},* the total amount of energy lost by a species

*i*, either by consumption or physiological processes, is exactly compensated by the metabolized energy it gains from consumption

*G*It will thus solve the equation knowing that and that gains are the part of ingoing fluxes once losses due to feeding efficiency are removed. where

_{i}.*X*defines energetic losses from species

_{i}*i*such as through metabolism, and

*F*is the flux from species

_{ij}*i*to species

*j*.

*e*defines a species’ feeding efficiency, subscript

*a*is, depending on the ecological assumption, equal to

*i*(when efficiency relates to the identity of the predator),

*j*(when efficiency relates to the identity of the prey) or

*ij*(when efficiency depends on both prey and predator). More details about parameters can be found in section 3. Any flux

*F*can be written as

_{ij}*F*=

_{ij}*W*, where

_{ij}F_{j}*F*is the sum of all ingoing fluxes to species

_{j}*j*, and

*W*defines the proportion of

_{ij}*F*that is obtained from species

_{j}*i*(Σ

*= 1), and can be obtained by scaling predator preferences*

_{i}W_{ij}*w*to the distribution of prey biomasses where

_{ij}*B*sets the biomass of species

_{i}*i*. We thus obtain the following model for determining each species’ sum of ingoing fluxes:

This equation is solved in two stages: first, the sum of ingoing fluxes for each species is computed. Then, individual fluxes for each pairwise predator-prey interaction are calculated using predator preferences (set in *W*).

The solution for eq. 5 depends on the chosen definition of feeding efficiency (assigned based on the predator, prey, or link identity) (see SI 1 for demonstrations) and is as follows:

Efficiencies depending on predator identity

*F*is the vector such that*F*describes the sum of ingoing fluxes to species_{i}*i, E*is the vector of feeding efficiencies, such that*E*describes the efficiency of a predator_{i}*i*(see related paragraph in section 3 for more precise definitions of feeding efficiencies) with*E*= 0 if_{i}*i*is basal,*W*is the matrix such that*W*sets the proportion of ingoing fluxes to species_{ij}*j*from species*i*and*X*is the vector defining the sum of energetic losses for each species.Efficiencies depending on prey identity In this case,

*E*is the vector such that*Ei*expresses a prey-related efficiency. is a vector such that*b*equals to 1 if species_{i}*i*is basal, 0 otherwise.Efficiencies depending on link identity (both prey and predator) Here, is a vector of ones,

*U*is the matrix defined by the term by term multiplication of matrices*W*and*E*:*U*=_{ij}*W*._{ij}E_{ij}*E*is a matrix such that*E*is the assimilation efficiency of species_{ij}*j*feeding on species*i*.

## 3 Defining the parameters

A great advantage of this method is that it offers a flexible quantitative framework that can be used to test many different ecological hypotheses related to fluxes in networks [18]. Parameters used to configure the model can be estimated from direct field measurement as well as 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 pure 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 example).

### Physiological losses

Depending on user assumptions and choices, different ecological processes can be used. Classical choices are often:

Metabolic rates [1]

Death rate [19]

Potentially more complex allometric functions, including time allocated to resting or hunting and associated energy costs [20]

Metabolic rates and death rates can be measured for simplified systems like in microcosms experiments (ref Jon). If the complexity of the network considered prevent such measurements, they can be estimated for each taxonomic group *i* using the classic allometric equation [1]
where *Y _{i}* represent a parameter related to the physiology of species

*i*.

*y*

_{0}and

*b*are constants associated with parameter

*Y*and

*M*is body mass. References for the choice of constant values associated with each model parameter can be found in the descriptions below. Depending on the amount of ecological information available, or precision required, parameters

_{j}*y*

_{0}and

*b*can be quite general (i.e., the same value for all species), or more specific (i.e., applying one parameter value per functional group, taxonomic group, or species). As

*Y*is typically estimated per unit biomass, setting the correct value for estimating energy flux is made by a simple multiplication by a species’ total biomass.

_{i}### Efficiencies

*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 using metabolic rate as an input parameter for energetic loss, assimilation efficiency, defined as the proportion of consumed energy that is assimilated (used in respiration and biomass production), needs to be provided. If mass-specific death rates are used in place of metabolism (sensu [18]), 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 *prey, pred* and *link.specific* for the *ef.level* argument. If, within a single study, each consumer has a relatively homogenous 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 the consumer species.

### Preferences

Preferences depict the feeding behavior of predator species and should quantify their foraging choices. Depending on system and user choice, they can be absolute preferences or per capita. The package thereafter offers the possibility to estimate or scale preferences using a linear scaling with prey biomass (like a type one functional response, eq. 4).

### Species biomasses

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 Other functionalities

Above we presented the theoretical background used by *fluxweb* to determine fluxes in food webs. However, the package offers several other possibilities. 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 Voltera like systems of equations). This offers the possibility to gain insight into network stability using the methods established for such equation systems. 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 SI 2 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 functions from the package are sensitive to a specified parameter.

## 5 Using *fluxweb*

Within the *fluxweb* package, we provide two complete case studies corresponding to different levels of trophic complexity (fig 1). The first example consists of a network of 62 nodes resolved to the species level and 573 edges depicting trophic interactions among mesofauna in forest soil (for details see [21]). As often for species resolved networks, we only have a binary description of interactions (no weight on trophic links nor feeding preferences are available). The network corresponding to the intermediate level of complexity is a version of the species resolved network where species were aggregated in trophic groups using a group detection method [22]. 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 *i* on a trophic group *j* is defined as the number of predation links from species of group *i* on species of group *j*. Data used for the species level-food web and the aggregated food web can be accessed using the *species.level* and *groups.level* lists respectively. Each of these lists contains all the necessary information to estimate fluxes. They are automatically loaded with the package.

### 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 species biomasses (g):

`species.level$biomasses`The vector of species body masses (g):

`species.level$bodymasses`The vector of assimilation efficiencies, related to prey identity. Values are 0.45 when prey is a plant, 0.85 when prey is an animal (these values are commonly used in allometric models of population dynamic; Delmas et al. 2016):

`species.level$efficiencies`

We used species metabolic rates to define energetic losses related to physiology (eq. 9).

### Network of trophic groups

Data provided here are similar to the ones used for the `species.level` list. Body mass of a group is defined as the average bodymass of species belonging to this group, group biomass as the sum. In addition, the list contains the `species.tgs` data frame indicating the species group composition.

### function examples

The different datasets can be loaded using the `load()` function and elements can be thereafter directly accessed after a use of the `attach()` function. In both cases, the matrix of fluxes is simply computed through the call to the *fluxing* function:

`species.fluxes = fluxing(mat, biomasses, metabolic.rates, efficiencies, bioms.prefs = TRUE, bioms.losses = TRUE, ef.level = ‘prey’)`

Here, `bioms.prefs = TRUE` specifies that species preferences depend on prey abundances (eq. 4), `bioms.losses = TRUE` specifies that the `metabolic.rates` input is defined per unit biomass, thus, total physiological losses have to be multiplied by species biomasses. In the same way, the stability of the food web of fluxes is returned by the *stability.value* function:

`stability.value(val.mat, biomasses, losses, efficiencies, growth.rates, bioms.prefs = TRUE, bioms.losses = TRUE, ef.level = ‘pred’)`

with the addition of a vector of growth rates for basal species (parameter `growth.rates`), determined using the classic allometric equation (eq. 9)

## 6 Conclusion

We presented here the R package *fluxweb*, providing a set of methods allowing the calculation of trophic fluxes in food webs based on the conceptual framework of the ‘food web energetics’ approach [3, 8, 14]. By automating the link between the identity and composition of interacting populations and energy fluxes, these methods facilitate the integration of community and ecosystem ecology. 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 is a much-needed advance to mechanistically understand how changes in biodiversity may impact ecosystem functioning [5], and is timely given the increasing number and complexity of ecological network data being collected over environmental and disturbance gradients [23, 24].

Under the equilibrium of biomasses assumption, 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. The impact of these estimations on ecological inferences can be assessed with the sensitivity function. The output of the function fluxing is a matrix of the fluxes between nodes. The sum of a single column can be used to assess the fluxes to a particular node of ecological interest, e.g. a top predator. Hypotheses regarding the effect of network structure or community composition on a single function(or multiple single functions; multifunctionality) can also be tested by summing multiple columns, such as secondary production by herbivores or decomposition by detritivores. Assessing such fluxes is important because they are directly linked to ecosystem services but may be mismatched with the standing biomass of these species or trophic groups [8]. Additionally, whole-system flux or throughput, the sum of the entire fluxing matrix, can be used as a single value representing the emergent property of multitrophic functioning [8]. This metric offers promise to assess mechanisms of BEF relationships in multitrophic communities, such as complementarity and selection effects [8].

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 use to assess the distribution of interaction strengths in the network. Second, the stability functions returns the network resilience, its ability to return to its equilibrium state following a small perturbation (see SI 2).

Overall, the *fluxweb* package thus offers some critically important tools for research on quantitative food webs and ecosystem functions, which facilitates novel research on ecosystem functions in real and dynamic natural landscapes [25].

## 7 Supplementary information I

### 7.1 Efficiency depending on predator identity

We will consider in the following that feeding efficiencies depend on predator identity. We define *E* as the vector of efficiencies and *W* as the matrix such that *W _{ij}* is the proportion of energy entering

*j*that is obtained from

*i*(Σ

_{j}

*W*= 1).

_{ij}*F*is the flux between species

_{ij}*i*and

*i*.

*L*, the energy loss of species

_{i}*j*is defined by: where

*s*is the number of species and

*X*are the physiological losses of species

_{i}*i*. Thus, for satisfying the equilibrium criteria,

*F*, the sum of fluxes entering

_{i}*i*is:

As *W _{ij}* set the proportion of energy entering

*j*obtained from species

*i*, using

*F*=

_{ij}*W*, we can write where values

_{ij}F_{j}*W*are estimated accordingly to species preferences (

_{ij}*ω*) and prey abundances:

_{ij}We then have:
which can be rewriten as:
where *diag*(*E*) is the diagonal matrix such as *diag*(*E) _{ii}* =

*E*. Provided that (

_{i}*diag*(

*E*) —

*W*) is invertible, the system solve as:

Then, all fluxes *F _{ij}* =

*W*are derived from

_{i}F_{j}*F*using

_{j}*W*.

### 7.2 defining efficiencies accordingly to prey identity

Another common method is to define feeding efficiencies accordingly to prey identity. This section proposes a method to adapt the previous framework to this case.

As preferences are defined at the prey level, we need to adapt the previous framework by simulating the addition of a nutrient node on which feed all basal species with en efficiency of one. Then, eq.5 becomes:
were *b _{i}* is 1 if

*i*is a basal species, 0 otherwise. This can be rewritten as: and, provided that is invertible, solved by:

### 7.3 defining efficiencies accordingly to the link level

It is possible to generalise this approach to efficiencies defined for each prey-predator couple. The solution needs the definition of matrix *U* such as *U _{ij}* =

*W*. The system then reads: where is the vector of ones. System is solved as:

_{ij}e_{ij}## 8 Supplementary information II

This document present how the fluxes calculated under the steady state hypothesis can easily be used to assess system stability, following the framework of Moore and De Ruiter. Here we use resilience as a definition of stability. Resilience is determined from the Jacobian matrix. The system is in a stable equilibrium only if the real parts of eigenvalues from the Jacobian are all negative. In this case, resilience is the absolute value of the real part of the larger eigenvalue. It is this value which is returned by the *stability* function from the fluxweb package

Another measure of stability, provided by the function *make.stability,* is to find the minimal value of a scalar *s* defining the proportion of physiological losses related to species density. In such case, physiological losses terms in the diagonal of the Jacobian matrix are now defined as *sX _{i}* and directly affect resilience value,

*s*being the measure of stability. We will show in the following section how fluxes at equilibrium can relate to a Lotka Voltera system in an equilibrium state, and how to compute the Jacobian matrix, first assuming that feeding efficiencies relates to predator identity and then assuming them to depend on prey identity.

### 8.1 Derivation of the Jacobian matrix

#### 8.1.1 preferences defined at predator level

*c _{ij}* is the coefficient of interaction between prey

*i*and predator

*j*and

*r*is the relative growth rate of producer

_{i}*i*.

*P*and

_{i}*p*define respectively the sets of prey and predator of species

_{i}*i*. This model assumes a type

*i*functional response

*f*defined as:

_{ij}As the whole method assumes that fluxes and biomasses are at an equilibrium state, we have:

denoting biomass of species *i* at equilibrium. Then, off diagonal elements *α _{ij}* from the Jacobian matrix correspond to the per capita effects (effect of one unit of species biomass). Considering the possible presence of cycles of length 1 (species

*i*is at the same time a prey and a predator of species

*j*), off diagonal elements are and at equilibrium, using we obtain:

Diagonal elements, considering possible cannibalistic loops, for producers (*p*) and consumers (*c*) are:
with *c _{ii}* ≠ 0 only if species

*i*is cannibalistic. Again, using and we obtain at equilibrium:

We can observe here that *α _{cc}* can be rewritten as
where

*F*sets the sum of fluxing ingoing species

_{i}*i*and

*L*its losses due to predation. As we assume a steady state hypothesis, ingoing fluxes compensate outgoing fluxes plus physiological losses:

_{i}*e*=

_{c}F_{i}*L*+

_{i}*X*. From that, we obtain:

_{i}#### 8.1.2 efficiencies defined at prey level

The Lotka Voltera system is now written as:

Here *e _{j}* defines efficiency of prey species

*j*. At equilibrium, off diagonal elements of the jacobian are like above:

Diagonal elements, considering possible cannibalistic loops, for producers (*p*) and consumers (*c*) are:
which, at equilibrium leads, like above, to:

#### 8.1.3 preferences defined at link level

following the same mathematical derivation as before, we obtain:

## Acknowledgements

M.J. was supported by the German Research Foundation within the framework of the Jena Experiment (FOR 1451) and by the Swiss National Science Foundation.