| Title: | Management Strategy Evaluation for Salmon Species |
| Version: | 3.0.0 |
| Date: | 2026-08-18 |
| Maintainer: | Quang Huynh <quang@bluematterscience.com> |
| Description: | Simulation tools to evaluate the long-term effects of salmon management strategies, including a combination of habitat, harvest, and habitat actions. The stochastic age-structured operating model accommodates complex life histories, including freshwater survival across early life stages, juvenile survival and fishery exploitation in the marine life stage, partial maturity by age class, and fitness impacts of hatchery programs on natural spawning populations. 'salmonMSE' also provides an age-structured conditioning model to develop operating models fitted to data. |
| License: | GPL (≥ 3) |
| Depends: | R (≥ 4.1.0) |
| Imports: | abind, RTMB (≥ 1.9), dplyr, ggplot2, grDevices, gsl, methods, reshape2, rlang, rmarkdown, parallel, stats, utils |
| Suggests: | bookdown, EnvStats, ggrepel, knitr, rstan, scales, testthat (≥ 3.0.0), tmbstan |
| Encoding: | UTF-8 |
| LazyData: | yes |
| LazyLoad: | yes |
| RoxygenNote: | 7.3.3 |
| URL: | https://docs.salmonmse.com/, https://github.com/Blue-Matter/salmonMSE |
| BugReports: | https://github.com/Blue-Matter/salmonMSE/issues |
| NeedsCompilation: | no |
| Packaged: | 2026-08-19 23:29:45 UTC; quang |
| Author: | Quang Huynh |
| Repository: | CRAN |
| Date/Publication: | 2026-08-20 10:00:02 UTC |
Calculate exploitation rate in conditioning model
Description
Internal functions for calculating aggregate exploitation rate (.CM_ER()) or by age class (.CM_ER()).
Usage
.CM_ER(
report,
type = c("PT", "T", "all"),
r = 1,
index_AEQ = NULL,
brood = FALSE,
simplify = TRUE
)
.CM_ERage(report, type = c("PT", "T"), brood = FALSE, simplify = TRUE)
Arguments
report |
List, output of state variables from individual MCMC samples, obtained with |
type |
Character, indicates type of variable to plot |
r |
Integer, the release strategy for the figure (only if |
index_AEQ |
Optional integer vector to identify years from which to borrow natural mortality and maturity
to calculate adult equivalents for incomplete brood years. Only used if |
brood |
Logical, whether to show results by brood year or return year (FALSE) |
simplify |
Logical, will return a matrix or array if TRUE, otherwise a list of output by MCMC simulation |
Value
An array if simplify = TRUE. Otherwise, a list.
Reference points for conditioning model
Description
Internal functions that calculate productivity (.CM_prod()) and reference points (.CM_MSY())
from the conditioning model.
These functions can be used to calculate values for a subset of years (productivity can vary
in time with natural mortality and maturity), or from average biological parameters in a subset of years.
Usage
.CM_prod(report, d, index = NULL, mean_bio = FALSE)
.CM_Srep(report, d, index = NULL, mean_bio = FALSE, type = c("spawner", "egg"))
.CM_MSY(
report,
d,
simple = TRUE,
index = NULL,
mean_bio = FALSE,
type = c("spawner", "egg", "u", "Sgen"),
AEQ = TRUE,
maximize = c("MSY", "MER"),
ncores = 1
)
Arguments
report |
List, output of state variables from individual MCMC samples, obtained with |
d |
List of data variables, obtained with |
index |
Integer vector to subset years with which to calculate reference points. Can be used
to reduce computation or average biological parameters from a subset of years, see |
mean_bio |
Logical, whether to average the natural mortality and maturity parameters across
years indicated in |
type |
Character, the type of reference point to calculate |
simple |
Logical, whether to use Ricker lambert equations for MSY reference points (TRUE) or age-structured optimization (FALSE) |
AEQ |
Logical, whether to use adult equivalents when calculating MSY for preterminal fisheries#' Only used if |
maximize |
Character, whether the numerical optimization maximizes catch (MSY) or excess recruitment (MER). For testing only,
should not impact results. Only used if |
ncores |
Numeric, number of processors for parallel computation. Useful if calculating numerically for many MCMC samples |
Value
Matrix, dimension [length(index), length(report)]. If mean_bio = TRUE, matrix has 1 row.
See Also
Egg production function
Description
Simple wrapper function to calculate hatchery egg production
Usage
.egg_func(
ptake = 1,
N,
gamma = 1,
fec,
p_female,
s_prespawn,
val = 0,
opt = TRUE
)
Arguments
ptake |
Numeric, proportion of spawners that spawn |
N |
Numeric, spawners |
gamma |
Numeric, relative reproductive success of spawners |
p_female |
Numeric, proportion female |
s_prespawn |
Numeric, survival of spawners prior to egg production |
val |
Numeric, target egg production. Used to optimize for |
opt |
Logical, whether the function is used to optimize for |
Value
Numeric
All-H Analyzer
Description
Wrapper function for an implementation of All-H Analyzer (AHA) in R. Can be used to compare outputs between AHA and salmonMSE.
Usage
AHA(SOM, ngen = 100, silent = FALSE)
Arguments
SOM |
An object of class SOM |
ngen |
Integer, the number of generations for which to run the simulation |
silent |
Logical, indicates whether to silence messages to the R console |
Value
A named list containing vectors of state variables (by simulation, population, and generation). See SMSE object description.
References
Hatchery Scientific Review Group. 2020. All-H Analyzer Tool Guide and Documentation. May 2020.
Class "Bio"
Description
The component of the operating model that controls biological dynamics, i.e., natural production.
Details
Various parameters can be stochastic (length nsim) or input as a single numeric
(value identical across all simulations).
Slots
NameCharacter. Identifying name
maxageInteger. The maximum age of the population age structure.
n_gInteger. Number of life history groups within a cohort. Life history groups (LHGs) are sub-units of a cohort that have different marine survival. Default is 1.
p_LHGThe proportion of the total egg production assigned to each life history group within a cohort. For example, if
Bio@n_g <- 2, thenBio@p_LHG <- c(0.9, 0.1), then 90 percent of the egg production in the first population is assigned to the first life history group and ten percent to the second LHG. Default isrep(1/Bio@n_g, Bio@n_g)p_matureEither vector by age (length
maxage) or an array with dimension[nsim, maxage, proyears]. The proportion mature by age.SRrelCharacter, stock-recruit relationship for density-dependent smolt production from fry. Either "BH" (Beverton-Holt) or "Ricker". Not used if habitat component is used. See
Habitatobject.capacityVector length
nsim. Only used ifSRrel = "BH". The asymptote, i.e., maximum juvenile production, of the Beverton-Holt stock-recruit function for density-dependent natural smolt production from egg production. Units of smolts. Not used if habitat component is used.kappaVector length
nsim. The adult productivity ratio for the stock-recruit function. Units of recruits per spawner. Natural per-capita production of recruits as the population approaches zero (density-independent component). Not used if habitat component is used.SmaxVector length
nsim. Only used ifSRrel = "Ricker". The spawner abundance that maximizes smolt production in the Ricker stock-recruit function. Units of spawners. Not used if habitat component is used.phiOptional, vector length
nsim. Egg production per smolt at unfished replacement. Units of egg per smolt. Converts productivity from units of recruits/spawner (kappa) to smolts/egg (alpha), wherealpha = kappa/phi. In simple models,phiis the product of marine survival, fecundity, and proportion female. If not provided,phiwill be calculated fromMjuv_NOS,p_mature,s_enroute,p_female,fec, andp_LHGcorresponding to the first year and weighted by life history groups. Not used if habitat component is used.tauOptional, vector length
nsim. Spawner per smolt at unfished replacement, only used ifSRrel = "Ricker". Units of spawner per smolt. Used to convertSmaxtoEmax, the corresponding egg production that maximizes smolt production, whereEmax = Smax * phi/tauand the Ricker parameterbeta = 1/Emax. In simple models,tauis the product of marine survival and proportion female. If not provided,tauwill be calculated fromMjuv_NOS,p_mature,s_enroute,p_female, andp_LHGcorresponding to the first year and weighted by life history groups. Not used if habitat component is used.Mjuv_NOSEither vector by age (length
maxage-1) or an array with dimension[nsim, maxage-1, proyears, n_g]. Natural mortality of immature natural origin fish, the value for the first age represents natural mortality from age 1 to 2, second age is mortality from age 2 to 3, and so on. To replicate the SAR parameter of a stage-specific model, setMjuv_NOS[a] = -log(SAR)whereais the age class prior to maturation (and zero for all other ages).fecVector by age (length
maxage) or an array with dimension[nsim, maxage, proyears]. Female fecundity of natural origin spawners.p_femaleNumeric. The proportion of females in the spawning population. Default is 0.5. Can also be a vector
[maxage](for situations where older spawners are predominantly female)s_enrouteNumeric. Survival of escapement to the spawning grounds (for spawning and for broodtake). Default is 1.
Creating Object
Objects can be created by calls of the form new("Bio")
Examples
showClass("Bio")
Convert conditioning model to operating model
Description
Creates an operating model from MCMC samples and data inputs of the conditioning model. Management actions for habitat, hatchery production, and harvest still need to be specified in the operating model.
Note: the function assumes the maturity values in the last conditioning year for the projection, which are likely not well informed by CWT data. Consider updating the maturity using some historical average (e.g., across most recent completed brood years).
Usage
CM2SOM(stanfit, sims, nsim = 2, seed = 1, proyears = 40)
Arguments
stanfit |
Output from |
sims |
Optional, a vector of integers indicating the MCMC iterations to convert to operating model simulations. Otherwise,
use argument |
nsim |
Integer, total number of simulations in the operating model. Only used if |
seed |
Integer, seed for sampling the MCMC output. Only used if |
proyears |
Integer, the number of projection years in the operating model |
Value
SOM object.
Plot reference points from conditioning model
Description
Plots time series of MSY reference points. Not used in automated reporting as they can be computationally expensive and individual case studies may require specific assumptions.
Usage
CM_MSY(
report,
d,
year1 = 1,
simple = FALSE,
index = NULL,
mean_bio = FALSE,
type = c("spawner", "egg", "u"),
maximize = c("MSY", "MER"),
AEQ = TRUE,
ncores = 1,
na.rm = FALSE
)
CM_Sgen(
report,
d,
year1 = 1,
simple = FALSE,
index = NULL,
mean_bio = FALSE,
ncores = 1,
na.rm = FALSE
)
Arguments
report |
List, output of state variables from individual MCMC samples, obtained with |
d |
List of data variables, obtained with |
year1 |
Numeric, first year of model |
simple |
Logical, whether to use Ricker lambert equations for MSY reference points (TRUE) or age-structured optimization (FALSE) |
index |
Integer vector to subset years with which to calculate reference points. Can be used
to reduce computation or average biological parameters from a subset of years, see |
mean_bio |
Logical, whether to average the natural mortality and maturity parameters across
years indicated in |
type |
Character, the type of reference point to calculate |
maximize |
Character, whether the numerical optimization maximizes catch (MSY) or excess recruitment (MER). For testing only,
should not impact results. Only used if |
AEQ |
Logical, whether to use adult equivalents when calculating MSY for preterminal fisheries#' Only used if |
ncores |
Numeric, number of processors for parallel computation. Useful if calculating numerically for many MCMC samples |
na.rm |
Logical, whether to exclude negative values from the median in figures |
Value
ggplot object
See Also
Estimation function for conditioning model
Description
Population dynamics model of an age structured salmon population. Used with RTMB to estimate historical reconstruction from data.
Usage
CM_int(p, d)
Arguments
p |
List of parameter variables. See |
d |
List of data variables. See |
Value
Numeric, objective function value (log-posterior)
Author(s)
Q. Huynh with Stan code provided by J. Korman and C. Walters
Deprecated functions
Description
Deprecated performance metric functions. These functions are now replaced with functions of same name
but prefixed with P_.
Usage
PNI50(...)
PNI80(...)
WILD50(...)
SMSY85(...)
Sgen100(...)
Arguments
... |
Same arguments as |
Value
A vector of probabilities
See Also
Solve for fishing effort
Description
Internal solver used by catch_func() to calculate the fishing effort needed to achieve target harvest rate or catch rate,
subject to partial retention due to mark-selective fishing.
Harvest rate is discounted by adult equivalents for preterminal fisheries.
Usage
Effort_solver(
Eff,
N,
vul,
ret,
release_mort,
type = c("u", "catch"),
u = 0,
K = 0,
AEQ = array(1, dim(N)),
p_mature = array(1, dim(N))
)
Arguments
Eff |
Numeric, fishing effort |
N |
Array |
vul |
Array |
ret |
Vector |
release_mort |
Vector |
type |
Character, either |
u |
Numeric, harvest rate target |
K |
Numeric, kept catch target |
AEQ |
Array |
p_mature |
Array |
Value
Numeric. Returns the difference between the realized harvest rate (for the given value of Eff) and the target
Class "Habitat"
Description
The component of the operating model that controls survival in the freshwater environment. Includes changes in survival from either environmental/climate effects or habitat mitigation.
Slots
NameCharacter. Identifying name
use_habitatLogical. If
TRUE, utilize stage-specific density-dependent functions from egg production from incubation mortality, egg-to-fry production, and fry-to-smolt production with annual deviations. Otherwise, the density-dependence is modeled for egg-to-smolt survival. SeeBioobject.prespawn_relCharacter, density-dependent function for pre-spawn mortality, e.g., for spawners to reach spawning sites. Choices are "BH" (Beverton-Holt) or "HS" (hockey stick). Default is "BH".
prespawn_prodNumeric, productivity for pre-spawn mortality. Default is 1. Default if
Inf.prespawn_capacityNumeric, capacity for pre-spawn mortality. Default is
Inf, i.e., density-independence. Default isInf.egg_relCharacter, density-dependent function for egg production from total spawning output. Choices are "BH" (Beverton-Holt) or "HS" (hockey stick). Default is "BH".
egg_prodNumeric, productivity for egg production from total spawning output (incubation). Default is 1. Default if
Inf.egg_capacityNumeric, capacity for egg production from total spawning output (incubation). Default is
Inf, i.e., density-independence. Default isInf.fry_relCharacter, density-dependent function for egg-to-fry production. Choices are "BH" (Beverton-Holt) or "HS" (hockey stick). Default is "BH".
fry_prodNumeric between 0-1, productivity for egg production from total spawning output, i.e., maximum survival as egg production approaches zero. Default is 0.4.
fry_capacityNumeric, capacity for fry production from egg production. Default is
Inf, i.e., for density-independence. Default isInf.fry_sdevMatrix
[nsim, proyears], deviations from the density-dependent egg-fry survival. Can be utilized to incorporate time-varying environmental, climate, or habitat mitigation effects. Default ismatrix(1, nsim, proyears).smolt_relCharacter, density-dependent function for fry-to-smolt production. Choices are "BH" (Beverton-Holt) or "HS" (hockey stick). Default is "BH".
smolt_prodNumeric between 0-1, productivity for smolt production from fry, i.e., maximum survival as fry production approaches zero. Default is 1.
smolt_capacityNumeric, capacity for smolt production from fry production. Set to
Inffor density-independence. Default isInf.smolt_sdevMatrix
[nsim, proyears], deviations from the density-dependent fry-smolt survival. Can be utilized to incorporate time-varying environmental, climate, or habitat mitigation effects. Default ismatrix(1, nsim, proyears).
Creating Object
Objects can be created by calls of the form new("Habitat")
Examples
showClass("Habitat")
Class "Harvest"
Description
The component of the operating model that controls marine harvest.
Slots
NameCharacter. Identifying name
type_PTCharacter. Whether to manage preterminal fishery catch from exploitation rate ("u") or catch target ("catch"). Default is "u".
type_TCharacter. Whether to manage terminal fishery catch from exploitation rate ("u") or catch target ("catch"). Default is "u".
u_preterminalNumeric, matrix
[nsim, proyears], or function. Iftype_PT = "u", the harvest rate of the immature component of the population in the pre-terminal fishery. The harvest rate is the ratio to kept AEQ catch to (kept AEQ catch + return), where AEQ are adult equivalents. Function should be of the formfunction(NO, HO, m) return(u).u_terminalNumeric, matrix
[nsim, proyears], or function. Iftype_T = "u", the harvest rate (ratio of kept catch to of the terminal marine fishery. Function should be of the formfunction(NO, HO, m) return(u).K_PTNumeric or function. If
type_PT = "catch", the catch target of the immature component of the population in the pre-terminal fishery. Function should be of the formfunction(NO, HO, m) return(K).K_TNumeric or function. If
type_T = "catch", the catch target of the return in the terminal fishery. Function should be of the formfunction(NO, HO, m) return(K).MSF_PTLogical. Whether to implement mark-selective fishing in the preterminal fishery, with no retention on unmarked fish.
MSF_TLogical. Whether to implement mark-selective fishing in the terminal fishery, with no retention on unmarked fish.
release_mortVector length 2. The proportion of released fish that die after release, in the pre-terminal and terminal fishery. Implemented to model mark-selective fishing. Not used if either
MSF_PTorMSF_TisFALSE.vulPTVector length
maxageor matrix[nsim, maxage]. Vulnerability schedule (between 0-1) in the preterminal fishery. Values indicate the proportion of fishing mortality experienced by each age class, whereF_preterminal = -log(1 - u_preterminal).vulTVector length
maxageor matrix[nsim, maxage]. Vulnerability schedule (between 0-1) in the terminal fishery. Values indicate the proportion of fishing mortality experienced by each age class, whereF_terminal = -log(1 - u_terminal).
Creating Object
Objects can be created by calls of the form new("Harvest")
Examples
showClass("Harvest")
Class "Hatchery"
Description
The component of the operating model that controls the hatchery management and in-river removals.
Details
Various parameters can be stochastic (length nsim) or input as a single numeric
(value identical across all simulations).
A description of the fitness parameters and hatchery dynamics is available in the online documentation.
Slots
NameCharacter. Identifying name
n_rInteger. Number of release strategies, sub-groups of fish with different survival schedules. Default is one.
n_yearlingVector length
n_r. The target number of yearlings released by release strategy. No hatchery is modeled ifsum(n_yearling, n_subyearling) = 0. are zero. Default is zero. Yearlings are differentiated from sub-yearlings only in the hatchery survival parameter, e.g., lower egg-yearling survival than for egg-subyearling, so more brood is needed for yearling releases.n_subyearlingVector length
n_r. The target number of subyearlings released. No hatchery is modeled ifsum(n_yearling, n_subyearling) = 0are zero. Default is zero. Yearlings are differentiated from sub-yearlings only in the hatchery survival parameter, e.g., lower egg-yearling survival than for egg-subyearling, so more brood is needed for yearling releases.yearling_DDLogical, whether freshwater yearling survival after release is density-dependent, in competition with natural-origin juveniles. Default is FALSE. Likely relevant only for stream types where there is substantial residence time before outmigration.
subyearling_DDLogical, whether freshwater subyearling survival after release is density-dependent, in competition with natural-origin juveniles. Default is FALSE. Likely relevant only for stream types where there is substantial residence time before outmigration.
s_prespawnNumeric. The survival of broodtake prior to egg production.
1 - s_prespawnis the proportion of fish not used for hatchery purposes, e.g., mortality or other resesarch purposes. Used to back-calculate the broodtake fromn_yearlingandn_subyearling. Default is 1.s_egg_smoltNumeric. The survival of eggs to the smolt life stage (for yearling release). Used to back-calculate the broodtake from
n_yearlingandn_subyearling. Default is 1.s_egg_subyearlingNumeric. The survival of eggs to subyearling life stage (for subyearling release). Used to back-calculate the broodtake from
n_yearlingandn_subyearling. Default is 1.Mjuv_HOSEither vector by age (length
maxage-1) or an array with dimension[nsim, maxage-1, proyears, n_r]. Natural mortality of immature hatchery origin fish. To replicate the SAR parameter of a stage-specific model, setMjuv_HOS[a] = -log(SAR)for the age class prior to maturation (and zero for all other ages).p_mature_HOSVector by age (length
maxage) or an array with dimension[nsim, maxage, proyears, n_r]for the maturity of hatchery spawners. Default is set equal toBio@p_maturefor all release strategies.stray_externalMatrix by age (length
maxage) and release strategyn_rthat denotes the annual number of hatchery origin strays from other populations/systems not included in the operating model. Default is zero. External strays are added at the escapement life stage, assumed unmarked. For multi-population models with straying within the system, see alsoSOM@straymatrix.gammaNumeric. The relative reproductive success of hatchery origin spawners (relative to natural origin spawners). Default is 1.
mNumeric. The mark rate of hatchery origin fish, which affects selective broodtake and fishery retention if mark-selective fishing is utilized. Set m = 1 for AHA compatibility with
ptarget_NOB. Default is zero.f_broodFunction that calculates the natural origin brood and hatchery origin brood from the escapement (after en-route mortality). Function should be of the form
function(NO, HO, stray, m) {return(list(NOB, HOB_marked, HOB_unmarked, HOB_stray))}. Allows for bespoke rules for broodtake.brood_importNot used if
f_broodis provided Matrix by age (lengthmaxage) for the number of annual imported hatchery origin broodstock. Egg production is weighted byfec_brood. To meet hatchery production target releases, imported brood and local marked brood are used indiscriminately. Default imported brood is zero.pmax_escNot used if
f_broodis provided Numeric. The maximum proportion of total escapement (after en route mortality) that could be used as broodtake. Set to 1 for AHA compatibility. Default is 0.75.pmax_NOBNot used if
f_broodis provided Numeric. The maximum proportion of the natural origin escapement (after en route mortality andpmax_esc) to be used as broodtake. If broodstock is limited bypmax_esc < 1, then this parameter should be 1. Default is 1.ptarget_NOBNot used if
f_broodis provided Numeric. The target proportion of the natural origin broodtake relative to the overall broodtake, assuming the mark rate is 1 and natural origin fish can be identified in the hatchery. The realized proportion may be lower if there are insufficient natural origin escapement. If the mark rate < 1, then this target proportion identifies the proportion of unmarked fished in the broodtake. If mark rate = 0, then pNOB is equal to the proportion in the escapement. Default is 0.9.phatcheryNot used if
f_broodis provided Numeric. Optional parameter (default isNA). If set to a numeric between 0-1, this value is the proportion of the hatchery origin escapement that return to the hatchery, for example, by removal from spawning grounds or swim-in facilities. These fish are available for broodtake. None of these fish will spawn in the natural environment. With the default option,NAallows all hatchery origin escapement to be available for brood (the remainder go to the spawning grounds).premove_HOSNumeric or function. The target proportion of the hatchery origin fish to be removed from the spawning grounds (in order to ensure a high proportion of NOS). The proportion of hatchery fish removed is discounted by the mark rate, i.e.,
p = premove_HOS * m. The removed hatchery-origin fish do not spawn and are not available for broodtake. A value less than one can represent imperfect implementation of weir removal. Default is zero. This slot can take a function that returns the proportion (p) based on hatchery-origin and natural-origin abundance (after brood removal), thus allowing for bespoke rules for in-river harvest. The function should be of the form:function(NO, HO, m) {return(p)}.premove_NOSNumeric or function. The target proportion of the natural origin fish to be removed from the spawning grounds, for example, through an in-river fishery. The proportion of natural fish removed is adjusted by the mark rate, i.e.,
p = premove_NOS * (1-m). Default is zero. This slot can take a function that returns the proportion (p) based on hatchery-origin and natural-origin abundance (after brood removal), thus allowing for bespoke rules for in-river harvest. The function should be of the form:function(NO, HO, m) {return(p)}.fec_broodVector length
maxageor an array with dimension[nsim, maxage, proyears]. The fecundity schedule of broodtake to calculate the total egg production for the hatchery. If missing, usesBio@fec.p_female_broodNumeric or vector
maxage. Proportion of females of brood used to calculate hatchery egg production, for situations with sex-selective brood. If missing, usesBio@p_female.fitness_typeCharacter vector length 2. The fitness function to apply in the natural and hatchery environment, respectively. For each, either "Ford" or "none".
thetaVector length 2. The optimum phenotype value for the natural and hatchery environments.
rel_lossVector length 3. The loss in fitness apportioned among the egg, fry, and smolt life stages which reduces survival. Theoretically, the three values should sum to 1. Alternatively, set to zero to set fitness loss to zero for that specific life stage (survival is one).
zbar_startVector length 2. The mean phenotype value in the natural and hatchery populations at the start of the projection. Alternatively, an array by dimension
[nsim, maxage, 2], where the age slot corresponds to cohort.fitness_varianceNumeric. The variance (omega-squared) of the fitness function. Assumed identical between the natural and hatchery environments. Default is 100.
phenotype_varianceNumeric. The variance (sigma-squared) of the phenotypic trait (theta). Assumed identical between the natural and hatchery environments. Default is 10.
heritabilityNumeric or vector length
[nsim]. The heritability (h-squared) of the phenotypic trait. Between 0-1. Default is 0.5fitness_floorNumeric. The minimum fitness value in the natural and hatchery environments, i.e., fitness cannot drop below this threshold. Default is 0.5.
Creating Object
Objects can be created by calls of the form new("Hatchery")
Examples
showClass("Hatchery")
Class "Historical"
Description
Optional component of the operating model that specifies the historical dynamics. The default option starts the projection with 1000 natural-origin juveniles and 1000 hatchery-origin juveniles (if there is hatchery production) in the oldest age class, representing single-brood year returns since there is only one age class in the population. Specify the abundance in all age class to simulate multiple brood-year returns.
Slots
NameCharacter. Identifying name
InitNjuv_NOSArray by
[nsim, maxage, n_g]. The abundance of immature natural origin fish at the beginning of the projection. Default assumes 1000 in the oldest age class, which creates a population with single brood year returns.InitNjuv_HOSArray by
[nsim, maxage, n_r]. The abundance of immature hatchery origin fish at the beginning of the projection. Default assumes 1000 in the oldest age class, which creates a population with single brood year returns.
Creating Object
Objects can be created by calls of the form new("Historical")
Examples
showClass("Historical")
Example performance metrics
Description
Functions that evaluate return probabilities of outcomes from the simulations.
Usage
P_PNI50(SMSE, Ref = 0.5, Yrs = NULL)
P_PNI80(SMSE, Ref = 0.8, Yrs = NULL)
P_WILD50(SMSE, Ref = 0.5, Yrs = NULL)
P_SMSY85(SMSE, Ref = 0.85, Yrs = NULL)
P_SMSY80(SMSE, Ref = 0.85, Yrs = NULL)
P_Sgen100(SMSE, Ref = 1, Yrs = NULL)
Arguments
SMSE |
SMSE object returned by |
Ref |
Threshold for the performance metric, used to calculate the probability that the metric exceeds this value |
Yrs |
Numeric vector of length 2 to indicate the year range over which to summarize performance. If NULL, the performance is summarized over all projection years. |
Details
-
P_PNI50calculates the probability that PNI exceeds 0.50 (threshold for an integrated-transition population, Withler et al. 2018) -
P_PNI80calculates the probability that PNI exceeds 0.80 (threshold for an integrated-wild population, Withler et al. 2018) -
P_WILD50calculates the probability that at least 50 percent of natural spawners are wild -
P_SMSY80calculates the probability that NOS exceeds 0.80 SMSY -
P_SMSY85calculates the probability that NOS/SMSY exceeds 0.85 SMSY -
P_Sgen100calculates the probability that NOS exceeds Sgen
Value
A vector of probabilities corresponding to population
References
Withler et al. 2018. Genetically Based Targets for Enhanced Contributions to Canadian Pacific Chinook Salmon Populations. DFO Can. Sci. Advis. Sec. Res. Doc. 2018/019. xii + 88 p.
Class "SMSE"
Description
Stores the outputs from the simulation of salmon operating models.
Details
In generation t, proportionate natural influence (PNI) is defined as:
\textrm{PNI}_t = \dfrac{p^\textrm{NOB}_t}{p^\textrm{NOB}_t + p^\textrm{HOSeff}_t}
with p^\textrm{HOSeff} = \textrm{HOSeff}/(\textrm{NOS} + \textrm{HOSeff}).
The proportion of wild salmon is defined as:
p^{\textrm{WILD}}_t = q^\textrm{HOScen}_t
\dfrac{(q^\textrm{HOScen}_{t-1})^2}
{(q^\textrm{HOScen}_{t-1})^2 + 2\gamma \times p^\textrm{HOScen}_{t-1} q^\textrm{HOScen}_{t-1} +
\gamma^2 (p^\textrm{HOScen}_{t-1})^2}
where q = 1-p and p^\textrm{HOScen} = \textrm{HOS}/(\textrm{NOS} + \textrm{HOS}).
Slots
NameCharacter. Identifying name
proyearsInteger. The number of projected years
nsimInteger. The number of simulations
nstocksInteger. The number of stocks
SnamesCharacter. Stock names
Egg_NOSArray
[nsim, nstocks, proyears]. Spawning output, i.e., egg production, of natural origin spawners.Egg_HOSArray
[nsim, nstocks, proyears]. Spawning output of hatchery origin spawners.Fry_NOSArray
[nsim, nstocks, proyears]. Fry that are offspring of natural origin spawners.Fry_HOSArray
[nsim, nstocks, proyears]. Fry that are offspring of hatchery origin spawners.Smolt_NOSArray
[nsim, nstocks, proyears]. Smolts that are offspring of natural origin spawners.Smolt_HOSArray
[nsim, nstocks, proyears]. Smolts that are offspring of hatchery origin spawners.Smolt_RelArray
[nsim, nstocks, proyears]. Smolts that are offspring of broodtake, i.e., hatchery releases.Njuv_NOSArray
[nsim, nstocks, nage, proyears]. Abundance of juvenile natural origin fish at the beginning of the year.Njuv_HOSArray
[nsim, nstocks, nage, proyears]. Abundance of juvenile hatchery origin fish at the beginning of the year.Return_NOSArray
[nsim, nstocks, nage, proyears]. Mature fish that will be natural origin spawners.Return_HOSArray
[nsim, nstocks, nage, proyears]. Mature fish that will be hatchery origin spawners.Escapement_NOSArray
[nsim, nstocks, nage, proyears]. The escapement of mature fish that will be natural origin spawners.Escapement_HOSArray
[nsim, nstocks, nage, proyears]. The escapement of mature fish that will be hatchery origin spawners.NOBArray
[nsim, nstocks, nage, proyears]. Natural origin broodtake.HOBArray
[nsim, nstocks, nage, proyears]. Hatchery origin broodtake (local + strays).HOB_strayArray
[nsim, nstocks, nage, proyears]. Hatchery origin broodtake (strays only).HOB_importArray
[nsim, nstocks, nage, proyears]. Imported hatchery origin broodtake used for hatchery production.NOSArray
[nsim, nstocks, nage, proyears]. Natural origin spawners.HOSArray
[nsim, nstocks, nage, proyears]. Hatchery origin spawners (local + strays).HOS_strayArray
[nsim, nstocks, nage, proyears]. Hatchery origin spawners (strays only).HOS_effectiveArray
[nsim, nstocks, nage, proyears]. Hatchery origin spawners (local + strays) discounted bygamma.KPT_NOSArray
[nsim, nstocks, proyears]. Pre-terminal fishery kept catch of natural origin spawners.KT_NOSArray
[nsim, nstocks, proyears]. Terminal fishery kept catch of natural origin spawners.KPT_HOSArray
[nsim, nstocks, proyears]. Pre-terminal fishery kept catch of hatchery origin spawners.KT_HOSArray
[nsim, nstocks, proyears]. Terminal fishery kept catch of hatchery origin spawners.DPT_NOSArray
[nsim, nstocks, proyears]. Pre-terminal fishery released catch (live and dead) of natural origin spawners.DT_NOSArray
[nsim, nstocks, proyears]. Terminal fishery released catch (live and dead) of natural origin spawners.DPT_HOSArray
[nsim, nstocks, proyears]. Pre-terminal fishery released catch (live and dead) of hatchery origin spawners.DT_HOSArray
[nsim, nstocks, proyears]. Terminal fishery released catch (live and dead) hatchery origin spawners.UPT_NOSArray
[nsim, nstocks, proyears]. Pre-terminal fishery harvest rate (from adult equivalent kept catch) of natural origin spawners.UT_NOSArray
[nsim, nstocks, proyears]. Terminal fishery harvest rate of natural origin spawners.UPT_HOSArray
[nsim, nstocks, proyears]. Pre-terminal fishery harvest rate of hatchery origin spawners.UT_HOSArray
[nsim, nstocks, proyears]. Terminal fishery harvest rate of hatchery origin spawners.ExPT_NOSArray
[nsim, nstocks, proyears]. Pre-terminal fishery exploitation rate (from kept catch and dead releases in adult equivalents) of natural origin spawners.ExT_NOSArray
[nsim, nstocks, proyears]. Terminal fishery exploitation rate of natural origin spawners.ExPT_HOSArray
[nsim, nstocks, proyears]. Pre-terminal fishery exploitation rate of hatchery origin spawners.ExT_HOSArray
[nsim, nstocks, proyears]. Terminal fishery exploitation rate of hatchery origin spawners.fitnessArray
[nsim, nstocks, 2, proyears]. Fitness of the population in the natural (1) and hatchery (2) environments.pNOBArray
[nsim, nstocks, proyears]. Proportion of natural fish in the brood.pHOS_censusArray
[nsim, nstocks, proyears]. Proportion of spawners of hatchery origin, weighted by age class fecundity.pHOS_effectiveArray
[nsim, nstocks, proyears]. Proportion of spawners of hatchery origin, discounted bygamma, weighted by age class fecundity.PNIArray
[nsim, nstocks, proyears]. Proportionate natural influence, index of gene flow from hatchery to the natural environment.p_wildArray
[nsim, nstocks, proyears]. Proportion of wild spawners, natural spawners whose parents were also produced in the natural environment assuming non-assortative mating, defined under Canada's Wild Salmon Policy.Mjuv_lossArray
[nsim, nstocks, nage-1, proyears]. Realized juvenile natural mortality, which may differ from inputs due to fitness loss.MiscList. Miscellaneous output:
-
Reffor reference points -
SOMfor the SOM object (updated bycheck_SOM()). -
LHGlistnstockslong containing state variables by natural-origin life history group -
RSlistnstockslong containing state variables by hatchery-origin release strategy
-
Creating Object
Objects can be created by calls of the form new("SMSE")
References
Withler et al. 2018. Genetically Based Targets for Enhanced Contributions to Canadian Pacific Chinook Salmon Populations. DFO Can. Sci. Advis. Sec. Res. Doc. 2018/019. xii + 88 p.
Examples
showClass("SMSE")
Class "SOM"
Description
An object containing all the parameters for a salmon operating model (SOM).
Slots
NameCharacter. Identifying name
nsimInteger. Number of simulations
proyearsInteger. The number of projected years
seedInteger. A random seed to ensure users can reproduce results exactly
BioBio object informing biological parameters and natural production. Provide a list of Bio objects for multi-population models.
HabitatHabitat object containing management levers for controlling survival in the freshwater environment. Provide a list of Habitat objects for multi-population models.
HatcheryHatchery object containing management levers for hatchery production and in-river removals. Provide a list of Hatchery objects for multi-population models.
HarvestHarvest object containing management levers for marine harvest. Provide a list of Harvest objects for multi-population models.
HistoricalHistorical object to inform historical reconstruction and informing starting abundance for the projection. Provide a list of Historical objects for multi-population models.
strayMatrix
[np, np]wherenp = length(Bio)and rowpindicates the re-assignment of hatchery fish to each population when they mature (at the recruitment life stage). For example,SOM@stray <- matrix(c(0.75, 0.25, 0.25, 0.75), 2, 2)indicates that 75 percent of mature fish return to their natal river and 25 percent stray in both populations. By default, an identity matrix is used (no straying).
Objects from the Class
Objects can be created by calls of the form
new("SOM", Bio, Habitat, Hatchery, Harvest, Historical).
Brood function
Description
Calculates broodtake and in-river removals from escapement of marine fisheries. This function also applies en-route mortality.
Usage
brood_func(
Nage_NOS,
Nage_HOS,
stray_external,
m,
m_stray,
s_enroute,
hatchery_args
)
Arguments
Nage_NOS |
Array |
Nage_HOS |
Array |
stray_external |
Array |
m |
Numeric, mark rate of |
m_stray |
Numeric, mark rate of |
s_enroute |
Numeric, en-route survival |
hatchery_args |
List of various hatchery arguments created by |
Value
Named list:
-
broodtakelist returned bycalc_broodtake() -
hatchery_productionlist returned bycalc_yearling() -
spawnerslist returned bycalc_spawners()
See Also
Calculate abundance from density-dependent mortality
Description
Calculates the abundance of survivors after applying either a Beverton-Holt or Ricker stock-recruit relationship.
Usage
calc_SRR(N1, N2 = N1, p, capacity, type = c("BH", "Ricker", "HS"))
Arguments
N1 |
Numeric, the initial abundance that scales the density-independent survival term |
N2 |
Numeric, the initial abundance that scales the density-dependent survival term |
p |
Numeric, the productivity parameter that sets the maximum survival as the initial abundance approaches zero |
capacity |
Numeric, the capacity parameter that set the maximum survivors |
type |
Character, the functional form of the stock-recruit relationship |
Details
The Beverton-Holt stock recruit relationship is of the following form:
\textrm{Smolt} = \dfrac{\alpha N_1}{1 + \beta N_2}
where \alpha = P, \beta = P/C.
The Ricker stock recruit relationship is of the following form:
\textrm{Smolt} = \alpha N_1 \exp(-\beta N_2)
where \alpha = P, \beta = P/(Ce), e is Euler's number.
Productivity P is in terms of abundance per unit of N_1 and N_2.
The hockey stick is of the following form:
\textrm{Smolt} =
\begin{cases}
p N_1 &, N_1 \le \frac{N_1}{N_2} \times C\\
\frac{N_1}{N_2} \times C &, \textrm{otherwise}
\end{cases}
Value
Numeric, the abundance of survivors
See Also
Examples
N1 <- 100
N2 <- 200
p <- 10
capacity <- 250
calc_SRR(N1, N2, p, capacity, type = "BH")
# Validation
SRRpars <- calc_SRRpars(p, capacity, type = "BH")
a <- SRRpars[1]
b <- SRRpars[2]
a * N1/(1 + b * N2)
Convert density-dependent survival parameters
Description
Converts from capacity/productivity parameters to alpha/beta stock-recruit parameters where productivity is in terms of smolts per spawner and alpha is terms of smolts per egg.
Usage
calc_SRRpars(p, capacity, f = 1, p_female = 1, type = c("BH", "Ricker", "HS"))
Arguments
p |
Numeric, the productivity parameter that sets the maximum survival as the initial abundance approaches zero |
capacity |
Numeric, the capacity parameter that set the maximum survivors |
f |
Fecundity, the spawning output per mature female |
p_female |
The proportion of females per spawner |
type |
Character, the functional form of the stock-recruit relationship |
Details
\alpha = \dfrac{P}{f \times p_{female}}
For the Beverton-Holt stock recruit relationship:
\beta = \dfrac{\alpha}{C}
For the Ricker stock recruit relationship:
\beta = \dfrac{\alpha}{Ce}
, e is Euler's number.
Value
Numeric vector length 2 for alpha and beta value, respectively
See Also
Examples
N1 <- 100
N2 <- 200
p <- 10
capacity <- 250
calc_SRRpars(p, capacity, type = "BH")
Ricker reference points
Description
Compute reference points (Umsy, Smsy, and Sgen) from Ricker stock-recruit function based on Scheuerell (2016).
Usage
calc_Smsy_Ricker(loga, b)
calc_Umsy_Ricker(loga)
calc_Sgen_Ricker(loga, b)
Arguments
loga |
Numeric, alpha parameter (returns per spawner) in the Ricker function: |
b |
Numeric, beta parameter |
Value
All three functions return a numeric
References
Scheuerell, M.D. 2016. An explicit solution for calculating optimum spawning stock size from Ricker’s stock recruitment model. PeerJ 4:e1623. doi:10.7717/peerj.1623
See Also
Examples
a <- 3
Smax <- 100
b <- 1/Smax
calc_Smsy_Ricker(log(a), b)
calc_Umsy_Ricker(log(a))
calc_Sgen_Ricker(log(a), b)
Solve for broodtake numbers
Description
Internal functions to calculate broodtake with various constraints, called by brood_func().
calc_broodtake() is a wrapper function.
calc_broodtake_custom() uses a user-provided function to generate brood numbers and adjusts
downwards if egg production exceeds the target.
.broodtake_func() is the optimization function used to calculate broodtake
Usage
calc_broodtake(
NO,
HO,
stray,
brood_import,
ptarget_NOB,
pmax_NOB,
phatchery,
egg_target,
p_female,
fec,
s_prespawn,
m
)
calc_broodtake_custom(
f_brood,
NO,
HO,
stray,
p_female,
fec,
s_prespawn,
m,
egg_target
)
.broodtake_func(
ptake_unmarked,
NO,
HO,
stray,
brood_import,
phatchery,
p_female,
fec,
egg_target,
s_prespawn,
ptarget_NOB,
m = 1,
opt = TRUE
)
Arguments
NO |
Matrix |
HO |
Matrix |
stray |
Matrix |
brood_import |
Vector |
ptarget_NOB |
Numeric, target proportion of |
pmax_NOB |
Numeric, maximum proportion of |
phatchery |
Numeric, proportion of |
egg_target |
Numeric, target egg production from which to back-calculate brood numbers |
p_female |
Vector |
fec |
Vector |
s_prespawn |
Numeric, survival of brood prior to egg production |
m |
Numeric, mark rate of |
f_brood |
Function that calculates the brood numbers |
ptake_unmarked |
Numeric, proportion of unmarked fish used for brood |
opt |
Logical, whether the function is used for optimization (TRUE) or reporting (FALSE) |
Value
calc_broodtake() returns a list from .broodtake_func()
calc_broodtake_custom() returns a named list, same format as calc_broodtake()
.broodtake_func() returns a numeric if opt = TRUE: log(p_unmarked) - log(ptarget_NOB), otherwise
a named list of brood and egg production.
-
egg_NOBMatrix[nage, n_g] -
egg_HOB_unmarkedMatrix[nage, n_r](including strays) -
egg_HOB_markedMatrix[nage, n_r] -
egg_HOB_importVector[nage] -
ptake_unmarkedNumeric -
ptake_markedNumeric -
pNOBNumeric -
NOBNumeric -
HOB_unmarkedMatrix[nage, n_r] -
HOB_markedMatrix[nage, n_r] -
HOB_importMatrix[nage, n_r] -
HOB_strayVector[nage]
Calculate equilibrium quantities with life history groups
Description
Calculate eggs/smolt or spawners/smolt based on life history parameters (survival, maturity, fecundity)
Usage
calc_phi(
Mjuv,
p_mature,
p_female,
fec,
s_enroute = 1,
n_g = 1,
p_LHG,
output = c("egg", "spawner")
)
Arguments
Mjuv |
Matrix |
p_mature |
Matrix |
p_female |
Numeric. Proportion female |
fec |
Matrix |
s_enroute |
Numeric, en-route survival of escapement to spawning grounds |
n_g |
Integer. Number of life history groups |
p_LHG |
Vector length |
output |
Character to indicate the output units, e.g., "egg" returns eggs per smolt, and "spawner" returns spawners per smolt |
Value
Numeric, units depend on "output" argument
Proportion wild spawners
Description
Calculate the proportion of wild spawners from a time series of spawners
-
calc_pwild()is the simple calculation based on the proportion of hatchery spawners -
calc_pwild_age()performs the calculation weighted by age class fecundity
Usage
calc_pwild(pHOS_cur, pHOS_prev, gamma)
calc_pwild_age(NOS_a, HOS_a, fec, gamma)
Arguments
pHOS_cur |
Numeric, proportion of hatchery spawners in current generation |
pHOS_prev |
Numeric, proportion of hatchery spawners in previous generation |
gamma |
Numeric, reduced reproductive success of hatchery spawners |
NOS_a |
Array |
HOS_a |
Array |
fec |
Array |
Value
calc_pwild_age() a matrix of pWILD by simulation and year. calc_pwild() returns a numeric
Examples
calc_pwild(0.9, 0.4, 0.8)
Reference points
Description
Calculate MSY and Sgen reference points for the operating model. Uses the biological parameters (maturity, natural mortality) in the last year of the projection.
-
calc_MSY()calculates the MSY reference points from a set of biological and fishery parameters -
calc_Sgen()calculates the Sgen, the spawner abundance that would reach the spawner abundance at MSY after one generation without fishing -
calc_ref()is a wrapper function that calculates MSY and Sgen for an operating model
Usage
calc_ref(SOM, rel_F, check = TRUE, maximize = c("MSY", "MER"), AEQ = TRUE)
calc_MSY(
Mjuv,
fec,
p_female,
rel_F,
vulPT,
vulT,
p_mature,
s_enroute,
n_g = 1,
p_LHG = 1,
SRRpars,
maximize = c("MSY", "MER"),
AEQ = TRUE,
F_search = c(1e-08, 5)
)
calc_Sgen(
Mjuv,
fec,
p_female,
rel_F,
vulPT,
vulT,
p_mature,
s_enroute,
n_g = 1,
p_LHG = 1,
SRRpars,
SMSY,
F_search = c(1e-08, 100),
nyears
)
Arguments
SOM |
An object of class SOM |
rel_F |
Numeric length 2, indicates the relative effort in the preterminal and terminal fisheries, with a maximum value of 1.
The default is |
check |
Logical, whether to check the SOM object using |
maximize |
Character, whether the MSY calculation is the optimum that maximizes catch ( |
AEQ |
Logical, whether to maximize preterminal catch in terms of adult equivalents |
Mjuv |
Numeric |
fec |
Numeric |
p_female |
Numeric for proportion female spawners |
vulPT |
Numeric |
vulT |
Numeric |
p_mature |
Numeric |
s_enroute |
Numeric for en-route survival of escapement to spawning grounds |
n_g |
Integer, number of life history groups within a cohort |
p_LHG |
Numeric |
SRRpars |
Data frame, one row, that contains the stock recruit parameters that predicts density-dependent survival at the egg-smolt life stage |
F_search |
Numeric, length 2 for the range of F values to search for the instantaneous fishing mortality that produces MSY |
SMSY |
Numeric, spawning abundance at MSY |
nyears |
Integer, number of years to project the population with no fishing to reach |
Value
-
calc_MSYreturns a vector of various state variables (catch, exploitation rate, egg production, spawners) at MSY -
calc_Sgenreturns a numeric -
calc_refreturns a list by stock, each containing a matrix of MSY state variables and Sgen by simulation
See Also
Examples
ref_simple <- calc_ref(simple_SOM)
ref_multi <- calc_ref(multi_SOM)
Smolt production
Description
Calculate smolt production from base stock-recruit parameters and fitness loss
Usage
calc_smolt(
N1,
N2 = N1,
kappa,
capacity,
Smax,
phi = 1,
tau = 1,
fitness_loss = 1,
SRrel = c("BH", "Ricker"),
per_recruit = FALSE
)
Arguments
N1 |
Egg production for the density-independent component of the stock-recruit relationship. Can be the number of spawners if |
N2 |
Egg production for the density-dependent component of the stock-recruit relationship (only used if |
kappa |
Base productivity parameter |
capacity |
Base capacity parameter if |
Smax |
Base Smax parameter if |
phi |
Unfished egg per smolt ( |
tau |
Unfished spawner per smolt |
fitness_loss |
Survival term to reduce smolt production due to fitness, between 0-1 |
SRrel |
Character for the stock-recruit function |
per_recruit |
Logical, whether N1 is a per recruit quantity (TRUE) or in absolute numbers (FALSE) |
Value
Numeric
Calculate spawners after broodtake
Description
Internal function that calculates remaining spawners after broodtake and additional removals.
Usage
calc_spawners(broodtake, NO, HO, stray, phatchery, premove_HOS, premove_NOS, m)
Arguments
broodtake |
List, returned by |
NO |
Matrix |
HO |
Matrix |
stray |
Matrix |
phatchery |
Numeric, proportion of |
premove_HOS |
Numeric, proportion of HO fish to remove (after brood). Can also be a function |
premove_NOS |
Numeric, proportion of NO fish to remove (after brood). Can also be a function |
m |
Numeric, mark rate |
Value
Named list:
NOS
[nage, n_g]natural-origin spawnersHOS
[nage, n_r]hatchery-origin spawnersHOS_stray
[nage, n_r]spawners that are straysNO_remove
[nage, n_g]natural-origin fish removed before spawningHO_remove
[nage, n_r]hatchery-origin fish removed before spawning
Calculate hatchery releases
Description
From egg target, calculate production of yearlings and subyearlings conditional on survival and proportion of releases.
.yearling_func() is the optimization function that determines proportions.
Usage
calc_yearling(egg_target, s_yearling, s_subyearling, p_yearling, p_subyearling)
.yearling_func(
p_egg_yearling,
egg_target,
s_yearling,
s_subyearling,
p_yearling,
opt = TRUE
)
Arguments
egg_target |
Numeric |
s_yearling |
Numeric, survival from egg to yearling |
s_subyearling |
Numeric, survival from egg to subyearling |
p_yearling |
Vector |
p_egg_yearling |
Numeric, proportion to eggs to become yearlings |
opt |
Logical, whether the function is used for optimization (TRUE) or reporting (FALSE) |
Value
calc_yearling() returns a named list returned by .yearling_func()
.yearling_func() returns a numeric if opt = TRUE: yearling/(yearling + subyearling) - p_yearling.
Otherwise, log(p_unmarked) - log(ptarget_NOB)', otherwise a named list:
-
yearlingVector[n_r]of yearling releases -
subyearlingVector[n_r]of subyearling releases
Catch function
Description
Internal function that does catch calculations for the preterminal and terminal marine fisheries.
Usage
catch_func(
NO,
HO,
type = c("u", "catch"),
U,
K,
V,
MSF = FALSE,
m = 1,
release_mort = 0,
p_mature_NO = array(1, dim(NO)),
p_mature_HO = array(1, dim(HO)),
AEQ_NO = array(1, dim(NO)),
AEQ_HO = array(1, dim(HO))
)
Arguments
NO |
Array |
HO |
Array |
type |
Character. Whether to calculate removals from harvest rate |
U |
Numeric or function. Harvest rate of fishery |
K |
Numeric or function. Total catch of the fishery |
V |
Matrix |
MSF |
Logical, whether fishing is mark-selective |
m |
Numeric vector length |
release_mort |
Numeric vector length |
p_mature_NO |
Optional, array |
p_mature_HO |
Optional, array |
AEQ_NO |
Optional, array |
AEQ_HO |
Optional, array |
Value
Named list:
-
K_NOkept natural-origin catch, same dimension asNO -
K_HOkept hatchery-origin catch, same dimension asHO -
D_NOdiscarded (live + dead) natural-origin catch, same dimension asNO -
D_HOdiscarded (live + dead) hatchery-origin catch, same dimension asHO -
DD_NOdead discarded natural-origin catch, same dimension asNO -
DD_HOdead discarded hatchery-origin catch, same dimension asHO -
Nsurv_NOnatural-origin survivors, same dimension asNO -
Nsurv_HOhatchery-origin survivors, same dimension asHO -
U_NOnatural-origin harvest rate (ratio of kept catch and abundance), vectorns -
U_HOhatchery-origin harvest rate (ratio of dead catch and abundance), vectorns -
Ex_NOnatural-origin exploitation rate (ratio of dead catch and abundance), vectorns -
Ex_HOhatchery-origin exploitation rate (ratio of dead catch and abundance), vectorns
Check inputs to SOM object
Description
Ensures that the slots in the SOM object have the correct dimensions. Function will update some slots to their full dimensions.
Usage
check_SOM(SOM, silent = FALSE)
Arguments
SOM |
SOM object |
silent |
Logical, whether to report progress in console |
Value
Updated SOM object with full dimensions in various slots
Examples
SOM_checked <- check_SOM(simple_SOM, silent = TRUE)
Compare scenarios in markdown
Description
Generate a markdown report for multiple model runs to compare scenarios. 3-5 is likely the ideal number of scenarios for comparison.
Usage
compare(
SMSE_list,
names,
col_vec,
filename = "SMSEcompare",
dir = tempdir(),
open_file = TRUE,
render_args = list(),
...
)
Arguments
SMSE_list |
List of SMSE objects |
names |
Character vector |
col_vec |
Character vector |
filename |
Character string for the name of the markdown and HTML files. |
dir |
The directory in which the markdown and HTML files will be saved. |
open_file |
Logical, whether the HTML document is opened after it is rendered. |
render_args |
List of arguments to pass to |
... |
Additional arguments (not used) |
Value
Returns invisibly the output of rmarkdown::render(), typically the path of the output file
See Also
Compare simulation runs
Description
Create figures that compare results across two dimensions
Usage
compare_spawners(SMSE_list, Design, prop = FALSE, FUN = median)
compare_fitness(SMSE_list, Design, FUN = median)
compare_escapement(SMSE_list, Design, FUN = median)
Arguments
SMSE_list |
A list of SMSE objects returned by |
Design |
A data frame with two columns that describes the factorial design of the simulations. Used to label the figure.
Rows correspond to each object in |
prop |
Logical, whether to plot absolute numbers over proportions |
FUN |
Summarizing function across simulations, typically |
Details
-
compare_spawners()generates a time series of the composition of spawners -
compare_fitness()generates a time series of metrics (fitness, PNI, pHOS, and pWILD) related to hatchery production -
compare_escapement()generates a time series of the proportion of spawners and broodtake to escapement
Value
A ggplot object
Compare state variables from simulation runs
Description
Compare outputs from multiple simulations to evaluate performance across states of nature and/or management levers (identified by colour):
-
compare_statevar_ts()produces a time series for all simulations, or with medians and 95th percentile intervals -
compare_statevar_hist()produces a histogram or density plot across all simulations for a particular year
Usage
compare_statevar_ts(
SMSE_list,
var = "PNI",
s = 1,
figure = TRUE,
xlab = "Projection Year",
quant = FALSE,
ylab = var,
ylim,
agg.fun = sum,
names,
col_vec,
...
)
compare_statevar_hist(
SMSE_list,
var = "PNI",
s = 1,
y,
figure = TRUE,
xlab = var,
names,
col_vec,
type = c("density", "hist"),
...
)
Arguments
SMSE_list |
List of SMSE objects for multiple model runs returned by |
var |
Character. Slot for the state variable in |
s |
Integer. Population index for multi-population model (e.g., |
figure |
Logical, whether to generate a figure (set to FALSE if only using the function to return the data matrix) |
xlab |
Character. Name of time variable for the figure |
quant |
Logical, whether to plot individual simulations (FALSE) or the median with 95 percent confidence intervals (TRUE) |
ylab |
Character. Name of the state variable for the figure |
ylim |
Vector. Y-axis limits |
agg.fun |
Function. Defines how to aggregate state variables that are reported by age. Typically, |
names |
Character vector |
col_vec |
Character vector |
... |
Additional arguments to base plot function |
y |
Integer. Projection year for the state variable to plot the histogram. If missing, the last projection year is used. |
type |
Character, whether to generate a density figure or histogram |
Value
An array invisibly. Also generates base graphics if figure = TRUE
See Also
Create list of parameters
Description
Internal functions that convert the operating model inputs into a list or data frame of parameters to pass on to other internal functions.
Usage
define_hatchery_args(SOM)
define_habitat_args(SOM)
define_fitness_args(SOM)
define_SRRpars(SOM)
Arguments
SOM |
SOM operating model object |
Value
define_hatchery_args() returns a length nstocks of hatchery parameters, in-river removals, and behavior of hatchery-origin
fish in the freshwater environment (fecundity, reproductive success, etc.)
define_habitat_args() returns a list of Habitat objects.
define_fitness_args() returns a length nstocks of fitness parameters.
define_SRRpars_args() returns a length nstocks, each of which is a data frame of stock-recruit parameters.
Fit conditioning model to historical data
Description
Bayesian stock reconstruction model of natural and hatchery origin fish population. Maturity and age-1 natural mortality are estimated from coded wire tag catch and escapement at age. A separate series of observed escapement, and hatchery releases reconstructs the population of interest, informed by natural mortality and maturity from CWT (Korman and Walters 2024). The model estimates time-varying maturity rate as well as time-varying ocean survival as a linear model of covariates (separate covariates for age 1 vs. ages 2+). The model can include either a preterminal juvenile fishery, terminal return fishery, or both (see Data and start sections of the documentation).
fit_CM() generates the RTMB model from data which can then be passed to sample_CM() to run the MCMC in Stan. Generate a markdown report with report_CM().
More information is available on the salmonMSE website
Usage
fit_CM(
data,
start = list(),
map = list(),
lower = list(),
upper = list(),
do_fit = TRUE,
verbose = TRUE,
silent = TRUE,
control = list(eval.max = 1e+05, iter.max = 1e+05),
...
)
sample_CM(fit, ...)
Arguments
data |
A list containing data inputs. See details. |
start |
An optional list containing parameter starting values. See details. |
map |
An optional list that describes how parameters are fixed in the model. See |
lower |
Named list containing lower bounds for parameters. See details. |
upper |
Named list containing upper bounds for parameters. See details. |
do_fit |
Logical, whether to do the fit and estimate the Hessian. |
verbose |
Logical, whether to report messages to console. |
silent |
Logical, whether to silence output from RTMB to the console. |
control |
List, |
... |
For |
fit |
List of output from |
Value
-
fit_CM()returns a named list containing the RTMB model (obj), nlminb output (opt), standard errors (SD), and parameter bounds (lowerandupper) -
sample_CM()returns astanfitobject containing the MCMC chains
Data
Data should passed through a named list with the following entries.
-
NagesInteger, number of age classes in the model -
LdyrInteger, number of years in the model -
lhtInteger, life history type. Should be 1 for now -
n_rInteger, number of release strategies for CWT, subset of a hatchery-origin brood year that differ in maturity rate. Default is 1. -
cwtreleaseMatrix[Ldyr, n_r], coded wire tag (CWT) releases by release year and release strategy -
cwtescArray[Ldyr, Nages, n_r]. CWT escapement by release year, age, and release strategy (assumes broodyear is release year minus 1). Poisson likelihood. -
cwtcatPTArray[Ldyr, Nages, n_r]. CWT preterminal catch (juvenile fish), by release year, age, and release strategy. Poisson likelihood. Set all values to zero to turn off parameters related to the preterminal fishery. -
cwtcatTArray[Ldyr, Nages, n_r]. CWT terminal catch (returning, mature fish), by release year, age, and release strategy. Poisson likelihood. Set all values to zero to turn off parameters related to the terminal fishery. -
bvulPTVector lengthNages. Prior mean for the vulnerability at age to the preterminal fishery. -
bvulTVector lengthNages. Prior mean for the vulnerability at age to the terminal fishery. -
RelRegFPTVectorLdyr. Trend in relative regional preterminal fishing mortality. Fishing mortality is estimated by estimating a scaling coefficient and annual deviations from this vector. Default isrep(1, d$Ldyr)(no prior trend) ifcwtcatPTis provided, otherwise zero. -
RelRegFTVectorLdyr. Trend in relative regional terminal fishing mortality. Default isrep(1, d$Ldyr)(no prior trend) ifcwtcatTis provided, otherwise zero. -
bmattVector lengthNages. Proportion maturity at age, base values for calculating the unfished replacement line. Also the prior means if year-specific maturity rates are estimated. -
mobase. Vector lengthNages. Natural mortality at age, base values for calculating the unfished replacement line and the the equilibrium spawners at age. -
covariate1Optional. MatrixLdyr, ncov1of linear covariates that predict natural mortality for age 1. -
covariateOptional. MatrixLdyr, ncovof linear covariates that predict natural mortality for ages 2+. -
hatchsurvNumeric, survival of hatchery releases into the smolt life stage. Density-independent. Default is 1. If less than 1, then hatchery origin fish have lower survival to age 2 (after first year of marine life stage) compared to natural origin fish. -
gammaOptional. Numeric, the relative spawning success of hatchery origin spawners. Default is 1. -
ssumNumeric, proportion of spawners that is female. Can also be a vectorNages -
fecVector lengthNages. Fecundity, egg production at age -
r_mattInteger, the release strategy for which to use maturity parameter for the natural system. Default is 1. -
obsescapeVector lengthLdyrby return year, total observed escapement from fisheries, i.e., return to river (all ages and both hatchery/natural fish). Lognormal likelhood. -
propwildspawnVector lengthLdyrby return year, proportion of the escapement that spawn (accounts for en-route mortality and broodtake) -
hatchreleaseVector lengthLdyr+1by release year, number of hatchery releases for the population. Default is zero. -
obs_pHOSOptional. Vector lengthLdyrby return year, observations of proportion of hatchery origin spawners (census) (between 0-1) by brood year. Fitted to model with logistic-normal likelihood. -
pHOS_sdNumeric, logistic-normal standard deviation of pHOS observations. Default is 1. -
pHOS_initNumeric, initial pHOS for equilibrium abundance in the first year of the model. Default is 0. -
s_enrouteNumeric, survival of escapement to spawning grounds. Default is 1. -
so_muNumeric, the prior mean for spawners at unfished replacement in logspace. Default islog(3 * max(data$obsescape)). -
so_sdNumeric, the prior standard deviation for spawners at unfished replacement in logspace. Default is 0.5. -
finitPTNumeric, initial preterminal fishing mortality for calculating the equilibrium juvenile proportions at age in the first year of the model. Default is 0. Set to"estimate"to allow the model to estimate the equilibrium condition. -
finitTNumeric, initial terminal fishing mortality for calculating the equilibrium juvenile proportions at age in the first year of the model. Default is 0. Set to"estimate"to allow the model to estimate the equilibrium condition. -
spawn_initNumeric, initial spawners to calculate equilibrium abundance in the first year of the model. Default isobsescape[1]. -
cwtExpNumeric, the CWT expansion factor, typically the reciprocal of the catch sampling rate (higher factors for lower sampling rate). The model scales down the CWT predictions to match the observations. In other words, the model assumes that the CWT catch and escapement are not expanded. For example,cwtExp = 10divides the CWT predictions by 10 for the likelihood. Default is 1. The Poisson distribution is used for the likelihood of the CWT observations, and the expansion parameter can be used to downweight the CWT likelihood relative to the escapement time series. However it requires adjustments of the CWT catches prior to fitting to ensure the proper population scale. If the expanded catch is 100, then the input CWT catch should be 10 and 50 withcwtExpof 10 and 2, respectively, to maintain the same population scale. The Poisson variance scales with the mean and is higher withcwtExp = 2. -
fitnessLogical, whether to calculate fitness effects on survival. Default isFALSE. -
thetaVector length 2, the optimum phenotype value for the natural and hatchery environments. Default is 100 and 80, respectively. See online article for more information. -
rel_lossVector length 3, the loss in fitness apportioned between the egg, fry (both prior to density-dependence), and smolt (after density-dependence) life stage. The three values should sum to 1. -
zbar_startVector length 2, the mean phenotype of the spawners and broodtake in the natural and hatchery environment, respectively, at the start of the model. Default values of 100 and 100, implying maximum fitness at for the natural environment at the start of the model. -
fitness_varianceNumeric. The variance (omega-squared) of the fitness function. Assumed identical between the natural and hatchery environments. Default is 100. -
phenotype_varianceNumeric. The variance (sigma-squared) of the phenotypic trait (with optimum theta). Assumed identical between the natural and hatchery environments. Default is 10. -
heritabilityNumeric. The heritability (h-squared) of the phenotypic trait. Between 0-1. Default is 0.5. -
fitness_floorNumeric. The minimum fitness value in the natural and hatchery environments. Default is 0.5.
start
Starting values for parameters can be provided through a named list:
-
log_crNumeric, log of the compensation ratio (productivity). Default is 3. -
log_soNumeric, unfished spawners in logspace. Default islog(3 * max(data$obsescape)). -
moaddNumeric, additive term to base natural mortality rate for age 1 juveniles. Default is zero. -
wtVectorLdyr. Annual deviates in natural mortality during the freshwater life stage (affects egg to smolt survival). Estimated with normal prior with mean zero and standard deviationp$wt_sd. Default is zero. -
wtoVectorLdyr. Annual deviates in natural mortality for age 1 juveniles (marine life stage). Estimated with normal prior with mean zero and standard deviationp$wto_sd. Default is zero. -
log_FbasePTNumeric, scaling coefficient to estimate preterminal fishing mortality fromdata$RelRegFPT. Default islog(0.1). -
log_FbaseTNumeric, scaling coefficient to estimate preterminal fishing mortality fromdata$RelRegFT. Default islog(0.1). -
log_fanomalyPTVectorLdyr. Annual lognormal deviates fromexp(log_FbasePT) * data$RelRegFPTto estimate preterminal fishing mortality. Estimated with normal prior with mean zero and standard deviationp$fanomaly_sd. Default is zero. -
log_fanomalyTVectorLdyr. Annual lognormal deviates fromexp(log_FbaseT) * data$RelRegFTto estimate terminal fishing mortality. Estimated with normal prior with mean zero and standard deviationp$fanomalyPT_sd. Default is zero. -
lnE_sdNumeric, lognormal standard deviation of the observed escapement. Estimated with hierarchicalgamma(2, 5)prior. Default is 0.1. -
wt_sdNumeric, lognormal standard deviation of the egg to smolt (freshwater) natural mortality deviates. Estimated with hierarchicalgamma(2, 5)prior. Default is 1. -
wto_sdNumeric, lognormal standard deviation of the age 1 (marine) natural mortality deviates. Estimated with hierarchicalgamma(2, 5)prior. Default is 1. -
fanomalyPT_sdNumeric, lognormal standard deviation offanomalyPT. Estimated with hierarchicalgamma(2, 5)prior. Default is 1. -
fanomalyT_sdNumeric, lognormal standard deviation offanomalyT. Estimated with hierarchicalgamma(2, 5)prior. Default is 1. -
logit_vulPTVectorNages-2of preterminal vulnerability at age in logit space. Fixed to zero and one at age 1 and the maximum age, respectively. Default isqlogis(data$bvul_PT[-c(1, data$Nages)]). -
logit_vulTVectorNages-2of terminal vulnerability at age in logit space. Fixed to zero and one at age 1 and the maximum age, respectively. Default isqlogis(data$bvul_T[-c(1, data$Nages)]). -
logit_mattMatrixLdyr, Nages-2maturity by year and age in logit space. Maturity is fixed to zero and one at age 1 and the maximum age, respectively. Default ismatrix(qlogis(data$bmatt[-c(1, data$Nages)]), data$Ldyr, data$Nages-2, byrow = TRUE). -
sd_mattVectorNages-2. Logit standard deviation of maturity (logit_matt) by age class. Default is 0.5. -
b1Vectorncov1of coefficients for linear covariates that predict natural mortality for age 1. Default is zero. -
bVectorncovof coefficients for linear covariates that predict natural mortality for ages 2+. Default is zero.
Bounds
By default, the standard deviation parameters and parameters in normal space (e.g., FbasePT, Fbase_T) have a lower bound of zero.
moadd has a lower bound of zero by default, but it is feasible that this parameter can be negative as well.
Deviation parameters centred around zero are bounded between -3 to 3.
The log_cr parameter has a lower bound of zero.
All other parameters are unbounded.
Covariates on natural mortality
Natural mortality is modeled as the sum of a base value M^\textrm{base}, additional scaling factor for age 1 M^\textrm{add},
a linear system of covariates X and coefficients b:
M_{y,a} =
\begin{cases}
M^\textrm{base}_a + M^\textrm{add} + \sum_j b^1_j X^1_{y,j} & \quad a = 1\\
M^\textrm{base}_a + \sum_j b_j X_{y,j} & \quad a = 2, \ldots, A
\end{cases}
Author(s)
Q. Huynh from Stan code provided by J. Korman and C. Walters
References
Korman, J. and Walters, C. 2024. A life cycle model for Chinook salmon population dynamics. Canadian Contractor Report of Hydrography and Ocean Sciences 62: vi + 60 p.
See Also
Calculate mean phenotype and fitness
Description
Quantitative genetics model of mean phenotypic trait and fitness of next brood year.
calc_zbar() is the internal function that calculates mean phenotype.
Usage
fitness_func(
Egg_NOS,
Egg_HOS,
Egg_NOB,
Egg_HOB,
zbar_brood,
fitness_args = list()
)
calc_zbar(
Egg_NOS,
Egg_HOS,
Egg_NOB,
Egg_HOB,
zbar_prev,
fitness_variance,
theta,
phenotype_variance,
heritability
)
Arguments
Egg_NOS |
Numeric, egg production by natural-origin spawners |
Egg_HOS |
Numeric, egg production by hatchery-origin brood |
Egg_NOB |
Numeric, egg production by natural-origin brood |
fitness_args |
List, containing |
zbar_prev |
Numeric, mean phenotype of parents |
fitness_variance |
Numeric, variance (omega-squared) of the fitness function |
theta |
Numeric length 2, optimum phenotype value for the natural and hatchery environments, respectively. |
phenotype_variance |
Numeric, variance (sigma-squared) of the phenotypic trait (theta) |
heritability |
Numeric, heritability (h-squared) of the phenotypic trait |
Value
fitness_func returns a list:
-
zbarNumeric length 2, mean phenotype of next generation to naturalzbar[1]and hatcheryzbar[2]environments -
fitnessNumeric length 2, fitness of next generation to natural and hatchery environments -
fitness_lossMatrix[2, 3]penalty in survival of next generation due to fitness effects
calc_zbar returns numeric length 2, mean phenotype of next generation
Calculate F from harvest rate
Description
Solves for apical instantaneous fishing mortality rate (F), proportional to fishing effort, from harvest rate (total retained catch over total abundance).
The apical F can be greater than the realized F, if retention < 1. Used by AHA()
Usage
get_F(
u = 0,
K = 0,
type = c("u", "catch"),
M,
N = 1,
vul = 1,
ret = 1,
release_mort = 0,
Fmax = 20
)
Arguments
u |
Harvest rate, between 0-1 |
K |
Catch, between 0-Inf |
type |
Character, either |
M |
Instantaneous natural mortality rate |
N |
Abundance |
vul |
Vulnerability |
ret |
Retention rate |
release_mort |
Release mortality as a proportion, between 0-1. Only relevant if |
Fmax |
Maximum allowable value of F |
Value
Numeric for the apical F
Figures for conditioning model results
Description
Functions used by the markdown report to generate summary figures from the age-structured conditoning model
Usage
get_report(stanfit, sims, inc_warmup = FALSE)
get_CMdata(fit)
CM_trace(stanfit, vars, inc_warmup = FALSE)
CM_pairs(stanfit, vars = c("log_so", "log_cr"), inc_warmup = FALSE)
CM_fit_esc(report, d, year)
CM_fit_pHOS(report, d, year)
CM_fit_CWTesc(report, d, year1 = 1, rs_names)
CM_fit_CWTcatch(report, d, PT = TRUE, year1 = 1, rs_names)
CM_maturity(
report,
d,
year1 = 1,
r = 1,
brood = TRUE,
annual = FALSE,
rs_names
)
CM_vul(report, type = c("vulPT", "vulT"))
CM_SRR(report, year1 = 1)
CM_prod(report, d, year1 = 1, index = NULL, mean_bio = FALSE)
CM_Srep(
report,
d,
year1 = 1,
index = NULL,
mean_bio = FALSE,
type = c("spawner", "egg"),
na.rm = FALSE
)
CM_M(report, year1 = 1, ci = TRUE)
CM_Megg(report, year1 = 1, ci = TRUE, surv = FALSE)
CM_Njuv(report, year1 = 1, ci = TRUE)
CM_recr(report, year1 = 1, ci = TRUE)
CM_esc(report, year1 = 1, ci = TRUE)
CM_F(report, PT = TRUE, year1 = 1, ci = TRUE)
CM_surv(report, year1 = 1, ci = TRUE)
CM_wt(stanfit, year1 = 1, ci = TRUE)
CM_surv2(report, year1 = 1, ci = TRUE, ylab = "Survival to age 2")
CM_wto(stanfit, year1 = 1, ci = TRUE)
CM_ER(
report,
brood = TRUE,
type = c("PT", "T", "all"),
year1 = 1,
ci = TRUE,
at_age = TRUE,
r = 1,
index_AEQ = NULL
)
CM_CWT_ER(
report,
brood = TRUE,
type = c("PT", "T", "all"),
year1 = 1,
ci = TRUE,
rs_names
)
CM_covariate(x, names, year1 = 1, b, ylab = "Covariate")
Arguments
stanfit |
Output from |
sims |
Optional integer vector for subset of MCMC iterations |
inc_warmup |
Logical, whether to include warmup MCMC samples |
fit |
Output from |
vars |
Character vector for variable names (see |
report |
List, output of state variables from individual MCMC samples, obtained with |
d |
List of data variables, obtained with |
year |
Vector of years |
year1 |
Numeric, first year of model |
rs_names |
Character vector of hatchery release strategies |
PT |
Logical, whether to plot preterminal catch, otherwise (plot terminal catch) |
r |
Integer, the release strategy for the figure (only if |
brood |
Logical, whether to show results by brood year or return year (FALSE) |
annual |
Logical, whether to show panel figure by individual year (TRUE) or a single time series figure |
type |
Character, indicates type of variable to plot |
index |
Integer vector to subset years with which to calculate reference points. Can be used
to reduce computation or average biological parameters from a subset of years, see |
mean_bio |
Logical, whether to average the natural mortality and maturity parameters across
years indicated in |
na.rm |
Logical, whether to exclude replacement values (and other reference points) that are less than zero from median calculations and resulting figures |
ci |
Logical whether to show posterior intervals in addition to posterior median |
surv |
Logical, whether to plot survival (values between 0 - 1) or instantaneous mortality rates |
ylab |
Character y axis label |
at_age |
Logical, whether to make figure by individual age |
index_AEQ |
Optional integer vector to identify years from which to borrow natural mortality and maturity
to calculate adult equivalents for incomplete brood years. Only used if |
x |
Matrix of covariates by year x covariate |
names |
Character of covariate names |
b |
Matrix of fixed effect coefficients by simulation x covariate. If missing only the covariates ( |
Value
-
get_report()returns the list of state variables by individual MCMC samples
-
get_CMdata()returns the list of data variables used in the conditioning model
-
CM_trace()returns a ggplot showing the MCMC trace plot (aka wormplot)
-
CM_pairs()returns output fromgraphics::pairs(), a matrix of scatterplots of MCMC posterior samples
-
CM_fit_esc()returns base graphics with fit to total escapement time series
-
CM_fit_pHOS()returns base graphics with fit to pHOS (census) observations
-
CM_fit_CWTesc()returns ggplot of fit to CWT escapement at age
-
CM_fit_CWTcatch()returns ggplot of fit to CWT catch at age
-
CM_maturity()returns ggplot of estimated maturity at age
-
CM_vul()returns ggplot of estimated fishery vulnerability at age
-
CM_SRR()returns ggplot of estimated stock-recruit relationship (density-dependent juvenile production from egg production) with average relationship and realized annual values. Years correspond to return years of egg production (predicts juvenile production of the following calendar year).
-
CM_prod()returns ggplot of productivity (adults/spawner), calculated from density-dependent egg-smolt Ricker parameters, juvenile natural mortality, fecundity, and maturity. Even if egg-smolt survival function is constant, the realized productivity can vary with annual changes in natural mortality or maturity..CM_prod()is the internal function that calculates productivity, with additional options for averaging time-varying biology.
-
CM_Srep()returns ggplot of spawners or egg production at replacement, calculated from density-dependent egg-smolt Ricker parameters, juvenile natural mortality, fecundity, and maturity. Even if egg-smolt survival function is constant, the realized replacement can vary with annual changes in natural mortality or maturity..CM_Srep()is the internal function with options for averaging time-varying biology.
-
CM_M()returns ggplot of estimated natural mortality time series by age (marine stage)
-
CM_Megg()returns ggplot of egg-juvenile mortality time series
-
CM_Njuv()returns ggplot of juvenile abundance
-
CM_recr()returns ggplot of recruitment (mature return)
-
CM_esc()returns ggplot of escapement (after terminal harvest)
-
CM_F()returns ggplot of instantaneous fishing mortality
-
CM_surv()returns ggplot of natural survival (converting from instantaneous units of natural mortality)
-
CM_wt()returns ggplot of annual deviations in egg-juvenile mortality from the Ricker function
-
CM_surv2()returns ggplot of annual survival to age 2, which includes age-1 mortality (marine life stage) for both natural and hatchery origin fish. Hatchery fish experience additional mortality specified by release mortality.
-
CM_wt()returns ggplot of annual deviations in age 1 natural mortality (first year in marine life stage, deviations from time series average)
-
CM_ER()returns ggplot of exploitation rate either by individual age or aggregate values. Aggregate values use adult equivalents for preterminal fisheries..CM_ER()and.CM_ERage()are the internal functions for reporting values for all simulations and years if desired.
-
CM_CWT_ER()returns ggplot of CWT exploitation rate (by release strategy)
-
CM_covariate()returns ggplot of mortality covariates
See Also
salmonMSE glossary
Description
Glossary of terms and parameters used in salmonMSE
Examples
data(glossary)
glossary[1:2, ]
Spawning and early life stage function
Description
Calculates egg production from spawners arriving at spawning grounds, broodtake and in-river removals from escapement of marine fisheries. This function also applies en-route mortality.
Usage
nextgen_SRR_func(
Brood_Calcs,
fec,
p_female,
hatchery_args = list(),
fitness_args = list(),
zbar_brood,
SRRpars,
p_LHG
)
nextgen_habitat_func(
Brood_Calcs,
Habitat,
fec,
p_female,
hatchery_args = list(),
fitness_args = list(),
zbar_brood,
p_LHG
)
Arguments
Brood_Calcs |
List, returned by |
fec |
Vector |
p_female |
Vector |
hatchery_args |
List of arguments created by |
fitness_args |
List of arguments created by |
Habitat |
Habitat object, modified by |
Value
Named list:
-
NOSMatrix[nage, n_g] -
HOSMatrix[nage, n_r] -
HOS_effectiveMatrix[nage, n_r] -
HOS_strayMatrix[nage, n_r] -
pHOSeffNumeric -
pHOScensusNumeric -
Egg_NOS[nage, n_g] -
Egg_HOS[nage, n_r] -
Smolt_RelOutVector[n_r] -
Fry_NOSVector[n_g] -
Fry_HOSVector[n_g] -
Smolt_NOSVector[n_g] -
Smolt_HOSVector[n_g]
Plot life history groups and release strategies
Description
Plot the annual proportions of life history groups (natural origin fish) or release strategies (hatchery origin) at various life stages
Usage
plot_LHG(
SMSE,
var = "NOS",
type = c("prop", "abs"),
s = 1,
FUN = median,
figure = TRUE,
xlab = "Projection Year",
ylab,
name,
ylim
)
plot_RS(
SMSE,
var = "HOS",
type = c("prop", "abs"),
s = 1,
FUN = median,
figure = TRUE,
xlab = "Projection Year",
ylab,
name,
ylim
)
Arguments
SMSE |
Class SMSE object returned by |
var |
Character. Slot for the state variables in |
type |
Character to indicate whether to plot proportion or absolute numbers |
s |
Integer. Population index for multi-population model (e.g., |
FUN |
Summarizing function across simulations, typically |
figure |
Logical, whether to generate a figure (set to FALSE if only using the function to return the data matrix) |
xlab |
Character. Name of time variable for the figure |
ylab |
Character. Name of the state variable for the figure |
name |
Character. Vector of names for the life history groups or release strategies |
ylim |
Vector length 2, y-axis limits |
Value
Base graphics figure, barplot of distribution or total numbers by LHG or RS. Returns invisibly the matrix of plotted values
See Also
Decision table of performance metrics
Description
Generates a coloured table of a performance metric across two axes, which may be a population dynamics variable (e.g., productivity) or a management action (e.g., hatchery production levels or harvest strategy). See example at https://docs.salmonmse.com/articles/decision-table.html. More examples below.
-
plot_decision_table()is a simple figure where colour range is intended to continuously transition from pink to white to green corresponding to values of 0, 0.5, and 1, respectively. -
plot_decision_table2()is converts performance metrics values into bins and provides more user control in the colour scheme
Usage
plot_decision_table(
x,
y,
z,
title,
xlab,
ylab,
scenario,
ncol = NULL,
dir = "v"
)
plot_decision_table2(
x,
y,
z,
title,
xlab,
ylab,
zlab,
scenario,
ncol = NULL,
dir = "v",
bin = c(0, 0.05, 0.25, 0.5, 0.75, 0.95),
bin_labels = c("0-0.04", "0.05-0.24", "0.25-0.49", "0.5-0.74", "0.75-0.94", "0.95-1"),
bin_col = c("purple4", "deeppink", "pink", "white", "green", "green4"),
cell_border = FALSE,
add_values = FALSE
)
Arguments
x |
Atomic, vector of values for the x axis (same length as z). Will be converted to factors |
y |
Atomic, vector of values for the y axis (same length as z). Will be converted to factors |
z |
Numeric, vector of values for the performance metric |
title |
Character, optional title of figure |
xlab |
Character, optional x-axis label |
ylab |
Character, optional y-axis label |
scenario |
Atomic, vector of faceting variables (same length as z) used to generate a grid of decision tables |
ncol |
Integer, number of columns for decision table grid, only used if |
dir |
Character, either "h" or "v" to describe how the grid of tables should be organized (horizontally or vertically) |
zlab |
Character, optional color legend |
bin |
Numeric vector of bins to sort values of |
bin_labels |
Character vector for bin names for the figure |
bin_col |
Character vector of colors for the bins in the figure |
cell_border |
Logical, whether to add borders for each cell in the figure |
add_values |
Logical, whether to add the values of |
Value
ggplot object
See Also
plot_statevar_ts() plot_tradeoff()
Examples
# Simple decision table
results <- data.frame(
PNI = c(0.7, 0.23, 0.05, 0.9, 0.85, 0.74, 0.95, 0.92, 0.9),
pNOB = rep(c(0.5, 0.75, 1), each = 3),
ER = rep(c(0.2, 0.3, 0.4), 3),
scenario = "High productivity"
)
plot_decision_table(
x = results$ER,
y = results$pNOB,
z = results$PNI,
title = "PNI",
xlab = "Exploitation rate",
ylab = "pNOB target"
)
# Multiple decision tables organized by scenario
# Continuing from above
results_low <- results
results_low$scenario <- "Low productivity"
results_low$PNI <- 0.5 * results$PNI
results_all <- rbind(results, results_low)
plot_decision_table(
x = results_all$ER,
y = results_all$pNOB,
z = results_all$PNI,
title = "PNI",
xlab = "Exploitation rate",
ylab = "pNOB target",
scenario = results_all$scenario
)
# Example of binned decision table
df <- expand.grid(
SAR = seq(0.005, 0.03, 0.005),
ER = seq(0, 0.5, 0.1)
)
df$value <- ifelse(5 * df$SAR + 0.2 > df$ER, 0.75, 0.05)
df$value <- ifelse(df$SAR < 0.02 & df$ER > 0.4, 0.04, df$value)
plot_decision_table2(
x = df$SAR,
y = df$ER,
z = df$value,
xlab = "Marine survival",
ylab = "Exploitation rate",
zlab = "Probability\nof objective"
)
Plot core output from salmonMSE
Description
Various functions that plot the state variables from salmonMSE projections:
-
plot_statevar_ts()produces a time series for all simulations, or with medians and 95th percentile intervals -
plot_statevar_hist()produces a histogram across all simulations for a particular year -
plot_spawners()produces a summary barplot of spawners, including NOS, HOS, and wild spawners -
plot_escapement()produces a summary figure of the proportion of spawners and broodtake to escapement -
plot_fitness()produces a summary figure of metrics (fitness, PNI, pHOS, and pWILD) related to hatchery production -
plot_fishery()produces a summary figure of metrics related to the fishery, e.g., median catch, exploitation rate or harvest rate
Usage
plot_statevar_ts(
SMSE,
var = "PNI",
s = 1,
figure = TRUE,
xlab = "Projection Year",
quant = FALSE,
ylab = var,
ylim,
agg.fun = sum,
...
)
plot_statevar_hist(SMSE, var = "PNI", s = 1, y, figure = TRUE, xlab = var, ...)
plot_spawners(SMSE, s = 1, prop = TRUE, FUN = median, figure = TRUE, ylim)
plot_fitness(SMSE, s = 1, FUN = median, figure = TRUE, ylim)
plot_escapement(SMSE, s = 1, FUN = median, figure = TRUE, ylim)
plot_fishery(
SMSE,
s = 1,
type = c("catch", "exploit", "harvest"),
FUN = median,
figure = TRUE,
ylim,
ylab,
...
)
plot_Kobe(
SMSE,
s = 1,
FUN = median,
figure = TRUE,
xlim,
ylim,
xlab = expression(NOS/S[MSY]),
ylab = expression(U/U[MSY]),
type = c("T", "PT")
)
Arguments
SMSE |
Class SMSE object returned by |
var |
Character. Slot for the state variable in |
s |
Integer. Population index for multi-population model (e.g., |
figure |
Logical, whether to generate a figure (set to FALSE if only using the function to return the data matrix) |
xlab |
Character. Name of time variable for the figure |
quant |
Logical, whether to plot individual simulations (FALSE) or the median with 95 percent confidence intervals (TRUE) |
ylab |
Character. Name of the state variable for the figure |
ylim |
Vector. Y-axis limits |
agg.fun |
Function. Defines how to aggregate state variables that are reported by age. Typically, |
... |
Additional arguments to base plot function |
y |
Integer. Projection year for the state variable to plot the histogram. If missing, the last projection year is used. |
prop |
Logical, whether to plot proportions or absolute numbers |
FUN |
Summarizing function across simulations, typically |
type |
For |
xlim |
Vector. X-axis limits |
Value
Functions return the matrix of plotted values invisibly. Figure plotted from base graphics
See Also
plot_decision_table() plot_LHG() compare_statevar_ts()
Tradeoff figure
Description
Generates a tradeoff figure, a comparison between two performance metrics, across two variables which may represent a population dynamics variable (e.g., productivity) or a management action (e.g., hatchery production levels or harvest strategy). See example at https://docs.salmonmse.com/articles/decision-table.html
Usage
plot_tradeoff(
pm1,
pm2,
x1,
x2,
xlab,
ylab,
x1lab,
x2lab,
scenario,
scenario_rows,
scenario_cols,
ncol = NULL,
dir = "v",
add_letters = FALSE
)
Arguments
pm1 |
Numeric or matrix. A vector of values for the first performance metric on the x-axis. Alternatively, provide a three column matrix corresponding to the lower bound, central tendency, and upper bound. |
pm2 |
Numeric or matrix. A vector of values for the second performance metric on the y-axis (same length as pm1). Alternatively, provide a three column matrix corresponding to the lower bound, central tendency, and upper bound. |
x1 |
Atomic, vector of values for the first grouping variable. Various levels are represented by colours. Same length as pm1. If numeric, you may want to convert values to factors. |
x2 |
Atomic, vector of values for the second grouping variable. Various levels are represented by shapes. Same length as pm1. If numeric, will be converted to factors. |
xlab |
Character, optional x-axis label |
ylab |
Character, optional y-axis label |
x1lab |
Character, optional label for the first grouping variable |
x2lab |
Character, optional label for the second grouping variable |
scenario |
Atomic, vector of scenario names (same length as |
scenario_rows |
Atomic, vector of scenario variables (same length as |
scenario_cols |
Atomic, vector of scenario variables (same length as |
ncol |
Integer, number of columns in the grid, only used if |
dir |
Character, either "h" or "v" to describe how the grid of tables should be organized (horizontally or vertically) , only used if |
add_letters |
Logical, whether to identify separate panels by letters (only used if scenarios are identified). Helpful for publication-level figures |
Value
ggplot object
See Also
plot_statevar_ts() plot_decision_table()
Examples
# Single tradeoff panel
results <- data.frame(
PNI = c(0.7, 0.23, 0.05, 0.9, 0.85, 0.74, 0.95, 0.92, 0.9),
Catch = c(10, 14, 12, 8, 7, 7, 8.2, 7.1, 6.9),
pNOB = rep(c(0.5, 0.75, 1), each = 3),
ER = rep(c(0.2, 0.3, 0.4), 3),
scenario = "High productivity"
)
plot_tradeoff(
pm1 = results$PNI,
pm2 = results$Catch,
x1 = results$ER,
x2 = results$pNOB,
xlab = "PNI",
ylab = "Catch",
x1lab = "Exploitation\nrate",
x2lab = "pNOB\ntarget"
)
# Multiple panels, continuing from above code
results_low <- results
results_low$scenario <- "Low productivity"
results_low$PNI <- 0.5 * results$PNI
results_low$Catch <- c(0.9, 0.8, 0.7) * results$Catch
results_all <- rbind(results, results_low)
g <- plot_tradeoff(
pm1 = results_all$PNI,
pm2 = results_all$Catch,
x1 = results_all$ER,
x2 = results_all$pNOB,
xlab = "PNI",
ylab = "Catch",
x1lab = "Exploitation\nrate",
x2lab = "pNOB\ntarget",
scenario = results_all$scenario
)
# Change legend with ggplot2
library(ggplot2)
g + scale_shape_manual(values = c(1, 4, 16))
Generate markdown reports
Description
Generate a markdown report for outcomes from a single operating model projection
Usage
## S4 method for signature 'SMSE'
report(
object,
name = object@Name,
filename = "SMSE",
dir = tempdir(),
open_file = TRUE,
render_args = list(),
...
)
Arguments
object |
SMSE object |
name |
Character string for the model name to include in the report, e.g., model run number. |
filename |
Character string for the name of the markdown and HTML files. |
dir |
The directory in which the markdown and HTML files will be saved. |
open_file |
Logical, whether the HTML document is opened after it is rendered. |
render_args |
List of arguments to pass to |
... |
Additional arguments (not used) |
Value
Returns invisibly the output of rmarkdown::render(), typically the path of the output file
See Also
Conditioning model markdown report
Description
Generate a markdown report to plot time series and MCMC posteriors of estimates from the conditioning model. See get_report() for the
various plotting functions used in the report.
Usage
report_CM(
stanfit,
year,
cov1_names,
cov_names,
rs_names,
name,
filename = "CM",
dir = tempdir(),
open_file = TRUE,
render_args = list(),
...
)
Arguments
stanfit |
Output from |
year |
Optional vector of calendar years |
cov1_names |
Optional character vector for names of covariates that predict age-1 natural mortality |
cov_names |
Optional character vector for names of covariates that predict age-2+ natural mortality |
rs_names |
Optional character vector for names of hatchery release strategies |
name |
Optional character string for the model name to include in the report, e.g., model run number |
filename |
Character string for the name of the markdown and HTML files |
dir |
The directory in which the markdown and HTML files will be saved. |
open_file |
Logical, whether the HTML document is opened after it is rendered |
render_args |
List of arguments to pass to |
... |
Additional arguments (not used) |
Details
Report excludes MCMC values from warmup iterations
Value
Returns invisibly the output of rmarkdown::render(), typically the path of the output file
See Also
Run salmonMSE
Description
salmonMSE() runs a salmon management strategy evaluation from an operating model object (SOM), by checking
the operating model object with check_SOM(), running the projection in ProjectSOM() (parallel if called upon, then stitches
together the output in a single object), and calculates reference points with calc_ref().
ProjectSOM() is the internal projection function.
simple_salmonMSE() is helper function that converts a simple operating model (modeling only recruit-spawners
with Ricker relationship, terminal marine fishery, without hatchery production) to a full operating model and runs the projection.
Usage
salmonMSE(SOM, ncores = 1, silent = FALSE)
ProjectSOM(SOM, sims, check = FALSE)
simple_salmonMSE(simpleSOM, ...)
Arguments
SOM |
An object of class SOM |
ncores |
Integer, maximum number of processors to run projection with parallel processing |
silent |
Logical, whether to report progress in console |
sims |
Optional integer vector to run projection for a subset of simulations. Intended for parallel processing. |
check |
Logical, whether to check the structure of the input object with |
simpleSOM |
An object of class simpleSOM |
... |
Other arguments to pass to |
Value
SMSE object
Examples
## Not run:
SMSE <- salmonMSE(simple_SOM)
## End(Not run)
Environment to store salmon specific variables, e.g, fitness, during the simulation
Description
Environment to store salmon specific variables, e.g, fitness, during the simulation
Usage
salmonMSE_env
Format
An object of class environment of length 0.
Class "simpleSOM"
Description
A simple operating model for modeling recruit-spawners and a terminal marine fishery, no hatchery production.
Details
Various parameters can be stochastic (length nsim) or input as a single numeric
(value identical across all simulations).
Slots
NameCharacter. Identifying name
nsimInteger. Number of simulations.
maxageInteger. The maximum age of the population age structure.
ngenInteger. The number of generations (life cycles) to run the projection.
kappaVector length
nsim. The adult productivity ratio for the stock-recruit function. Units of recruits per spawner. Natural per-capita production of recruits as the population approaches zero (density-independent component).SmaxVector length
nsim. The spawner abundance that maximizes smolt production in the Ricker stock-recruit function. Units of spawners.sigmaRVector length
nsim. The lognormal standard deviation in the Ricker stock-recruit relationship. Recruitment anomalies will be simulated with[stats::rlnorm()].RecdevOptional matrix
[nsim, ngen-1]of recruitment anomalies in the Ricker stock-recruit relationship. Overrides thesigmaRargument and provides more user flexibility, for example, simulating with auto-correlation.type_TCharacter. Whether to manage terminal fishery catch from exploitation rate ("u") or catch target ("catch"). Default is "u".
u_terminalNumeric, matrix
[nsim, proyears], or function. Iftype_T = "u", the harvest rate (ratio of kept catch to of the terminal marine fishery. Function should be of the formfunction(NO, HO, m) return(u).K_TNumeric or function. If
type_T = "catch", the catch target of the return in the terminal fishery. Function should be of the formfunction(NO, HO, m) return(K).InitReturnSingle numeric or vector
[nsim]. The return at the beginning of the projection. Default assumes 1000.
Creating Object
Objects can be created by calls of the form new("simpleSOM")
Examples
showClass("simpleSOM")
Example objects from salmonMSE
Description
S4 objects containing operating model inputs to run the projection.
Usage
simple_SOM
multi_SOM
Format
An object of class SOM.
An object of class SOM of length 1.
Source
See salmonMSE website
Examples
data(simple_SOM)
data(multi_SOM)
Internal stray function
Description
Calculates the number of fish that move from donor to recipient populations from a movement matrix
Usage
stray_func(N, stray_matrix, m)
Arguments
N |
Array |
stray_matrix |
Matrix |
m |
Vector |
Value
Named list:
-
N_remainAbundance of hatchery-origin fish that do not stray, same dimension asN -
N_strayAbundance of strays by recipient population, same dimension asN -
m_strayMark rate of strays by recipient population, vector[ns]