From 9d2b108ce7d8ee5b796bb1fd306e6109ce8b6329 Mon Sep 17 00:00:00 2001 From: Derek Ogle Date: Tue, 19 Aug 2025 08:18:08 -0500 Subject: [PATCH] Changes to metaM() to address #133 --- DESCRIPTION | 2 +- NEWS.md | 1 + R/metaM.R | 22 +++++++++++++++------- man/metaM.Rd | 13 ++++++++----- tests/testthat/testthat_metaM.R | 7 ++++--- 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7187dba5..1507a707 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: FSA Version: 0.10.9000 -Date: 2025-8-8 +Date: 2025-8-16 Title: Simple Fisheries Stock Assessment Methods Description: A variety of simple fish stock assessment methods. Authors@R: c( diff --git a/NEWS.md b/NEWS.md index 9d60ec92..e2c813e1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # FSA 0.10.9000 * `chapmanRobson()`: Added catch for when n+T<1 and n+T<2. This addresses [#131](https://github.com/fishR-Core-Team/FSA/issues/131)). +* `metaM()`: Added `method="HamelCope"` to address [#133](https://github.com/fishR-Core-Team/FSA/issues/133). A few minor edits to documentation. * `PSDlit`: Added info for Flier and Longear Sunfish. * `wSlit`: Added info for Flier and Longear Sunfish. This addresses [#122](https://github.com/fishR-Core-Team/FSA/issues/122)). diff --git a/R/metaM.R b/R/metaM.R index 865f09dc..b8a68564 100644 --- a/R/metaM.R +++ b/R/metaM.R @@ -13,6 +13,7 @@ #' \item \code{method="HoenigLM"}: The \dQuote{modified Hoenig equation derived with a linear model} as described in Then \emph{et al.} (2015) on the second line of Table 3. Requires only \code{tmax}. #' \item \code{method="HewittHoenig"}: The \dQuote{Hewitt and Hoenig (2005) equation} from their equation 8. Requires only \code{tmax}. #' \item \code{method="tmax1"}: The \dQuote{one-parameter tmax equation} from the first line of Table 3 in Then \emph{et al.} (2015). Requires only \code{tmax}. +#' \item \code{method="HamelCope"}: The equation 7 from Hamel and Cope (2022). Requires only \code{tmax}. #' \item \code{method="K1"}: The \dQuote{one-parameter K equation} from the fourth line of Table 3 in Then \emph{et al.} (2015). Requires only \code{K}. #' \item \code{method="K2"}: The \dQuote{two-parameter K equation} from the fifth line of Table 3 in Then \emph{et al.} (2015). Requires only \code{K}. #' \item \code{method="JensenK1"}: The \dQuote{Jensen (1996) one-parameter K equation}. Requires only \code{K}. @@ -54,15 +55,15 @@ #' \item \code{givens}: A string that contains the input values required by the method to estimate M. #' } #' -#' @section Testing: Kenchington (2014) provided life history parameters for several stocks and used many models to estimate M. I checked the calculations for the \code{PaulyL}, \code{PaulyW}, \code{HoenigO}, \code{HoenigOF}, \code{HoenigO2}, \code{HoenigO2F}, \code{"JensenK1"}, \code{"Gislason"}, \code{"AlversonCarney"}, \code{"Charnov"}, \code{"ZhangMegrey"}, \code{"RikhterEfanov1"}, and \code{"RikhterEfanov2"} methods for three stocks. All results perfectly matched Kenchington's results for Chesapeake Bay Anchovy and Rio Formosa Seahorse. For the Norwegian Fjord Lanternfish, all results perfectly matched Kenchington's results except for \code{HoenigOF} and \code{HoenigO2F}. +#' @section Testing: Kenchington (2014) provided life history parameters for several stocks and used many models to estimate M. I checked the calculations for the \code{"PaulyL"}, \code{"PaulyW"}, \code{"HoenigO"}, \code{"HoenigOF"}, \code{"HoenigO2"}, \code{"HoenigO2F"}, \code{"JensenK1"}, \code{"Gislason"}, \code{"AlversonCarney"}, \code{"Charnov"}, \code{"ZhangMegrey"}, \code{"RikhterEfanov1"}, and \code{"RikhterEfanov2"} methods for three stocks. All results perfectly matched Kenchington's results for Chesapeake Bay Anchovy and Rio Formosa Seahorse. For the Norwegian Fjord Lanternfish, all results perfectly matched Kenchington's results except for \code{"HoenigOF"} and \code{"HoenigO2F"}. #' -#' Results for the Rio Formosa Seahorse data were also tested against results from \code{\link[fishmethods]{M.empirical}} from \pkg{fishmethods} for the \code{PaulyL}, \code{PaulyW}, \code{HoenigO}, \code{HoenigOF}, \code{"Gislason"}, and \code{"AlversonCarney"} methods (the only methods in common between the two packages). All results matched perfectly. +#' Results for the Rio Formosa Seahorse data were also tested against results from \code{\link[fishmethods]{M.empirical}} from \pkg{fishmethods} for the \code{"PaulyL"}, \code{"PaulyW"}, \code{"HoenigO"}, \code{"HoenigOF"}, \code{"Gislason"}, and \code{"AlversonCarney"} methods (the only methods in common between the two packages). All results matched perfectly. #' #' @author Derek H. Ogle, \email{DerekOgle51@gmail.com} #' #' @section IFAR Chapter: 11-Mortality. #' -#' @seealso See \code{\link[fishmethods]{M.empirical}} in \pkg{fishmethods} for similar functionality. +#' @seealso See \code{\link[fishmethods]{M.empirical}} in \pkg{fishmethods} for similar functionality and the "Natural Mortality Tool" Shiny app on-line. #' #' @references Ogle, D.H. 2016. \href{https://fishr-core-team.github.io/fishR/pages/books.html#introductory-fisheries-analyses-with-r}{Introductory Fisheries Analyses with R}. Chapman & Hall/CRC, Boca Raton, FL. #' @@ -74,6 +75,8 @@ #' #' Gislason, H., N. Daan, J.C. Rice, and J.G. Pope. 2010. Size, growth, temperature and the natural mortality of marine fish. Fish and Fisheries 11:149-158. #' +#' Hamel, O. and J. M. Cope. 2022. Development and considerations for application of a longevity-based prior for the natural mortality rate. Fisheries Research 256:106477 [Was (is? from https://www.researchgate.net/publication/363595336_Development_and_considerations_for_application_of_a_longevity-based_prior_for_the_natural_mortality_rate).] +#' #' Hewitt, D.A. and J.M. Hoenig. 2005. Comparison of two approaches for estimating natural mortality based on longevity. Fishery Bulletin. 103:433-437. [Was (is?) from http://fishbull.noaa.gov/1032/hewitt.pdf.] #' #' Hoenig, J.M. 1983. Empirical use of longevity data to estimate mortality rates. Fishery Bulletin. 82:898-903. [Was (is?) from http://www.afsc.noaa.gov/REFM/age/Docs/Hoenig_EmpiricalUseOfLongevityData.pdf.] @@ -108,7 +111,7 @@ #' Mmethods("tmax") #' #' ## Simple Examples -#' metaM("tmax",tmax=20) +#' metaM("HamelCope",tmax=20) #' metaM("HoenigNLS",tmax=20) #' metaM("HoenigNLS",tmax=20,verbose=FALSE) #' @@ -133,7 +136,7 @@ #' #' ## Example of multiple methods using Mmethods #' # select some methods -#' metaM(Mmethods()[-c(15,20,22:24,26:29)],K=K,Linf=Linf,Temp=Temp,tmax=tmax,t50=t50) +#' metaM(Mmethods()[-c(16,21,23:25,27:30)],K=K,Linf=Linf,Temp=Temp,tmax=tmax,t50=t50) #' # select just the Hoenig methods #' metaM(Mmethods("Hoenig"),K=K,Linf=Linf,Temp=Temp,tmax=tmax,t50=t50) #' @@ -150,7 +153,7 @@ Mmethods <- function(method=c("all","tmax","K","Hoenig","Pauly","FAMS")) { method <- match.arg(method) all_meth <- c("HoenigNLS","HoenigO","HoenigOF","HoenigOM","HoenigOC", "HoenigO2","HoenigO2F","HoenigO2M","HoenigO2C", - "HoenigLM","HewittHoenig","tmax1", + "HoenigLM","HewittHoenig","tmax1","HamelCope", "PaulyLNoT","PaulyL","PaulyW", "K1","K2","JensenK1","JensenK2","Gislason", "AlversonCarney","Charnov", @@ -161,7 +164,7 @@ Mmethods <- function(method=c("all","tmax","K","Hoenig","Pauly","FAMS")) { P_meth <- switch(method, all = { meths <- all_meth }, - tmax = { meths <- c("tmax1",H_meth)}, + tmax = { meths <- c("HamelCope","tmax1",H_meth)}, K = { meths <- c("K1","K2","JensenK1","JensenK2")}, Hoenig = { meths <- H_meth}, Pauly = { meths <- all_meth[grep("Pauly",all_meth)] }, @@ -191,6 +194,11 @@ metaM <- function(method=Mmethods(), metaM1 <- function(method,tmax,K,Linf,t0,b,L,Temp,t50,Winf,PS,...) { switch(method, + HamelCope = { ## from Hamel & Cope (2022), Equation 7 + name <- "Hamel and Cope (2022) tmax equation" + iCheck_tmax(tmax) + givens <- c(tmax=tmax) + M <- 5.40/tmax }, tmax1 = { ## from Then et al. (2015), Table 3, 1st line name <- "Then et al. (2015) tmax equation" iCheck_tmax(tmax) diff --git a/man/metaM.Rd b/man/metaM.Rd index 4361c863..9104d3d3 100644 --- a/man/metaM.Rd +++ b/man/metaM.Rd @@ -74,6 +74,7 @@ One of several methods is chosen with \code{method}. The available methods can b \item \code{method="HoenigLM"}: The \dQuote{modified Hoenig equation derived with a linear model} as described in Then \emph{et al.} (2015) on the second line of Table 3. Requires only \code{tmax}. \item \code{method="HewittHoenig"}: The \dQuote{Hewitt and Hoenig (2005) equation} from their equation 8. Requires only \code{tmax}. \item \code{method="tmax1"}: The \dQuote{one-parameter tmax equation} from the first line of Table 3 in Then \emph{et al.} (2015). Requires only \code{tmax}. + \item \code{method="HamelCope"}: The equation 7 from Hamel and Cope (2022). Requires only \code{tmax}. \item \code{method="K1"}: The \dQuote{one-parameter K equation} from the fourth line of Table 3 in Then \emph{et al.} (2015). Requires only \code{K}. \item \code{method="K2"}: The \dQuote{two-parameter K equation} from the fifth line of Table 3 in Then \emph{et al.} (2015). Requires only \code{K}. \item \code{method="JensenK1"}: The \dQuote{Jensen (1996) one-parameter K equation}. Requires only \code{K}. @@ -92,9 +93,9 @@ One of several methods is chosen with \code{method}. The available methods can b Conditional mortality (cm) is estimated from instantaneous natural mortality (M) with 1-exp(-M). It is returned with M here simply as a courtesy for those using the \code{rFAMS} package. } \section{Testing}{ - Kenchington (2014) provided life history parameters for several stocks and used many models to estimate M. I checked the calculations for the \code{PaulyL}, \code{PaulyW}, \code{HoenigO}, \code{HoenigOF}, \code{HoenigO2}, \code{HoenigO2F}, \code{"JensenK1"}, \code{"Gislason"}, \code{"AlversonCarney"}, \code{"Charnov"}, \code{"ZhangMegrey"}, \code{"RikhterEfanov1"}, and \code{"RikhterEfanov2"} methods for three stocks. All results perfectly matched Kenchington's results for Chesapeake Bay Anchovy and Rio Formosa Seahorse. For the Norwegian Fjord Lanternfish, all results perfectly matched Kenchington's results except for \code{HoenigOF} and \code{HoenigO2F}. + Kenchington (2014) provided life history parameters for several stocks and used many models to estimate M. I checked the calculations for the \code{"PaulyL"}, \code{"PaulyW"}, \code{"HoenigO"}, \code{"HoenigOF"}, \code{"HoenigO2"}, \code{"HoenigO2F"}, \code{"JensenK1"}, \code{"Gislason"}, \code{"AlversonCarney"}, \code{"Charnov"}, \code{"ZhangMegrey"}, \code{"RikhterEfanov1"}, and \code{"RikhterEfanov2"} methods for three stocks. All results perfectly matched Kenchington's results for Chesapeake Bay Anchovy and Rio Formosa Seahorse. For the Norwegian Fjord Lanternfish, all results perfectly matched Kenchington's results except for \code{"HoenigOF"} and \code{"HoenigO2F"}. -Results for the Rio Formosa Seahorse data were also tested against results from \code{\link[fishmethods]{M.empirical}} from \pkg{fishmethods} for the \code{PaulyL}, \code{PaulyW}, \code{HoenigO}, \code{HoenigOF}, \code{"Gislason"}, and \code{"AlversonCarney"} methods (the only methods in common between the two packages). All results matched perfectly. +Results for the Rio Formosa Seahorse data were also tested against results from \code{\link[fishmethods]{M.empirical}} from \pkg{fishmethods} for the \code{"PaulyL"}, \code{"PaulyW"}, \code{"HoenigO"}, \code{"HoenigOF"}, \code{"Gislason"}, and \code{"AlversonCarney"} methods (the only methods in common between the two packages). All results matched perfectly. } \section{IFAR Chapter}{ @@ -107,7 +108,7 @@ Mmethods() Mmethods("tmax") ## Simple Examples -metaM("tmax",tmax=20) +metaM("HamelCope",tmax=20) metaM("HoenigNLS",tmax=20) metaM("HoenigNLS",tmax=20,verbose=FALSE) @@ -132,7 +133,7 @@ metaM(c("RikhterEfanov1","PaulyL","HoenigO","HewittHoenig","AlversonCarney"), ## Example of multiple methods using Mmethods # select some methods -metaM(Mmethods()[-c(15,20,22:24,26:29)],K=K,Linf=Linf,Temp=Temp,tmax=tmax,t50=t50) +metaM(Mmethods()[-c(16,21,23:25,27:30)],K=K,Linf=Linf,Temp=Temp,tmax=tmax,t50=t50) # select just the Hoenig methods metaM(Mmethods("Hoenig"),K=K,Linf=Linf,Temp=Temp,tmax=tmax,t50=t50) @@ -155,6 +156,8 @@ Charnov, E.L., H. Gislason, and J.G. Pope. 2013. Evolutionary assembly rules for Gislason, H., N. Daan, J.C. Rice, and J.G. Pope. 2010. Size, growth, temperature and the natural mortality of marine fish. Fish and Fisheries 11:149-158. +Hamel, O. and J. M. Cope. 2022. Development and considerations for application of a longevity-based prior for the natural mortality rate. Fisheries Research 256:106477 [Was (is? from https://www.researchgate.net/publication/363595336_Development_and_considerations_for_application_of_a_longevity-based_prior_for_the_natural_mortality_rate).] + Hewitt, D.A. and J.M. Hoenig. 2005. Comparison of two approaches for estimating natural mortality based on longevity. Fishery Bulletin. 103:433-437. [Was (is?) from http://fishbull.noaa.gov/1032/hewitt.pdf.] Hoenig, J.M. 1983. Empirical use of longevity data to estimate mortality rates. Fishery Bulletin. 82:898-903. [Was (is?) from http://www.afsc.noaa.gov/REFM/age/Docs/Hoenig_EmpiricalUseOfLongevityData.pdf.] @@ -180,7 +183,7 @@ Then, A.Y., J.M. Hoenig, N.G. Hall, and D.A. Hewitt. 2015. Evaluating the predic Zhang, C-I and B.A. Megrey. 2006. A revised Alverson and Carney model for estimating the instantaneous rate of natural mortality. Transactions of the American Fisheries Society. 135-620-633. [Was (is?) from http://www.pmel.noaa.gov/foci/publications/2006/zhan0531.pdf.] } \seealso{ -See \code{\link[fishmethods]{M.empirical}} in \pkg{fishmethods} for similar functionality. +See \code{\link[fishmethods]{M.empirical}} in \pkg{fishmethods} for similar functionality and the "Natural Mortality Tool" Shiny app on-line. } \author{ Derek H. Ogle, \email{DerekOgle51@gmail.com} diff --git a/tests/testthat/testthat_metaM.R b/tests/testthat/testthat_metaM.R index 20dd4e24..76b802b4 100644 --- a/tests/testthat/testthat_metaM.R +++ b/tests/testthat/testthat_metaM.R @@ -10,8 +10,8 @@ test_that("metaM() messages",{ "should be one of") ## missing parameters - # default tmax method - expect_error(metaM("tmax"), + # default tmax1 method + expect_error(metaM("tmax1"), "must be given to") # Pauly L method expect_error(metaM("PaulyL",Linf=200,K=0.3), @@ -136,7 +136,8 @@ test_that("metaM() matches results from Kenchington (2014)",{ expect_equal(round(tmp$M,2)[-7],tmp$expM[-7]) ## Norwegian Fjord Lanternfish - ## matches except for the HoenigOF and HoenigO2F, which Kenchington acknowledged as erroneous + ## matches except for the HoenigOF and HoenigO2F, which Kenchington + ## acknowledged as erroneous tmp <- metaM(meths,tmax=8,Linf=8.306,Winf=8.68,K=0.204,t0=-0.64, b=3.26,t50=2,T=8,L=2) tmp <- data.frame(tmp,expM=c(0.51,0.46,0.55,0.61,0.58,0.64,0.31,