fishprior

The vignette provides a demonstration on how to use the fishprior package to obtain priors for life-history parameters that will be applicable in the assessment of the status of the population.

Data

Data for priors can be obtained from either FishBase using get_fishbase_traits() and summarize_fishbase_traits(), which is a wrapper around the rfishbase package.

This example provides code used to query FishBase for traits for three species. The rfishbase package provides a flexible approach for querying tables in FishBase, and our functions act as wrappers for these calls.

species_list <- c(
  "Merluccius merluccius",
  "Gadus chalcogrammus",
  "Anoplopoma fimbria"
)
example_base_raw <- get_fishbase_traits(spec_names = species_list)
example_base_raw
## # A tibble: 1,437 × 22
##    rfishbase Species          SpecCode Sex   PopGrowthRef DataSourceRef Locality
##    <chr>     <chr>               <int> <chr>        <int>         <int> <chr>   
##  1 popgrowth Anoplopoma fimb…      512 fema…          312           733 Oregon  
##  2 popgrowth Anoplopoma fimb…      512 fema…          312           733 Oregon  
##  3 popgrowth Anoplopoma fimb…      512 fema…          312           733 Oregon  
##  4 popgrowth Anoplopoma fimb…      512 fema…          312           733 Oregon  
##  5 popgrowth Anoplopoma fimb…      512 male           312           733 Oregon  
##  6 popgrowth Anoplopoma fimb…      512 male           312           733 Oregon  
##  7 popgrowth Anoplopoma fimb…      512 male           312           733 Oregon  
##  8 popgrowth Anoplopoma fimb…      512 male           312           733 Oregon  
##  9 popgrowth Anoplopoma fimb…      512 unse…         5760          5818 Northea…
## 10 popgrowth Anoplopoma fimb…      512 unse…         5760          5818 Northea…
## # ℹ 1,427 more rows
## # ℹ 15 more variables: YearStart <int>, YearEnd <int>, Number <dbl>,
## #   Type <chr>, C_Code <chr>, E_CODE <dbl>, SourceRef <int>, StockCode <dbl>,
## #   AgeMatRef <int>, trait <chr>, value <dbl>, SE <dbl>, SD <dbl>,
## #   country <chr>, EcosystemName <chr>

This data can be summarized to provide output similar to what is returned from FishLife. Only a handful of traits are currently summarized but more can be provided in the future should it be desired. Feel free to fill out a GitHub Issue if you would like to see more traits summarized.

example_base <- summarize_fishbase_traits(example_base_raw)
example_base
## # A tibble: 19 × 6
##    Species               trait                mean_normal sd_normal  mean     sd
##    <chr>                 <chr>                      <dbl>     <dbl> <dbl>  <dbl>
##  1 Anoplopoma fimbria    log(growth_coeffici…       0.239     0.134 -1.57 0.508 
##  2 Anoplopoma fimbria    log(length_maturity)      59.1       4.02   4.08 0.0687
##  3 Anoplopoma fimbria    log(length_infinity)      79.0      17.7    4.35 0.213 
##  4 Anoplopoma fimbria    log(age_maturity)          5.64      0.789  1.72 0.137 
##  5 Anoplopoma fimbria    log(age_max)              79.5      20.5    4.36 0.261 
##  6 Gadus chalcogrammus   log(growth_coeffici…       0.237     0.121 -1.58 0.552 
##  7 Gadus chalcogrammus   log(length_maturity)      35.7       3.49   3.57 0.0966
##  8 Gadus chalcogrammus   log(length_max)           64.1      28.2    4.02 0.692 
##  9 Gadus chalcogrammus   log(length_infinity)      69.8      16.4    4.22 0.213 
## 10 Gadus chalcogrammus   log(natural_mortali…       0.344     0.191 -1.20 0.545 
## 11 Gadus chalcogrammus   log(age_maturity)          4         0.798  1.37 0.200 
## 12 Gadus chalcogrammus   log(age_max)              19         8.15   2.84 0.521 
## 13 Merluccius merluccius log(growth_coeffici…       0.166     0.102 -1.95 0.561 
## 14 Merluccius merluccius log(length_maturity)      37.0      11.0    3.57 0.293 
## 15 Merluccius merluccius log(length_max)           76.8      24.1    4.30 0.277 
## 16 Merluccius merluccius log(length_infinity)      85.9      34.1    4.38 0.373 
## 17 Merluccius merluccius log(natural_mortali…       0.360     0.150 -1.11 0.438 
## 18 Merluccius merluccius log(age_maturity)          3.45      1.43   1.15 0.454 
## 19 Merluccius merluccius log(age_max)               9.67      3.75   2.22 0.321

Filtering

As an example of querying data and building custom priors, we will start with a simple example based on Atlantic cod (Gadus morhua). The data pulled from FishBase can be limited to just the data that pertains to cod. Each row represents a unique combination of study and trait. Initial columns store metadata about the study and the value column stores the value of the trait found in that study.

cod_traits <- get_fishbase_traits(spec_names = "Gadus morhua")

The study-specific traits can be summarized as we did before but now just for cod using summarize_fishbase_traits().

cod_summary <- summarize_fishbase_traits(cod_traits)

This approach is simple because it uses all studies in FishBase to summarize data; in practice, it may be of interest to only use studies from a specific region. As a demonstration of how to do this, we provide a slightly more complex example. Each of the tables returned by get_fishbase_traits() has a Locality field, e.g.,

cod_traits |>
  dplyr::count(Locality)
## # A tibble: 193 × 2
##    Locality                                     n
##    <chr>                                    <int>
##  1 Aberdeen Bay, 1969-1970 (INS)                4
##  2 Atlantic coast / Autumn 1992-1999.           3
##  3 Atlantic coast / Spring 1992-1999.           3
##  4 Atlantic coast / Winter 1992-1999.           3
##  5 Baltic                                       7
##  6 Baltic Sea                                   1
##  7 Baltic Sea (SD 25-32), 2016, 1st quarter     1
##  8 Baltic Sea (SD 25-32), early 1990s           1
##  9 Baltic Sea (SD 25-32), late 2000s            1
## 10 Baltic subdiv. 26                            4
## # ℹ 183 more rows

Looking at the locality for growth for example, a handful of studies are from eastern Canada and the northeastern United States. If we wanted to summarize only these studies, we can use some custom filtering.

cod_traits_filtered <- cod_traits |>
  dplyr::filter(
    rfishbase == "popgrowth",
    grepl(
      "Southern Gulf of St\\. Lawrence|Gulf of Maine|Southern New England",
      Locality
    )
  )
dplyr::count(cod_traits_filtered, trait, Locality)
## # A tibble: 14 × 3
##    trait     Locality                               n
##    <chr>     <chr>                              <int>
##  1 K         Georges Bank and Gulf of Maine         1
##  2 K         Gulf of Maine Bank (5Y)                1
##  3 K         Southern Gulf of St. Lawrence         11
##  4 K         Southern New England (200 m depth)     1
##  5 Loo       Georges Bank and Gulf of Maine         1
##  6 Loo       Gulf of Maine Bank (5Y)                1
##  7 Loo       Southern Gulf of St. Lawrence         11
##  8 Loo       Southern New England (200 m depth)     1
##  9 M         Southern Gulf of St. Lawrence          1
## 10 Winfinity Georges Bank and Gulf of Maine         1
## 11 Winfinity Gulf of Maine Bank (5Y)                1
## 12 Winfinity Southern Gulf of St. Lawrence         11
## 13 Winfinity Southern New England (200 m depth)     1
## 14 to        Southern Gulf of St. Lawrence         11

And then we can pass our filtered dataframe into summarize_fishbase_traits()

cod_summary_filtered <- summarize_fishbase_traits(cod_traits_filtered)
cod_summary_filtered
## # A tibble: 3 × 6
##   Species      trait                   mean_normal sd_normal   mean     sd
##   <chr>        <chr>                         <dbl>     <dbl>  <dbl>  <dbl>
## 1 Gadus morhua log(growth_coefficient)       0.178    0.0728 -1.81   0.435
## 2 Gadus morhua log(length_infinity)         93.3     36.7     4.47   0.379
## 3 Gadus morhua log(natural_mortality)        0.44    NA      -0.821 NA

Because we only filtered locality for the results from rfishbase::popgrowth(), this filtering only affects summaries for parameters coming from this table (“log(growth_coefficient)”, “log(length_infinity)”).