Skip to contents

1. Installing LHTpicker package

For this vigenette to work LHTpicker must be installed and exist in R’s default libpath.


# devtools::install_github("https://github.com/d2gex/LHTPicker", dep=TRUE)

2. Fetch wanted LHTs from FishLife

There are two use cases for using FishLife to obtain missing Life History Traits (LHTs): i) You want to evaluate a species for which no biological parameters are available, meaning you need to retrieve FishLife-predicted LHTs for the desired taxon. ii) You have some biological parameters but not all, and you use FishLife to generate a new set of parameters that integrates and updates your existing data.

This section deals with case i.

2.1 Inputted taxa details

A csv file with the taxon names and the wanted LHTs you are seeking is required.The csv shows as columns those LHTs you are after, as shown below.

taxon_lhts_to_fetch <- readRDS("data/wanted_taxon_details.rds")
head(taxon_lhts_to_fetch)
#>                   taxon Linf Winf  K L50  M Amat Amax Temperature
#> 1    Trisopterus luscus   NA   NA NA  NA NA   NA   NA          NA
#> 2 Pollachius pollachius   NA   NA NA  NA NA   NA   NA          NA

The wrapper uses a list to map column names in your csv to the actual names used by FishLife. Should some predicted variable names change in FishLife in the future, you may need to tweak the list. See that such a list is a member of an R6 object and it is called fishlife_context. If nothing has changed in FishLife, unless you need to add more wanted parameters, nothing else is required to do.

LHTpicker::fishlife_context$lht_names
#> $Linf
#> [1] "log(length_infinity)"
#> 
#> $Winf
#> [1] "log(weight_infinity)"
#> 
#> $K
#> [1] "log(growth_coefficient)"
#> 
#> $M
#> [1] "log(natural_mortality)"
#> 
#> $L50
#> [1] "log(length_maturity)"
#> 
#> $Amax
#> [1] "log(age_max)"
#> 
#> $Amat
#> [1] "log(age_maturity)"
#> 
#> $Temperature
#> [1] "temperature"

Likewise, to back-transform the obtained predicted variables LHTpicker provides a function that map such predicted variables with the required function to convert it. As previously mentioned, you may not need to touch this list either.

LHTpicker::fishlife_context$backtransform_function_list
#> $`log(length_infinity)`
#> function (x)  .Primitive("exp")
#> 
#> $`log(weight_infinity)`
#> function (x)  .Primitive("exp")
#> 
#> $`log(growth_coefficient)`
#> function (x)  .Primitive("exp")
#> 
#> $`log(natural_mortality)`
#> function (x)  .Primitive("exp")
#> 
#> $`log(length_maturity)`
#> function (x)  .Primitive("exp")
#> 
#> $`log(age_max)`
#> function (x)  .Primitive("exp")
#> 
#> $`log(age_maturity)`
#> function (x)  .Primitive("exp")
#> 
#> $temperature
#> function (x) 
#> x
#> <bytecode: 0x555c39c6b860>
#> <environment: namespace:base>

2.2 Fetching predicted LHTs

Please refer to the reference for further details.

p_lht_picker <- LHTpicker::PredictedLHTPicker$new(FishLife::FishBase_and_Morphometrics,
                                                  LHTpicker::fishlife_context$lht_names,
                                                  LHTpicker::fishlife_context$backtransform_function_list,
                                                  taxon_lhts_to_fetch)
predicted_lht_df <- p_lht_picker$pick_and_backtransform()
head(predicted_lht_df)
#>                   taxon     Linf      Winf         K      L50         M
#> 1    Trisopterus luscus 43.86770  833.9878 0.3737931 19.52203 0.5981946
#> 2 Pollachius pollachius 87.30785 5819.9735 0.1867131 34.71789 0.3085845
#>       Amat      Amax Temperature
#> 1 1.400562  6.458926    17.36961
#> 2 3.456610 12.138258    12.11773

In case FishLife cannot provide details about a species for whatever reason, LHTpicker will return a column of NA values for the rows holding details about the missing species, as shown below.

non_existant_taxon_lhts_to_fetch <- dplyr::mutate(taxon_lhts_to_fetch, taxon = dplyr::case_when(
    taxon == "Trisopterus luscus" ~ "IDoNoExist",
    .default = taxon
))
p_lht_picker <- LHTpicker::PredictedLHTPicker$new(FishLife::FishBase_and_Morphometrics,
                                                  LHTpicker::fishlife_context$lht_names,
                                                  LHTpicker::fishlife_context$backtransform_function_list,
                                                  non_existant_taxon_lhts_to_fetch)
predicted_lht_df <- p_lht_picker$pick_and_backtransform()
head(predicted_lht_df)
#> # A tibble: 2 × 9
#>   taxon                  Linf  Winf      K   L50      M  Amat  Amax Temperature
#>   <chr>                 <dbl> <dbl>  <dbl> <dbl>  <dbl> <dbl> <dbl>       <dbl>
#> 1 IDoNoExist             NA     NA  NA      NA   NA     NA     NA          NA  
#> 2 Pollachius pollachius  87.3 5820.  0.187  34.7  0.309  3.46  12.1        12.1

3 Fetch updated LHTs given new data

This section deals with case ii, that is, with fetching updated LHTs from FishLife.

3.1 Inputted predicting taxa details

A csv file with the taxon names you are after and the wanted-to-update LHTs is required as shown below. Let’s suppose we have most of the LHTs however we do not know the natural mortality(M) nor the age of maturity.

taxon_lhts_to_update <- readRDS("data/wanted_update_taxon_details.rds")
head(taxon_lhts_to_update)
#> # A tibble: 2 × 9
#>   taxon                  Linf  Winf     K   L50 M     Amat   Amax Temperature
#>   <chr>                 <dbl> <dbl> <dbl> <dbl> <lgl> <lgl> <dbl>       <dbl>
#> 1 Trisopterus luscus     42.4   921 0.21   19.4 NA    NA        9        14.3
#> 2 Pollachius pollachius 102.  12045 0.193  41.6 NA    NA        8        14.3

3.2 Fetching updated LHTs

Unless the previous function, we need to provide two extra parameters: a prefix that LHTpicker will use to concatenate to the named of updated columns in the csv and function transformation list, similar to the back-transformation one, to transform the provided LHTs into Fishlife’s expected domain. Once again, unless you need other variables from FishLife, you do not need to modify neither of the related transformation and back-transformation lists.


u_lht_picker <- LHTpicker::UpdatedLHTPicker$new(
  FishLife::FishBase_and_Morphometrics,
  taxon_lhts_to_update,
  LHTpicker::fishlife_context$updated_prefix,
  LHTpicker::fishlife_context$transform_function_list,
  LHTpicker::fishlife_context$backtransform_function_list,
  LHTpicker::fishlife_context$lht_names
)
updated_lht_df <- u_lht_picker$pick_and_backtransform()
head(updated_lht_df)
#>                   taxon   Linf  Winf     K   L50  M Amat Amax Temperature
#> 1    Trisopterus luscus  42.41   921 0.210 19.45 NA   NA    9        14.3
#> 2 Pollachius pollachius 102.14 12045 0.193 41.60 NA   NA    8        14.3
#>   updated_Linf updated_Winf updated_K updated_M updated_L50 updated_Amax
#> 1     44.01880     839.5509 0.3451741 0.5872462    19.60257     6.973144
#> 2     95.04985    8387.9049 0.1881105 0.2997824    36.48049    11.111069
#>   updated_Amat updated_Temperature
#> 1     1.438878            16.75299
#> 2     3.413651            13.05912

See how each updated column name from FishLife has a prefix attached to it and how updated_M and Amat have now been provided. In order to use the these LHTs for your assessment you need to use the whole returned set, to avoid breaking the covariance matrix among parameters (Thorson et al., 2017)