# Intro to fishflux

## Introduction

The fishflux package provides a tool to model fluxes of C (carbon), N (nitrogen) and P (phosphorus) in fishes. It combines basic principles from elemental stoichiometry and metabolic theory. The package offers a user-friendly interface to apply the model. fishflux is ideal for fish ecologists wishing to predict ingestion, egestion and excretion to study fluxes of nutrients and energy.

Main assets:

• Provides function to model fluxes of Carbon, Nitrogen and Phosphorus for fishes
• Allows for the estimation of uncertainty, dpending on the uncertainy of the input parameters
• Provides some functions to help find parameters as inputs for the model
• Provides functions to extract and illustrate results

fishflux uses Markov Chain Monte Carlo simulations provided by stan. Therefore, the first step is to install rstan. It’s important to closely follow all the steps described on the page depending on your operating system.

### GitHub

The best way to install the latest development version of fishflux is to install it from GitHub.

install.packages("devtools")
devtools::install_github("nschiett/fishflux", dependencies = TRUE) # if errors are returned, try adding args = "--preclean" to install_github
library(fishflux)

### CRAN

fishflux will be available on CRAN in the future:

install.packages("fishflux")
library(fishflux)

Another option is to download the source file available on GitHub here.

install.packages(path_to_fishflux_file, repos = NULL, type = "source")
library(fishflux)

## How to use fishflux?

fishflux is designed to follow three simple steps:

• Find the right input parameters
• Run the model simulation with those input parameters
• Plot the model results and check sensitivity

### Input parameters

Before running the model, the parameters have to be specified. Below, there is a table showing all parameters needed to run the model simulation. fishflux provides several functions to find some of these parameters, but note that others have to be provided by the user at this stage. Ideally, all parameters should also have a standard deviation, so that their uncertainty can be reflected in the model predictions

. Overview of inputs, including input parameters, to be specified by the user of the model. k indicates c, n or p. VBGC = von Bertalanffy growth curve.
Symbol Description Unit
ak Element-specific assimilation efficiency _
lt Total length of individual cm
linf Asymptotic adult length (VBGC) cm
κ Growth rate parameter (VBGC) yr − 1
t0 Age at settlement (VBGC) yr
lwa Parameter length-weight relationship g cm − 1
lwb Parameter length-weight relationship _
Qk Element-specific body content percentage %
f0 Metabolic normalisation constant independent of body mass g Cg − αd − 1
alpha Mass-scaling exponent _
theta Activity scope _
v Environmental temperature C
h trophic level _
r Aspect ratio of caudal fin _
F0nz Mass-specific turnover rate of N g Ng − 1d − 1
F0pz Mass-specific turnover rate of P g Pg − 1d − 1
mdw Ratio of dry mass and wet mass of fish _
Dk Elemental stoichiometry of diet %

A good place to start is checking if you are using the correct scientific name of your species of interest. The function name_errors will tell you if the species name is correct. This function can be useful, especially when working with larger databases.

# example
fishflux::name_errors("Zebrazoma scopas")
#> Inaccurate species names found:
#> [1] "Zebrazoma scopas"

Once the species names are verified and/or corrected we can continue with specifying some parameters.

The find_lw function searches FishBase to find length-weight relationship parameters lw_a and lw_b extracted from Froese and Pauly (2018).

# example
fishflux::find_lw("Zebrasoma scopas", mirror = "se")
#>            species   lwa_m     lwa_sd lwb_m    lwb_sd
#> 1 Zebrasoma scopas 0.02455 0.00269898  2.98 0.0255102

The model uses parameters von Bertalanffy’s growth model (VBGM) to estimate growth rates. A quick way to get available information from FishBase is the function growth_params(). This can be a good indication, but users should interpret these estimates with a critical eye, as they come from disparate sources of varying accuracy. Alternatively, it is advised to use growth curves derived from otolith readings. In the absence of otolith data, one might consider extracting standardised estimations from Morais and Bellwood (2018).

# example
# The option otolith=TRUE filters out sources that used otoliths for the estimation of growth parameters
fishflux::growth_params("Sargocentron microstoma", otolith = FALSE)
#> # A tibble: 1 x 7
#>   species           Locality                k  Linf    t0 method        comments
#>   <chr>             <chr>               <dbl> <dbl> <dbl> <chr>         <chr>
#> 1 Sargocentron mic… Tiahura reef, Moor…     1  18.6    NA length-frequ… <NA>

Further, there are a couple more basic functions to get an indication of parameters that are available on FishBase such as trophic_level() and aspect_ratio(). Note that it is always better to get the approximations through analysis, measurements and otolith analysis over parameters extracted from functions, such as growth_params(), trophic_level() and aspect_ratio(). To get an overview of all parameters available, fishflux provides a wrapper function model_parameters().

# example
zebsco <- fishflux::model_parameters("Zebrasoma scopas", family = "Acanthuridae", temp = 27, mirror = "se")
## Here we set the temperature at 27 degrees as an example, this the average sea temperature in Moorea, French Polynesia
print(zebsco)
#>            species    t0 Linf     k     asp troph   lwa_m     lwa_sd lwb_m
#> 1 Zebrasoma scopas -0.49 13.3 0.425 2.02091     2 0.02455 0.00269898  2.98
#>      lwb_sd     mdw_m        f0_m        f0_sd alpha_m   alpha_sd
#> 1 0.0255102 0.2504833 0.001517989 3.159307e-10    0.77 0.05286288

All other parameters have to be provided by the user. For more information on how to acquire these parameters, take a look at (“this paper” add reference to methods paper).

### Run model

Once all the parameters are collected, we can run the model through cnp_model_mcmc(). Note that this model can be run with or without specifying the standard deviation (sd) of each parameter. If the sd of a certain parameter is not provided, it will be automatically set to a very low value (1-10). As mentioned before, it is advisable to include uncertainty of parameters. fishflux is designed to use the MCMC sampler in order to include uncertainty of predictions.

## load the example parameters for Zebrasoma scopas, a list
param_zebsco <- fishflux::param_zebsco
## Run the model, specifying the target length(s) and the parameter list
model <- fishflux::cnp_model_mcmc(TL = 5:20, param = param_zebsco)

The object model now contains all the samples generated from the MCMC simulation and a summary of all parameters generated. To extract certain variables of interest, use the extract() function. Predictions for fluxes of C, N and P are all in g / day.

fishflux::extract(model, c("Fn","Fp"))
#>    TL      Fn_mean    Fn_median        Fn_sd      Fn_2.5%    Fn_97.5%
#> 1   5 0.0008987209 0.0008258532 0.0004516529 0.0002423150 0.002031488
#> 2   6 0.0013357059 0.0012378933 0.0006248591 0.0002959874 0.002653808
#> 3   7 0.0018768647 0.0017758075 0.0008742402 0.0004740814 0.003738993
#> 4   8 0.0026590472 0.0025532038 0.0012911737 0.0005992649 0.005746066
#> 5   9 0.0034221864 0.0031061876 0.0016377464 0.0009420806 0.007233407
#> 6  10 0.0044195767 0.0038852723 0.0023892242 0.0011095291 0.010526108
#> 7  11 0.0057319944 0.0050676513 0.0030845922 0.0016102430 0.012885794
#> 8  12 0.0072934452 0.0063093784 0.0043618776 0.0014571498 0.018758855
#> 9  13 0.0090031867 0.0077025454 0.0052639524 0.0019067974 0.021708729
#> 10 14 0.0108806082 0.0092915323 0.0073677685 0.0018518916 0.030552511
#> 11 15 0.0141539873 0.0128978910 0.0089168574 0.0029504032 0.035822178
#> 12 16 0.0162576158 0.0145682771 0.0101301444 0.0030217873 0.039965390
#> 13 17 0.0199742166 0.0172777433 0.0135862916 0.0036164357 0.055119465
#> 14 18 0.0231738608 0.0199836568 0.0147192686 0.0052239551 0.057336415
#> 15 19 0.0271181883 0.0239311875 0.0164676788 0.0069112849 0.067299478
#> 16 20 0.0315487819 0.0270554074 0.0202909591 0.0069171193 0.080001736
#>          Fn_25%      Fn_75%      Fp_mean    Fp_median        Fp_sd      Fp_2.5%
#> 1  0.0005816077 0.001158470 8.352455e-05 4.277732e-05 0.0001117367 2.902640e-06
#> 2  0.0009116195 0.001703405 1.669686e-04 8.494485e-05 0.0002010300 5.784209e-06
#> 3  0.0012659418 0.002389309 2.772809e-04 1.540319e-04 0.0003064478 1.211269e-05
#> 4  0.0017201503 0.003384442 4.987763e-04 2.944143e-04 0.0004987073 1.620800e-05
#> 5  0.0021991061 0.004323226 7.326251e-04 4.804397e-04 0.0006866742 2.857762e-05
#> 6  0.0028434615 0.005580287 1.042972e-03 6.586121e-04 0.0010097491 5.200344e-05
#> 7  0.0034949124 0.007133755 1.521884e-03 1.166166e-03 0.0012950953 8.926156e-05
#> 8  0.0040357055 0.009743393 2.137272e-03 1.702862e-03 0.0017995857 1.073146e-04
#> 9  0.0049349494 0.012173890 2.810153e-03 2.216744e-03 0.0020961563 1.785846e-04
#> 10 0.0052709913 0.014753474 3.587968e-03 2.938491e-03 0.0028628492 2.662557e-04
#> 11 0.0073955622 0.019403184 4.954343e-03 4.431519e-03 0.0035473058 5.954426e-04
#> 12 0.0080519490 0.023043383 5.894096e-03 5.081785e-03 0.0040793728 6.397111e-04
#> 13 0.0093925742 0.026849303 7.527176e-03 6.315506e-03 0.0054435638 1.031925e-03
#> 14 0.0116262290 0.031257030 8.977836e-03 7.702347e-03 0.0058904522 1.852600e-03
#> 15 0.0138513133 0.035900198 1.078995e-02 9.322225e-03 0.0065657686 2.759588e-03
#> 16 0.0144162522 0.043618297 1.250707e-02 1.067074e-02 0.0080601277 2.663946e-03
#>        Fp_97.5%       Fp_25%       Fp_75%
#> 1  0.0004502539 2.221946e-05 8.632868e-05
#> 2  0.0007094332 4.106703e-05 2.251265e-04
#> 3  0.0010850049 7.346480e-05 3.727040e-04
#> 4  0.0019298993 1.495326e-04 7.272235e-04
#> 5  0.0023678743 2.072471e-04 1.102726e-03
#> 6  0.0033171869 3.046594e-04 1.547747e-03
#> 7  0.0049417097 5.487247e-04 2.180400e-03
#> 8  0.0069855636 6.694722e-04 3.277222e-03
#> 9  0.0077723291 1.085282e-03 4.073406e-03
#> 10 0.0107356357 1.271643e-03 5.026458e-03
#> 11 0.0137122876 2.171150e-03 6.981234e-03
#> 12 0.0156439734 2.542919e-03 8.474473e-03
#> 13 0.0214169574 3.387298e-03 1.026325e-02
#> 14 0.0222512941 4.481644e-03 1.214329e-02
#> 15 0.0264268661 5.560754e-03 1.418037e-02
#> 16 0.0312137388 5.763463e-03 1.734978e-02

### Plot results

To visualize main outputs of the model, fishflux contains a plotting function. The function limitation() returns the proportion of iterations of the model simulation that had limitation of C, N and P respectively. The function plot_cnp() plots the predicted output of the model.

## limitation
fishflux::limitation(model)

#>    tl nutrient prop_lim
#> 1   5        c    0.000
#> 2   6        c    0.000
#> 3   7        c    0.000
#> 4   8        c    0.000
#> 5   9        c    0.000
#> 6  10        c    0.000
#> 7  11        c    0.000
#> 8  12        c    0.000
#> 9  13        c    0.000
#> 10 14        c    0.012
#> 11 15        c    0.012
#> 12 16        c    0.038
#> 13 17        c    0.072
#> 14 18        c    0.106
#> 15 19        c    0.132
#> 16 20        c    0.180
#> 17  5        n    0.316
#> 18  6        n    0.416
#> 19  7        n    0.478
#> 20  8        n    0.560
#> 21  9        n    0.606
#> 22 10        n    0.616
#> 23 11        n    0.722
#> 24 12        n    0.736
#> 25 13        n    0.840
#> 26 14        n    0.802
#> 27 15        n    0.876
#> 28 16        n    0.854
#> 29 17        n    0.852
#> 30 18        n    0.860
#> 31 19        n    0.842
#> 32 20        n    0.796
#> 33  5        p    0.684
#> 34  6        p    0.584
#> 35  7        p    0.522
#> 36  8        p    0.440
#> 37  9        p    0.394
#> 38 10        p    0.384
#> 39 11        p    0.278
#> 40 12        p    0.264
#> 41 13        p    0.160
#> 42 14        p    0.186
#> 43 15        p    0.112
#> 44 16        p    0.108
#> 45 17        p    0.076
#> 46 18        p    0.034
#> 47 19        p    0.026
#> 48 20        p    0.024
## Plot one variable:
fishflux::plot_cnp(model,  y = "Fp", x = "tl", probs = c(0.5, 0.8, 0.95))

## Plot multiple variables:
fishflux::plot_cnp(model,  y = c("Fp", "Gp", "Ip", "Wp"), x = "tl", probs = 0.5)

### Sensitivity

The function sensitivity() looks at how the distribution of the input variables affects the uncertainty of the model predictions. Basically, the model is run for each input parameter, while keeping all the others fixed. The output of the function gives a matrix of the width of the 95% CI for all model predictions (columns), depending on the input variables (rows). The input parameters and output variables of interest can be specified by arguments “par” and “out” respectively.

fishflux::sensitivity(TL = 10, param = list(k_sd = 0.2, Dn_sd = 0.2, Dc_sd = 0.1),
par = c("k_sd","Dn_sd","Dc_sd"),
out = c("Ic", "In", "Ip", "Gc"))

#>            Ic_CI        In_CI        Ip_CI        Gc_CI
#> k_sd  0.03068835 3.682602e-03 1.227534e-03 1.178433e-02
#> Dn_sd 0.24090608 4.110545e-03 9.636243e-03 7.154956e-11
#> Dc_sd 0.01018204 2.560408e-10 8.513156e-11 6.705841e-11

For more information on the theoretical framework of the model, see Schiettekatte et al. (2020) ( paper ). Every function of fishflux has a help page with more documentation. In the case of errors, bugs or discomfort, you are invited to raise an issue on GitHub. fishflux is always in development and we are happy to take your comments or suggestions into consideration.