Title: | Woods Hole Assessment Model (WHAM) |
---|---|
Description: | The Woods Hole Assessment Model (WHAM) is a general age-structured stock assessment framework that can be configured to estimate assessment models that range in complexity from statistical catch-at-age (SCAA) model with annual recruitments as fixed effects, to state-space, multi-stock, multi-region, age-structured models where many parameters can be treated as time- and age-varying process errors and/or allowing effects of environmental covariates. WHAM is a generalization of code from Miller et al. (2016), Miller and Hyun (2018), and Miller et al. (2018). WHAM also has many similarities of input data sources with ASAP (Legault and Restrepo 1999) and provides functions to generate a WHAM input file from an ASAP3 dat file, although this is not a requirement. Many of the plotting functions for input data, results, and diagnostics have modified from code written by Chris Legault and Liz Brooks. |
Authors: | Tim Miller [aut, cre] |
Maintainer: | Tim Miller <[email protected]> |
License: | GPL-3 |
Version: | 2.0.0 |
Built: | 2025-03-20 20:45:03 UTC |
Source: | https://github.com/timjmiller/wham |
Access quick convergence checks from 'TMB' and 'nlminb'.
check_convergence(mod, ret = FALSE, f = "")
check_convergence(mod, ret = FALSE, f = "")
mod |
output from |
ret |
T/F, return list? Default = FALSE, just prints to console |
a list with at least the first three of these components:
$convergence
From stats::nlminb
, "0 indicates successful convergence for nlminb"
$maxgr
Max absolute gradient value, from 'max(abs(mod$gr(mod$opt$par)))'
$maxgr_par
Name of parameter with max gradient
$is_sdrep
If TMB::sdreport
was performed
for this model, this indicates whether it performed without error
$na_sdrep
If TMB::sdreport
was performed
without error for this model, this indicates which (if any) components of the
diagonal of the inverted hessian were returned as NA
fit_wham
, fit_tmb
, stats::nlminb
## Not run: data("input4_SNEMAYT") # load SNEMA yellowtail flounder data and parameter settings mod = fit_wham(input4_SNEMAYT) # using default values check_convergence(mod) ## End(Not run)
## Not run: data("input4_SNEMAYT") # load SNEMA yellowtail flounder data and parameter settings mod = fit_wham(input4_SNEMAYT) # using default values check_convergence(mod) ## End(Not run)
fit_tmb
.check_estimability
calculates the matrix of second-derivatives of the marginal likelihood
w.r.t. fixed effects, to see if any linear combinations are not estimable (i.e. cannot be
uniquely estimated conditional upon model structure and available data, e.g., resulting
in a likelihood ridge and singular, non-invertable Hessian matrix)
check_estimability(obj, h)
check_estimability(obj, h)
obj |
The compiled object |
h |
optional argument containing pre-computed Hessian matrix |
A tagged list of the hessian and the message
After fitting multiple WHAM (or ASAP) models, compare_wham_models
produces plots
and a table of AIC and Mohn's rho to aid model comparison.
compare_wham_models( mods, do.table = TRUE, do.plot = TRUE, fdir = getwd(), compare.opts = NULL, table.opts = NULL, plot.opts = NULL, fname = NULL, sort = NULL, calc.rho = NULL, calc.aic = NULL, do.print = NULL )
compare_wham_models( mods, do.table = TRUE, do.plot = TRUE, fdir = getwd(), compare.opts = NULL, table.opts = NULL, plot.opts = NULL, fname = NULL, sort = NULL, calc.rho = NULL, calc.aic = NULL, do.print = NULL )
mods |
(named) list of fit WHAM/ASAP models. To read in ASAP model output, use |
do.table |
T/F, produce table of AIC and/or Mohn's rho? Default = TRUE. |
do.plot |
T/F, produce plots? Default = TRUE. |
fdir |
character, path to directory to save table and/or plots. Default = |
compare.opts |
list of options to generate comparison results:
|
table.opts |
list of options for AIC/rho table:
|
plot.opts |
list of options for plots:
|
plot.opts$which
specifies which plots to make:
3-panel of SSB (spawning stock biomass), F (fully-selected fishing mortality), and Recruitment
CV (coefficient of variation) for SSB, F, and Recruitment
Fleet selectivity (by block, averaged across years)
Index selectivity (by block, averaged across years)
Selectivity tile (fleets + indices, useful for time-varying random effects)
M time series (natural mortality, can specify which age with plot.opts$M.age)
M tile (useful for time-varying random effects)
3-panel of F X% SPR, SSB at F_X%SPR, and yield at F_X%SPR
2-panel of relative status (SSB / SSB at F_X%SPR and F / F_X%SPR)
Kobe status (relative SSB vs. relative F)
If plot.opts$return.ggplot = TRUE
, a list g
is returned holding the above ggplot2 objects for later modification.
g[[i]]
holds the plot corresponding to i
above, e.g. g[[2]]
is the CV plot.
a list with the following components:
daic
Vector of delta-AIC by model (if do.table=T
and table.opts$calc.aic=T
)
aic
Vector of AIC by model (if do.table=T
and table.opts$calc.aic=T
)
rho
Matrix of Mohn's rho by model (if do.table=T
and table.opts$calc.rho=T
)
best
Name of best model (lowest AIC) (if do.table=T
and table.opts$calc.aic=T
)
tab
Results table of AIC and Mohn's rho (if do.table=T
)
g
List of ggplot2 objects for later modification (if do.plot=T
and plot.opts$return.ggplot=T
)
fit_wham
, read_asap3_fit,
read_wham_fit
## Not run: base <- read_asap3_fit() m1 <- fit_wham(input1) m2 <- fit_wham(input2) mods <- list(base=base, m1=m1, m2=m2) res <- compare_wham_models(mods) ## End(Not run)
## Not run: base <- read_asap3_fit() m1 <- fit_wham(input1) m2 <- fit_wham(input2) mods <- list(base=base, m1=m1, m2=m2) res <- compare_wham_models(mods) ## End(Not run)
Changes internal flags to do the extra calculations and reporting for reference points.
do_reference_points(model, do.sdrep = FALSE, save.sdrep = TRUE)
do_reference_points(model, do.sdrep = FALSE, save.sdrep = TRUE)
model |
a fitted WHAM model object returned by fit_wham or project_wham. |
do.sdrep |
T/F, calculate standard deviations of model parameters? See |
save.sdrep |
T/F, save the full |
Function to add fitted retrospective peels to fitted model returned by fit_wham
. Calls retro
.
to fit the model peeling off 1, 2, ..., n.peels
years of data.
This is just a wrapper for retro that instead of returning just the list of peels, returns the fitted model with the peels.
do_retro_peels( model, n.peels = 7, ran = NULL, use.mle = TRUE, do.sdrep = FALSE, n.newton = 0, MakeADFun.silent = FALSE, retro.silent = FALSE, save.input = FALSE, do.brps = FALSE, check.version = TRUE )
do_retro_peels( model, n.peels = 7, ran = NULL, use.mle = TRUE, do.sdrep = FALSE, n.newton = 0, MakeADFun.silent = FALSE, retro.silent = FALSE, save.input = FALSE, do.brps = FALSE, check.version = TRUE )
model |
Optimized TMB model, output from |
n.peels |
Integer, number of peels to use in retrospective analysis. Default = |
ran |
Character, specifies which parameters to treat as random effects. Default = |
use.mle |
T/F, use MLEs from full model fit as initial values for each peel? If not, the initial values from full model input are used. Default = |
do.sdrep |
T/F, calculate standard deviations of model parameters for each peel? Default = |
n.newton |
integer, number of additional Newton steps after optimization for each peel. Default = |
MakeADFun.silent |
T/F, Passed to silent argument of |
retro.silent |
T/F, Passed to argument of internal fit_peel function. Determines whether peel number is printed to screen. Default = |
save.input |
T/F, should modified input list be saved for every peel? Necessary to project from a peel but increases model object size. Default = |
do.brps |
T/F, calculate and report biological reference points |
check.version |
T/F, whether to verify the wham package commit and version for the fitted model are the same as the currently used package. |
peels
, a list of length n.peels
, where entry i is a model
fit by peeling off i years of data.
Runs TMB::sdreport
and adds the object to the fitted (and projected) model list. E.g., fit$sdrep.
do_sdreport( model, save.sdrep = TRUE, TMB.bias.correct = FALSE, TMB.jointPrecision = FALSE )
do_sdreport( model, save.sdrep = TRUE, TMB.bias.correct = FALSE, TMB.jointPrecision = FALSE )
model |
a fitted WHAM model object returned by fit_wham or project_wham. |
save.sdrep |
T/F, save the full |
TMB.bias.correct |
T/F whether to use the bias.correct feature of TMB::sdreport. Default = |
TMB.jointPrecision |
T/F whether to return the joint precision matrix for the fixed and random effects from TMB::sdreport. Default = |
check_estimability
.extract_fixed
extracts the best previous value of fixed effects, in a way that works for both mixed and fixed effect models
extract_fixed(obj)
extract_fixed(obj)
obj |
The compiled object |
A vector of fixed-effect estimates
Internal function called by retro
for i in 1–n.peels
.
Fits the model peeling off i years of data (calls fit_tmb
).
fit_peel( peel, input, do.sdrep = FALSE, n.newton = 3, MakeADFun.silent = FALSE, retro.silent = FALSE, save.input = FALSE )
fit_peel( peel, input, do.sdrep = FALSE, n.newton = 3, MakeADFun.silent = FALSE, retro.silent = FALSE, save.input = FALSE )
peel |
Integer, number of years of data to remove before model fitting. |
input |
input with same structure as that provided by |
do.sdrep |
T/F, calculate standard deviations of model parameters? Default = |
n.newton |
integer, number of additional Newton steps after optimizafit_tmbtion for each peel. Default = |
MakeADFun.silent |
T/F, Passed to silent argument of |
retro.silent |
T/F, Passed to argument of internal fit_peel function. Determines whether peel number is printed to screen. Default = |
save.input |
T/F, should modified input list be saved? Necessary to project from a peel but increases model object size. Default = |
out
, output of fit_tmb
for peel i
Runs optimization on the TMB model using stats::nlminb
.
If specified, takes additional Newton steps and calculates standard deviations.
Internal function called by fit_wham
.
fit_tmb( model, n.newton = 3, do.sdrep = TRUE, do.check = FALSE, save.sdrep = FALSE, use.optim = FALSE, opt.control = NULL )
fit_tmb( model, n.newton = 3, do.sdrep = TRUE, do.check = FALSE, save.sdrep = FALSE, use.optim = FALSE, opt.control = NULL )
model |
Output from |
n.newton |
Integer, number of additional Newton steps after optimization. Default = |
do.sdrep |
T/F, calculate standard deviations of model parameters? See |
do.check |
T/F, check if model parameters are identifiable? Runs internal |
save.sdrep |
T/F, save the full |
use.optim |
T/F, use |
opt.control |
list of control parameters to pass to optimizer. For nlminb default = list(iter.max = 1000, eval.max = 1000). For optim default = list(maxit=1000). |
model
, appends the following:
model$opt
Output from stats::nlminb
model$date
System date
model$dir
Current working directory
model$rep
model$report()
model$TMB_version
Version of TMB installed
model$parList
List of parameters, model$env$parList()
model$final_gradient
Final gradient, model$gr()
model$sdrep
Estimated standard deviations for model parameters, TMB::sdreport
or summary.sdreport)
fit_wham
, retro
, TMBhelper::check_estimability
Fits the compiled WHAM model using TMB::MakeADFun
and
stats::nlminb
. Runs retrospective analysis if specified.
fit_wham( input, n.newton = 3, do.sdrep = TRUE, do.retro = TRUE, n.peels = 7, do.osa = TRUE, osa.opts = list(method = "oneStepGaussianOffMode", parallel = TRUE), do.post.samp = TRUE, model = NULL, do.check = FALSE, MakeADFun.silent = FALSE, retro.silent = FALSE, do.proj = FALSE, proj.opts = list(n.yrs = 3, use.last.F = TRUE, use.avg.F = FALSE, use.FXSPR = FALSE, proj.F = NULL, proj.catch = NULL, avg.yrs = NULL, cont.ecov = TRUE, use.last.ecov = FALSE, avg.ecov.yrs = NULL, proj.ecov = NULL, cont.Mre = NULL, avg.rec.yrs = NULL, percentFXSPR = 100), do.fit = TRUE, save.sdrep = TRUE, do.brps = TRUE, fit.tmb.control = NULL, TMB.bias.correct = FALSE, TMB.jointPrecision = FALSE )
fit_wham( input, n.newton = 3, do.sdrep = TRUE, do.retro = TRUE, n.peels = 7, do.osa = TRUE, osa.opts = list(method = "oneStepGaussianOffMode", parallel = TRUE), do.post.samp = TRUE, model = NULL, do.check = FALSE, MakeADFun.silent = FALSE, retro.silent = FALSE, do.proj = FALSE, proj.opts = list(n.yrs = 3, use.last.F = TRUE, use.avg.F = FALSE, use.FXSPR = FALSE, proj.F = NULL, proj.catch = NULL, avg.yrs = NULL, cont.ecov = TRUE, use.last.ecov = FALSE, avg.ecov.yrs = NULL, proj.ecov = NULL, cont.Mre = NULL, avg.rec.yrs = NULL, percentFXSPR = 100), do.fit = TRUE, save.sdrep = TRUE, do.brps = TRUE, fit.tmb.control = NULL, TMB.bias.correct = FALSE, TMB.jointPrecision = FALSE )
input |
Named list with components:
|
n.newton |
integer, number of additional Newton steps after optimization. Passed to |
do.sdrep |
T/F, calculate standard deviations of model parameters? See |
do.retro |
T/F, do retrospective analysis? Default = |
n.peels |
integer, number of peels to use in retrospective analysis. Default = |
do.osa |
T/F, calculate one-step-ahead (OSA) residuals? Default = |
osa.opts |
list of 2 options (method, parallel) for calculating OSA residuals, passed to |
do.post.samp |
T/F, obtain sample from posterior of random effects? Default = |
model |
(optional), a previously fit wham model. |
do.check |
T/F, check if model parameters are identifiable? Passed to |
MakeADFun.silent |
T/F, Passed to silent argument of |
retro.silent |
T/F, Passed to argument of internal retro function. Determines whether peel number is printed to screen. Default = |
do.proj |
T/F, do projections? Default = |
proj.opts |
a named list with the following components:
|
do.fit |
T/F, fit the model using |
save.sdrep |
T/F, save the full |
do.brps |
T/F, calculate and report biological reference points. Default = |
fit.tmb.control |
list of optimizer controlling attributes passed to |
TMB.bias.correct |
T/F whether to use the bias.correct feature of TMB::sdreport. Default = |
TMB.jointPrecision |
T/F whether TMB::sdreport should return the joint precision matrix for the fixed and random effects. Default = |
Standard residuals are not appropriate for models with random effects. Instead, one-step-ahead (OSA) residuals
can be used for evaluating model goodness-of-fit (Thygeson et al. (2017),
implemented in TMB::oneStepPredict
). Additional OSA residual options
are passed to TMB::oneStepPredict
in a list osa.opts
. For example,
to use the (much faster, ~1 sec instead of 2 min) full Gaussian approximation instead of the (default)
generic method, you can use osa.opts=list(method="fullGaussian")
.
a fit TMB model with additional output if specified:
$rep
List of derived quantity estimates (see examples)
$sdrep
Parameter estimates (and standard errors if do.sdrep=TRUE
)
$peels
Retrospective analysis (if do.retro=TRUE
)
$osa
One-step-ahead residuals (if do.osa=TRUE
)
fit_tmb
, retro
, TMB::oneStepPredict
, project_wham
## Not run: data("input4_SNEMAYT") # load SNEMA yellowtail flounder data and parameter settings mod = fit_wham(input4_SNEMAYT) # using default values mod = fit_wham(input4_SNEMAYT, do.retro=FALSE, osa.opts=list(method="oneStepGeneric")) # slower OSA method. names(mod$rep) # list of derived quantities mod$rep$SSB # get SSB estimates (weight, not numbers) m1$rep$NAA[,1] # get recruitment estimates (numbers, first column of numbers-at-age matrix) m1$rep$F[,1] # get F estimates for fleet 1 ## End(Not run)
## Not run: data("input4_SNEMAYT") # load SNEMA yellowtail flounder data and parameter settings mod = fit_wham(input4_SNEMAYT) # using default values mod = fit_wham(input4_SNEMAYT, do.retro=FALSE, osa.opts=list(method="oneStepGeneric")) # slower OSA method. names(mod$rep) # list of derived quantities mod$rep$SSB # get SSB estimates (weight, not numbers) m1$rep$NAA[,1] # get recruitment estimates (numbers, first column of numbers-at-age matrix) m1$rep$F[,1] # get F estimates for fleet 1 ## End(Not run)
Refits a previously fitted WHAM model a number of times with different initial parameter values
jitter_wham( fit_RDS = NULL, n_jitter = 10, initial_vals = NULL, which_rows = NULL, do_parallel = TRUE, n_cores = NULL, res_dir = NULL, wham_location = NULL, test_dir = NULL )
jitter_wham( fit_RDS = NULL, n_jitter = 10, initial_vals = NULL, which_rows = NULL, do_parallel = TRUE, n_cores = NULL, res_dir = NULL, wham_location = NULL, test_dir = NULL )
fit_RDS |
(required) location of RDS file with fitted WHAM model. |
n_jitter |
the number of different starting locations on the likelihood surface to refit the model from. Default = 10. |
initial_vals |
(optional) matrix (n_jitter x n parameters) of starting values to use for jittering. |
which_rows |
(optional) which rows of intial_vals to use for jittering. Useful if doing jitter fits in stages. |
do_parallel |
T/F whether to do jitter fits in parallel. Requires snowfall and parallel packages to be installed. Default = TRUE. |
n_cores |
(optional) the number of cores to use for parallel fitting. |
res_dir |
directory where to save individual files for each jitter refit. Useful if jittering for some reason crashes R. If not provided, no files will be saved. |
wham_location |
(optional) location of WHAM package. Useful if not using the WHAM installation in the standard library location. |
test_dir |
(optional) directory for package repository. To be used when the function is being called during package testing rather than an installed version of WHAM. |
Because the likelihood surface of a specific model may not be monotone, optimization may result in a local maximum which can be dependent on the parameter
values used to start the optimization. It is considered good practice to check whether the optimization is consistent for a range of starting values.
There does not appear to be an approach that is both best and computationally efficient to do this check so, this function allows the user to provide the
alternative starting values for all fixed effects parameters to use in the jittering. When initial_vals
is not provided, a default method is used
where n_jitter random draws from a MVN distribution with mean equal to the MLE from the fitted model and covariance matrix equal to that estimated for the
the MLEs.
a list of two elements. First is the results which is a list (length = n_jitter) of lists with 3 elements: minimized negative log-likelihood, jitter MLEs, and gradient. Second element is the matrix of initial values for the jitters.
Standard residuals are not appropriate for models with random effects. Instead, one-step-ahead (OSA) residuals
can be used for evaluating model goodness-of-fit (Thygeson et al. (2017),
implemented in TMB::oneStepPredict
). OSA residual options
are passed to TMB::oneStepPredict
in a list osa.opts
. Current options are method:
oneStepGaussianOffMode (default), oneStepGaussian, or oneStepGeneric, and parallel: TRUE/FALSE.
See TMB::oneStepPredict
for further details.
It is not recommended to run this function (or TMB::oneStepPredict
) with any random effects and
mvtweedie age composition likelihoods due to extensive computational demand. An error will be thrown in such cases.
See Trijoulet et al. (2023) for OSA methods for age composition OSA residuals.
make_osa_residuals( model, osa.opts = list(method = "oneStepGaussianOffMode", parallel = TRUE), sdrep_required = TRUE )
make_osa_residuals( model, osa.opts = list(method = "oneStepGaussianOffMode", parallel = TRUE), sdrep_required = TRUE )
model |
A fit WHAM model, output from |
the same fit TMB model with additional elements for osa residuals:
$OSA.Ecov
data.frame returned by TMB::oneStepPredict
for environmental observations, if applicable.
$OSA.agregate
data.frame returned by TMB::oneStepPredict
for aggregate catch and index
observations conditional on any environmental observations, if applicable.
$OSA.agecomp
data.frame returned by TMB::oneStepPredict
for age composition observations
conditional on any aggregate catch or index, or environmental observations, if applicable.
$osa
One-step-ahead residuals (if do.osa=TRUE
)
## Not run: data("input4_SNEMAYT") # load SNEMA yellowtail flounder data and parameter settings mod <- fit_wham(input4_SNEMAYT, do.osa =FALSE, do.retro =FALSE) mod <- make_osa_residuals(mod) # calculate Mohn's rho plot_wham_output(mod) ## End(Not run)
## Not run: data("input4_SNEMAYT") # load SNEMA yellowtail flounder data and parameter settings mod <- fit_wham(input4_SNEMAYT, do.osa =FALSE, do.retro =FALSE) mod <- make_osa_residuals(mod) # calculate Mohn's rho plot_wham_output(mod) ## End(Not run)
Calculate Mohn's rho for a WHAM model with peels
mohns_rho(model)
mohns_rho(model)
model |
A fit WHAM model, output from |
rho
, a vector of Mohn's rho
## Not run: data("input4_SNEMAYT") # load SNEMA yellowtail flounder data and parameter settings mod = fit_wham(input4_SNEMAYT) # using default values: do.retro = T, n.peels = 7 mohns_rho(mod) # calculate Mohn's rho ## End(Not run)
## Not run: data("input4_SNEMAYT") # load SNEMA yellowtail flounder data and parameter settings mod = fit_wham(input4_SNEMAYT) # using default values: do.retro = T, n.peels = 7 mohns_rho(mod) # calculate Mohn's rho ## End(Not run)
Generates many output plots and tables for a fit WHAM model.
plot_wham_output( mod, dir.main = getwd(), out.type = "html", res = 72, plot.opts = NULL )
plot_wham_output( mod, dir.main = getwd(), out.type = "html", res = 72, plot.opts = NULL )
mod |
output from |
dir.main |
character, directory to save plots to (default = |
out.type |
character, either |
res |
resolution to save .png files (dpi) |
plot.opts |
(optional) list of plot modifications |
out.type = 'html'
(default) makes a html file for viewing plot .png files and html tables of parameter estimates in a browser.
out.type = 'pdf'
makes one pdf file of all plots and tables.
out.type = 'png'
creates a subdirectory 'plots_png“ in dir.main
and saves .png files within.
out.type = 'pdf' or 'png'
makes LaTeX and pdf files of tables of parameter estimates.
(tabs: 'input data', 'diagnostics', 'results', 'ref_points', 'retro', and 'misc').
plot.opts
holds optional arguments to modify plots:
$ages.lab
Character vector, will change age labels in plots (default is 1:n.ages
).
$font.family
Font family, e.g. "Times"
.
$browse
T/F whether to open the html file in a browser. Default = T.
Plot functions are located in wham_plots_tables.R
Table function is located in par_tables_fn.R
fit_wham
, wham_html
, wham_plots_tables
## Not run: data("input4_SNEMAYT") # load fit wham model mod <- fit_wham(input4_SNEMAYT) plot_wham_output(mod) ## End(Not run)
## Not run: data("input4_SNEMAYT") # load fit wham model mod <- fit_wham(input4_SNEMAYT) plot_wham_output(mod) ## End(Not run)
prepare_projection
is an internal function called by project_wham
,
which in turn is called by fit_wham
if do.proj = TRUE
.
prepare_projection(model, proj.opts, check.version = FALSE)
prepare_projection(model, proj.opts, check.version = FALSE)
model |
a previously fit wham model |
proj.opts |
a named list with the following components:
|
check.version |
T/F check whether version WHAM and TMB for fitted model match that of the version of WHAM using for projections. Default = |
same as prepare_wham_input
, a list ready for fit_wham
:
data
Named list of data, passed to TMB::MakeADFun
par
Named list of parameters, passed to TMB::MakeADFun
map
Named list of factors that determine which parameters are estimated, passed to TMB::MakeADFun
random
Character vector of parameters to treat as random effects, passed to TMB::MakeADFun
years
Numeric vector of representing (non-projection) model years of WHAM model
years_full
Numeric vector of representing all model and projection years of WHAM model
ages.lab
Character vector of age labels, ending with plus-group
model_name
Character, name of stock/model (specified in call to prepare_wham_input
)
prepare_wham_input
, project_wham
Prepares data and parameter settings for fit_wham
, optionally using an ASAP3 data file read into R by read_asap3_dat
.
By default, this will set up a SCAA version like ASAP without any penalties or random effects.
If any asap3, basic_info, catch_info, and index_info arguments are not provided, some respective arbitrary
assumptions are made. The various options described below, such as NAA_re
and selectivity
,
can still be used without the asap3 object.
prepare_wham_input( asap3 = NULL, model_name = "WHAM for unnamed stock", recruit_model = 2, ecov = NULL, selectivity = NULL, M = NULL, NAA_re = NULL, catchability = NULL, age_comp = NULL, move = NULL, L = NULL, F = NULL, catch_info = NULL, index_info = NULL, basic_info = NULL )
prepare_wham_input( asap3 = NULL, model_name = "WHAM for unnamed stock", recruit_model = 2, ecov = NULL, selectivity = NULL, M = NULL, NAA_re = NULL, catchability = NULL, age_comp = NULL, move = NULL, L = NULL, F = NULL, catch_info = NULL, index_info = NULL, basic_info = NULL )
asap3 |
(optional) list containing data and parameters (output from |
model_name |
character, name of stock/model |
recruit_model |
numeric, option to specify stock-recruit model (see details) |
ecov |
(optional) named list of environmental covariate data and parameters (see |
selectivity |
(optional) list specifying selectivity options by block: models, initial values, parameters to fix, and random effects (see |
M |
(optional) list specifying natural mortality options: model, random effects, initial values, and parameters to fix (see |
NAA_re |
(optional) list specifying options for random effect on numbers-at-age, initial numbers at age, and recruitment model (see |
catchability |
(optional) list specifying options for priors and random effects on catchability (see |
age_comp |
(optional) character or named list, specifies age composition model for fleet(s) and indices (see |
move |
(optional) list specifying movement/migration options for models with more than 1 region (see |
L |
(optional) list specifying "extra" mortality options (see |
F |
(optional) list specifying fishing mortality options (see |
catch_info |
(optional) list specifying catch information (see |
index_info |
(optional) list specifying index informaiton (see |
basic_info |
(optional) list of basic population information for use when asap3 is not provided (see details) |
recruit_model
specifies the stock-recruit model. See wham.cpp
for implementation.
SCAA (without NAA_re option specified) or Random walk (if NAA_re$sigma specified), i.e. predicted recruitment in year i = recruitment in year i-1
(default) Random about mean, i.e. steepness = 1
Beverton-Holt
Ricker
Note: fit_wham
allows fitting a SCAA model (NAA_re = NULL
), which estimates recruitment in every year as separate fixed effect parameters,
but in that case no stock-recruit function is estimated. A warning message is printed if recruit_model > 2
and NAA_re = NULL
.
If you wish to use a stock-recruit function for expected recruitment, choose recruitment deviations as random effects,
either only age-1 (NAA_re = list(sigma="rec")
) or all ages (NAA_re = list(sigma="rec+1")
, "full state-space" model).
See below for details on NAA_re
specification.
ecov
specifies any environmental covariate data and models. See set_ecov
for full details.
selectivity
specifies options for selectivity, to overwrite existing options specified in the ASAP data file. See set_selectivity
for full details.
M
specifies estimation options for natural mortality and can overwrite M-at-age values specified in the ASAP data file. See set_M
for full details.
NAA_re
specifies options for random effects on numbers-at-age (NAA, i.e. state-space model or not). See set_NAA
for full details.
If NULL
, a traditional statistical catch-at-age model is fit.
catchability
specifies options for catchability. See set_q
for full details. If NULL
and asap3
is not NULL, a single catchability parameter for each index is used with initial values specified in ASAP file. If both are NULL, initial catchabilities for all indices = 0.3.
move
specifies options for movement if there are multiple regions. See set_move
for full details.
age_comp
specifies the age composition models for fleet(s) and indices. See set_age_comp
for full details.
catch_info
is an optional list of fishery catch information that can be used to set up these types of observations when there is no asap3 file given. See set_catch
for full details. Useful for setting
up an operating model to simulate population processes and observations. Also can be useful for setting up the structure of assessment model when asap3 has not been used.
index_info
is an optional list of survey/index information that can be used to set up these types of observations when there is no asap3 file given. See set_indices
for full details. Useful for setting
up an operating model to simulate population processes and observations. Also can be useful for setting up the structure of assessment model when asap3 has not been used.
basic_info
is an optional list of information that can be used to set up the population and types of observations when there is no asap3 file given. Particularly useful for setting
up an operating model to simulate population processes and observations. Also can be useful for setting up the structure of assessment model when asap3 has not been used.
The current options are:
integer vector of ages (years) with the last being a plus group
integer vector of years that the population model spans.
number of seasons within year.
number of fishing fleets.
proportions of year for each season within year (sums to 1).
matrix (length(years) x n_fleets) of annual fishing mortality rates for each fleet to initialize the model.
array ((n_fleets + n_indices + n_stocks) x length(years) x length(ages)) of annual weight at at age for each fleet, each index, and spawning biomass for each stock.
array (n_stocks x length(years) x length(ages)) of annual maturity at age for estimating spawning biomass for each stock.
matrix (n_years x n_stocks) (1 or length(years)) of yearly proportions (0-1) of the year at which to calculate spawning biomass.
vector (n_stocks) of seasons in which each stock spawns.
vector (n_stocks) of regions in which each stock spawns.
array (n_stocks x n_regions x n_ages) of 0/1 indicating where individuals of each stock may exist on January 1 of each year.
integer vector of ages to use to average F at age for reported "Fbar" across all fleets, by regions and by fleet.
vector (length(n_indices)) of catchabilities for each of the indices to initialize the model.
(0-100) percentage of unfished spawning biomass per recruit for determining equilibrium fishing mortality reference point
(0-100) percentage of SPR-based F to use in projections.
(0-100) percentage of Fmsy to use in projections.
which years to average inputs to per recruit calculation (selectivity, M, WAA, maturity) for SPR-based reference points. Default is last 5 years (tail(1:length(years),5))
which years to average recruitments for calculating SPR-based SSB reference points. Default is 1:length(years)
1(3): use annual R estimates(predictions) for annual SSB_XSPR, 2(4): use average R estimates(predictions). 5: use bias-corrected expected recruitment. For long-term projections, may be important to use certain years for XSPR_R_avg_yrs
T/F vector (length = 9). When simulating from the model, whether to simulate any process errors for (NAA, M, selectivity, q, movement, unidentified mortality, q priors, movement priors, Ecov). Only used for applicable random effects.
T/F vector (length = 3). When simulating from the model, whether to simulate catch, index, and ecov observations.
T/F vector (length = 2). When simulating from the model, whether to simulate base period (model years) and projection period.
T/F. Perform bias correction of log-normal random effects for NAA.
T/F. Perform bias correction of analytic SSB/R and Y/R when there is bias correction of log-normal NAA. May want to use XSPR_R_opt = 5 for long-term projections.
If other arguments to prepare_wham_input
are provided such as selectivity
, M
, and age_comp
, the information provided there
must be consistent with basic_info
. For example the dimensions for number of years, ages, fleets, and indices.
a named list with the following components:
data
Named list of data, passed to TMB::MakeADFun
par
Named list of parameters, passed to TMB::MakeADFun
map
Named list defining how to optionally collect and fix parameters, passed to TMB::MakeADFun
random
Character vector of parameters to treat as random effects, passed to TMB::MakeADFun
years
Numeric vector of years to fit WHAM model (specified in ASAP3 .dat file)
ages.lab
Character vector of age labels, ending with plus-group (specified in ASAP3 .dat file)
model_name
Character, name of stock/model (specified in call to prepare_wham_input
)
log
list of character strings attempting to describe the input and what the model assumes.
read_asap3_dat
, fit_wham
, ASAP, Iles & Beverton (1998)
## Not run: asap3 = read_asap3_dat("ex1_SNEMAYT.dat") input = prepare_wham_input(asap3) mod = fit_wham(input) # no ASAP3 file, default parameter values and configuration input = prepare_wham_input() mod = fit_wham(input, fit = FALSE) set.seed(8675309) simdata = mod$simulate(complete=TRUE) input$data = simdata fit = fit_wham(input, do.osa = FALSE) ## End(Not run)
## Not run: asap3 = read_asap3_dat("ex1_SNEMAYT.dat") input = prepare_wham_input(asap3) mod = fit_wham(input) # no ASAP3 file, default parameter values and configuration input = prepare_wham_input() mod = fit_wham(input, fit = FALSE) set.seed(8675309) simdata = mod$simulate(complete=TRUE) input$data = simdata fit = fit_wham(input, do.osa = FALSE) ## End(Not run)
Provides projections/forecasts for an existing (already fit) WHAM model.
project_wham( model, proj.opts = list(n.yrs = 3, use.last.F = TRUE, use.avg.F = FALSE, use.FXSPR = FALSE, use.FMSY = FALSE, cont.ecov = TRUE, use.last.ecov = FALSE, percentFXSPR = 100, percentFMSY = 100), n.newton = 3, do.sdrep = TRUE, MakeADFun.silent = FALSE, save.sdrep = TRUE, check.version = TRUE, TMB.bias.correct = FALSE, TMB.jointPrecision = FALSE )
project_wham( model, proj.opts = list(n.yrs = 3, use.last.F = TRUE, use.avg.F = FALSE, use.FXSPR = FALSE, use.FMSY = FALSE, cont.ecov = TRUE, use.last.ecov = FALSE, percentFXSPR = 100, percentFMSY = 100), n.newton = 3, do.sdrep = TRUE, MakeADFun.silent = FALSE, save.sdrep = TRUE, check.version = TRUE, TMB.bias.correct = FALSE, TMB.jointPrecision = FALSE )
model |
a previously fit wham model |
proj.opts |
a named list with the following components:
|
n.newton |
integer, number of additional Newton steps after optimization. Passed to |
do.sdrep |
T/F, calculate standard deviations of model parameters? See |
MakeADFun.silent |
T/F, Passed to silent argument of |
save.sdrep |
T/F, save the full |
check.version |
T/F check whether version WHAM and TMB for fitted model match that of the version of WHAM using for projections. Default = |
TMB.bias.correct |
T/F whether to use the bias.correct feature of TMB::sdreport. Default = |
TMB.jointPrecision |
T/F whether to return the joint precision matrix for the fixed and random effects from TMB::sdreport. Default = |
WHAM implements five options for handling fishing mortality in the projections.
Exactly one of these must be specified in proj.opts
:
Use last year F (default). Set proj.opts$use.last.F = TRUE
. WHAM will use F in the terminal model year for projections.
Use average F. Set proj.opts$use.avg.F = TRUE
. WHAM will use F averaged over proj.opts$avg.yrs
for projections (as is done for M-, maturity-, and weight-at-age).
Use F at X% SPR. Set proj.opts$use.FXSPR = TRUE
. WHAM will calculate F at X% SPR.
Specify F. Provide proj.opts$proj.F
, an F vector with length = n.yrs
.
Specify catch. Provide proj.opts$proj.catch
, a vector of aggregate catch with length = n.yrs
. WHAM will calculate F to get specified catch.
proj.opts$avg.yrs
controls which years the following will be averaged over in the projections:
Maturity-at-age
Weight-at-age
Natural mortality-at-age
Fishing mortality-at-age (if proj.opts$use.avgF = TRUE
)
If fitting a model with recruitment estimated freely in each year, i.e. as fixed effects as in ASAP, WHAM handles recruitment
in the projection years similarly to using the empirical cumulative distribution function. WHAM does this by calculating the mean
and standard deviation of log(R) over all model years (default) or a specified subset of years (proj.opts$avg.rec.yrs
). WHAM then
treats recruitment in the projections as a random effect with this mean and SD, i.e. log(R) ~ N(meanlogR, sdlogR).
WHAM implements four options for handling the environmental covariate(s) in the projections.
Exactly one of these must be specified in proj.opts
if ecov
is in the model:
Set $cont.ecov = TRUE
. WHAM will estimate the ecov process in projection years (i.e. continue the random walk / AR1 process).
Set $use.last.ecov = TRUE
. WHAM will use ecov value from the terminal year (of population model) for projections.
Provide $avg.yrs.ecov
, a vector specifying which years to average over the environmental covariate(s) for projections.
ecov
Provide $proj.ecov
, a matrix of user-specified environmental covariate(s) to use for projections. Dimensions must be # projection years (proj.opts$n.yrs
) x # ecovs (ncols(ecov$mean)
).
If the original model fit the ecov in years beyond the population model, WHAM will use the already-fit
ecov values for the projections. If the ecov model extended at least proj.opts$n.yrs
years
beyond the population model, then none of the above need be specified.
a projected WHAM model with additional output if specified:
$rep
List of derived quantity estimates (see examples)
$sdrep
Parameter estimates (and standard errors if do.sdrep=TRUE
)
$peels
Retrospective analysis (if do.retro=TRUE
)
$osa
One-step-ahead residuals (if do.osa=TRUE
)
## Not run: data("input4_SNEMAYT") # load SNEMA yellowtail flounder input data and model settings mod <- fit_wham(input4_SNEMAYT) # using default values (do.proj=T) mod2 <- fit_wham(input4_SNEMAYT, do.retro=F, do.osa=F, do.proj=F) # fit model without projections, retro analysis, or OSA residuals mod_proj <- project_wham(mod2) # add projections to previously fit model, using default values: use.lastF = TRUE, n.yrs = 3, avg.yrs = last 5 years names(mod_proj$rep) # list of derived quantities tail(mod_proj$rep$SSB, 3) # get 3-year projected SSB estimates (weight, not numbers) x = summary(mod_proj$sdrep) unique(rownames(x)) # list of estimated parameters and derived quanitites with SE x = x[rownames(x) == "log_SSB",] # SSB estimates with SE ssb.mat = exp(cbind(x, x[,1] + qnorm(0.975)*cbind(-x[,2],x[,2])))/1000 # calculate 95% CI colnames(ssb.mat) <- c("SSB","SSB_se","SSB_lower","SSB_upper") tail(ssb.mat, 3) # 3-year projected SSB estimates with SE and 95% CI ## End(Not run)
## Not run: data("input4_SNEMAYT") # load SNEMA yellowtail flounder input data and model settings mod <- fit_wham(input4_SNEMAYT) # using default values (do.proj=T) mod2 <- fit_wham(input4_SNEMAYT, do.retro=F, do.osa=F, do.proj=F) # fit model without projections, retro analysis, or OSA residuals mod_proj <- project_wham(mod2) # add projections to previously fit model, using default values: use.lastF = TRUE, n.yrs = 3, avg.yrs = last 5 years names(mod_proj$rep) # list of derived quantities tail(mod_proj$rep$SSB, 3) # get 3-year projected SSB estimates (weight, not numbers) x = summary(mod_proj$sdrep) unique(rownames(x)) # list of estimated parameters and derived quanitites with SE x = x[rownames(x) == "log_SSB",] # SSB estimates with SE ssb.mat = exp(cbind(x, x[,1] + qnorm(0.975)*cbind(-x[,2],x[,2])))/1000 # calculate 95% CI colnames(ssb.mat) <- c("SSB","SSB_se","SSB_lower","SSB_upper") tail(ssb.mat, 3) # 3-year projected SSB estimates with SE and 95% CI ## End(Not run)
WHAM is built on ASAP ([Legault and Restrepo (1999)](http://sedarweb.org/docs/wsupp/S12RD06%20ASAPdoc.pdf)) and this
function provides functionality to use a preexisting ASAP3 input data file. The
output of read_asap3_dat
should then be passed to prepare_wham_input
.
If you are not familiar with ASAP3 input files, see the ASAP documentation
and code.
read_asap3_dat(filename)
read_asap3_dat(filename)
filename |
character vector, names of ASAP3 .dat files. The file either needs to be
in the current working directory, or |
a named list with the following components:
dat
Named list of input data and parameters
comments
Comments at top of ASAP3 .dat file (indicated by "#")
prepare_wham_input
, fit_wham
, ASAP documentation
## Not run: asap3 = read_asap3_dat("ASAP_SNEMAYT.dat") input = prepare_wham_input(asap3) mod = fit_wham(input) ## End(Not run)
## Not run: asap3 = read_asap3_dat("ASAP_SNEMAYT.dat") input = prepare_wham_input(asap3) mod = fit_wham(input) ## End(Not run)
Gets output from a fit ASAP3 model for plotting with WHAM models.
read_asap3_fit(wd, asap.name, pSPR = 40)
read_asap3_fit(wd, asap.name, pSPR = 40)
wd |
character, directory where ASAP3 output files are located (ex: 'C:/MY/file/directories/model/'). 5 files are needed: |
asap.name |
character, base name of original .dat file (i.e. without the .dat extension) |
pSPR |
scalar, user-specified percent SPR to use for reference points, expressed as 100*SSBPR(Fspr)/SSBPR(F=0). Default = 40. |
a named list with the following elements:
$years
numeric vector, model years only, e.g. 1972:2020
$years_full
numeric vector, model + proj years, e.g. 1972:2022
. For ASAP this will be the same as $years
.
$selAA
list of length(n_selblocks), first the fleet blocks then indices, i.e. if 4 fleet blocks and 3 indices, selAA[[5]]
is for index 1. Each element is a matrix, years (rows) x ages (cols), selectivity at age
$selblock_pointer_fleets
matrix, n_years x n_fleets, indices of selAA used by each fleet in each year
$selblock_pointer_indices
matrix, n_years x n_indices, indices of selAA used by each index in each year
$MAA
matrix, n_years x n_ages, natural mortality
$log_SSB
matrix, n_years x 2, log-scale spawning stock biomass. 1st col = MLE, 2nd col = SE (from .std file in ADMB).
$log_F
matrix, n_years x 2, log-scale fully-selected F. 1st col = MLE, 2nd col = SE (from .std file in ADMB).
$log_NAA
matrix, n_years x n_ages, numbers at age
$NAA_CV
matrix, n_years x n_ages, CV of numbers at age
$percentSPR
scalar, X% SPR used to calculate reference points, default = 40
$log_Y_FXSPR
matrix, n_years x 2, log-scale yield at FXSPR. 1st col = MLE, 2nd col = SE.
$log_FXSPR
matrix, n_years x 2, log-scale FXSPR. 1st col = MLE, 2nd col = SE.
$log_SSB_FXSPR
matrix, n_years x 2, log-scale SSB at FXSPR, i.e. annual numerator of SPR(FXSPR) * Recruits. 1st col = MLE, 2nd col = SE.
$log_rel_ssb_F_cov
list, length n_years, each element is a 2x2 covariance matrix with SSB / SSB_FXSPR first and F / F_FXSPR second
compare_wham_models
, read_wham_fit
## Not run: base <- read_asap3_fit(wd=file.path(getwd(),'asap_results'), asap.name='BASE_5C.DAT', pSPR=40) m1 <- fit_wham(input1) m2 <- fit_wham(input2) mods <- list(base=base, m1=m1, m2=m2) res <- compare_wham_models(mods) ## End(Not run)
## Not run: base <- read_asap3_fit(wd=file.path(getwd(),'asap_results'), asap.name='BASE_5C.DAT', pSPR=40) m1 <- fit_wham(input1) m2 <- fit_wham(input2) mods <- list(base=base, m1=m1, m2=m2) res <- compare_wham_models(mods) ## End(Not run)
Gets output from a fit WHAM model for plotting with other models.
Internal function, called within compare_wham_models
.
read_wham_fit(mod, alphaCI = 0.05)
read_wham_fit(mod, alphaCI = 0.05)
mod |
output from |
alphaCI |
(1-alpha)% confidence intervals will be calculated. Default = 0.05 for 95% CI. |
a named list with the following elements:
$years
numeric vector, model years only, e.g. 1972:2020
$years_full
numeric vector, model + proj years, e.g. 1972:2022
$selAA
list of length(n_selblocks), first the fleet blocks then indices, i.e. if 4 fleet blocks and 3 indices, selAA[[5]]
is for index 1. Each element is a matrix, years (rows) x ages (cols), selectivity at age
$selblock_pointer_fleets
matrix, years x fleets, indices of selAA used by each fleet in each year
$selblock_pointer_indices
matrix, years x indices, indices of selAA used by each index in each year
$MAA
array, stocks x regions x years x ages, natural mortality
$log_SSB
matrix, years x 2, log-scale spawning stock biomass. 1st col = MLE, 2nd col = SE.
$log_F
matrix, years x 2, log-scale fully-selected F. 1st col = MLE, 2nd col = SE.
$log_NAA_rep
array, stocks x regions x years x ages, numbers at age
$NAA_CV
array, stocks x regions x years x ages, CV of numbers at age
$percentSPR
scalar, X% SPR used to calculate reference points, default = 40
$log_Y_FXSPR
matrix, years x 2, log-scale yield at FXSPR. 1st col = MLE, 2nd col = SE.
$log_FXSPR
matrix, years x 2, log-scale FXSPR. 1st col = MLE, 2nd col = SE.
$log_SSB_FXSPR
matrix, years x 2, log-scale SSB at FXSPR. 1st col = MLE, 2nd col = SE.
$log_rel_ssb_F_cov
list, length n_years, each element is a 2x2 covariance matrix with SSB/SSB_FXSPR first and F/F_FXSPR second
fit_wham
, read_asap3_fit
, compare_wham_models
Internal function called by fit_peel
for i in 1–n.peels
.
Creates the input for the model peeling off i years of data (calls fit_tmb
).
Reduces the year dimension of all data, parameters, maps, so that one can project correctly from the peeled model.
reduce_input(input, years_peeled, retro = TRUE)
reduce_input(input, years_peeled, retro = TRUE)
input |
list containing data, parameters, map, and random elements (output from |
years_peeled |
which of input$years to peel from the model input |
retro |
(T/F) whether this is for a retro peel (Default = TRUE) |
Internal function called by fit_wham
. Calls fit_peel
to fit the model peeling off 1, 2, ..., n.peels
years of data.
retro( model, n.peels = 7, ran = NULL, use.mle = TRUE, do.sdrep = FALSE, n.newton = 0, MakeADFun.silent = FALSE, retro.silent = FALSE, save.input = FALSE, do.brps = FALSE, check.version = TRUE )
retro( model, n.peels = 7, ran = NULL, use.mle = TRUE, do.sdrep = FALSE, n.newton = 0, MakeADFun.silent = FALSE, retro.silent = FALSE, save.input = FALSE, do.brps = FALSE, check.version = TRUE )
model |
Optimized TMB model, output from |
n.peels |
Integer, number of peels to use in retrospective analysis. Default = |
ran |
Character, specifies which parameters to treat as random effects. Default = |
use.mle |
T/F, use MLEs from full model fit as initial values for each peel? If not, the initial values from full model input are used. Default = |
do.sdrep |
T/F, calculate standard deviations of model parameters for each peel? Default = |
n.newton |
integer, number of additional Newton steps after optimization for each peel. Default = |
MakeADFun.silent |
T/F, Passed to silent argument of |
retro.silent |
T/F, Passed to argument of internal fit_peel function. Determines whether peel number is printed to screen. Default = |
save.input |
T/F, should modified input list be saved for every peel? Necessary to project from a peel but increases model object size. Default = |
do.brps |
T/F, calculate and report biological reference points |
check.version |
T/F, whether to verify the wham package commit and version for the fitted model are the same as the currently used package. |
peels
, a list of length n.peels
, where entry i is a model
fit by peeling off i years of data.
Generate simulated data from fitted model and refit the model to the simulated data
self_test( fit_RDS = NULL, n = 10, seeds = NULL, which_seeds = NULL, conditional = TRUE, map_change = NULL, do_parallel = TRUE, n_cores = NULL, res_dir = NULL, wham_location = NULL, test_dir = NULL, save_inputs = FALSE )
self_test( fit_RDS = NULL, n = 10, seeds = NULL, which_seeds = NULL, conditional = TRUE, map_change = NULL, do_parallel = TRUE, n_cores = NULL, res_dir = NULL, wham_location = NULL, test_dir = NULL, save_inputs = FALSE )
fit_RDS |
(required) location of RDS file with fitted WHAM model. |
n |
the number of simulated data sets to create and fit. Default = 10. |
seeds |
(optional) vector of seeds to use to generate each simulated data set. |
which_seeds |
(optional) which |
conditional |
T/F whether to fix rather than simulate estimated random effects. Deafult = TRUE. |
map_change |
(optional) list of input$map elements for altering mapping assumptions of fitted model. |
do_parallel |
T/F whether to do self-test fits in parallel. Requires snowfall and parallel packages to be installed. Default = TRUE. |
n_cores |
(optional) the number of cores to use for parallel fitting. |
res_dir |
directory where to save individual files for each self test fit. Useful if doing self test in stages. If not provided, no files will be saved. |
wham_location |
(optional) location of WHAM package. Useful if not using the WHAM installation in the standard library location. |
test_dir |
(optional) directory for package repository. To be used when the function is being called during package testing rather than an installed version of WHAM. |
save_inputs |
T/F whether to save the simulated inputs in res_dir. Default = FALSE. |
a list of two elements. First is the results which is a list (length = n) of lists with 6 elements: minimized negative log-likelihood, MLEs, gradient, SSB, F, abundance at age. Second element is the vector of seeds used for self-test simulations.
Specify the age composition models for fleet(s) and indices.
set_age_comp(input, age_comp)
set_age_comp(input, age_comp)
input |
list containing data, parameters, map, and random elements (output from |
age_comp |
specifies the age composition models for fleet(s) and indices. If The age composition models available are:
Dirichlet, treating zero observations as missing. 1 parameter.
.
The two Dirichlet-multinomial options will only differ when input-sample-size differs among years. In these cases, the linear-Dirichlet multinomial is designed to decrease the effective sample size in each year by approximately the same proportion, while the saturating-Dirichlet multinomial will decrease the years with highest input-sample-size much more than those with lower input-sample-size.
One-step-ahead residuals will be calculated for all but options 8-10 when
|
a named list with same elements as the input provided with age composition likelihood options modified.
## Not run: wham.dir <- find.package("wham") path_to_examples <- system.file("extdata", package="wham") asap3 <- read_asap3_dat(file.path(path_to_examples,"ex1_SNEMAYT.dat")) input <- prepare_wham_input(asap3) input <- set_age_comp(input, age_comp = "logistic-normal-miss0") #no longer multinomial ## End(Not run)
## Not run: wham.dir <- find.package("wham") path_to_examples <- system.file("extdata", package="wham") asap3 <- read_asap3_dat(file.path(path_to_examples,"ex1_SNEMAYT.dat")) input <- prepare_wham_input(asap3) input <- set_age_comp(input, age_comp = "logistic-normal-miss0") #no longer multinomial ## End(Not run)
Specify catch selectivity blocks and aggregate and age composition observations for catch
set_catch(input, catch_info = NULL)
set_catch(input, catch_info = NULL)
input |
list containing data, parameters, map, and random elements (output from |
catch_info |
(optional) list specifying various aspects about catch by fleet (see details)
|
a named list with same elements as the input provided with catch observations and fleet options modified.
## Not run: wham.dir <- find.package("wham") path_to_examples <- system.file("extdata", package="wham") asap3 <- read_asap3_dat(file.path(path_to_examples,"ex1_SNEMAYT.dat")) input <- prepare_wham_input(asap3) input <- set_catch(input, catch_info = list(agg_catch = newcatch)) #constant catch of 500 mt ## End(Not run)
## Not run: wham.dir <- find.package("wham") path_to_examples <- system.file("extdata", package="wham") asap3 <- read_asap3_dat(file.path(path_to_examples,"ex1_SNEMAYT.dat")) input <- prepare_wham_input(asap3) input <- set_catch(input, catch_info = list(agg_catch = newcatch)) #constant catch of 500 mt ## End(Not run)
Specify configuration for environmental covariates, effects on the population, and parameter values
set_ecov(input, ecov)
set_ecov(input, ecov)
input |
list containing data, parameters, map, and random elements (output from |
ecov |
(optional) named list of environmental covariate data and parameters (see details)
|
a named list with same elements as the input provided with environmental covariate observations, effects, and model options modified.
## Not run: wham.dir <- find.package("wham") path_to_examples <- system.file("extdata", package="wham") asap3 <- read_asap3_dat(file.path(path_to_examples,"ex1_SNEMAYT.dat")) env.dat <- read.csv(file.path(path_to_examples,"GSI.csv"), header=T) input <- prepare_wham_input(asap3, NAA_re = list(sigma = "rec")) ecov <- list( label = "GSI", mean = as.matrix(env.dat$GSI), logsigma = 'est_1', # estimate obs sigma, 1 value shared across years year = env.dat$year, use_obs = matrix(1, ncol=1, nrow=dim(env.dat)[1]), # use all obs (=1) process_model = 'ar1') # "rw" or "ar1" input <- set_ecov(input, ecov = ecov) #GSI in the model without any effects ## End(Not run)
## Not run: wham.dir <- find.package("wham") path_to_examples <- system.file("extdata", package="wham") asap3 <- read_asap3_dat(file.path(path_to_examples,"ex1_SNEMAYT.dat")) env.dat <- read.csv(file.path(path_to_examples,"GSI.csv"), header=T) input <- prepare_wham_input(asap3, NAA_re = list(sigma = "rec")) ecov <- list( label = "GSI", mean = as.matrix(env.dat$GSI), logsigma = 'est_1', # estimate obs sigma, 1 value shared across years year = env.dat$year, use_obs = matrix(1, ncol=1, nrow=dim(env.dat)[1]), # use all obs (=1) process_model = 'ar1') # "rw" or "ar1" input <- set_ecov(input, ecov = ecov) #GSI in the model without any effects ## End(Not run)
Specify configuration for fully-selected fishing mortality
set_F(input, F_opts = NULL)
set_F(input, F_opts = NULL)
input |
list containing data, parameters, map, and random elements (output from |
F_opts |
(optional) named list of initial values for annual fully-selected fishing mortality and configuration method for estimation.
|
Specify index selectivity blocks and aggregate and age composition observations for indices
set_indices(input, index_info = NULL)
set_indices(input, index_info = NULL)
input |
list containing data, parameters, map, and random elements (output from |
index_info |
(optional) list specifying various aspects about catch by indices (see details)
|
Specify model and parameter configuration for "extra" mortality not directly attributed to natural mortality
set_L(input, L)
set_L(input, L)
input |
list containing data, parameters, map, and random elements (output from |
L |
(optional) list specifying "extra" mortality options: model, random effects, initial values, and parameters to fix (see details)
|
Specify model and parameter configuration for natural mortality
set_M(input, M)
set_M(input, M)
input |
list containing data, parameters, map, and random elements (output from |
M |
(optional) list specifying natural mortality options: model, random effects, initial values, and parameters to fix (see details)
|
a named list with same elements as the input provided with natural mortality options modified.
## Not run: wham.dir <- find.package("wham") path_to_examples <- system.file("extdata", package="wham") asap3 <- read_asap3_dat(file.path(path_to_examples,"ex1_SNEMAYT.dat")) input <- prepare_wham_input(asap3) M = list(mean_model = "estimate-M") input <- set_q(input, M = M) #estimate a constant M parameters ## End(Not run)
## Not run: wham.dir <- find.package("wham") path_to_examples <- system.file("extdata", package="wham") asap3 <- read_asap3_dat(file.path(path_to_examples,"ex1_SNEMAYT.dat")) input <- prepare_wham_input(asap3) M = list(mean_model = "estimate-M") input <- set_q(input, M = M) #estimate a constant M parameters ## End(Not run)
Specify model and parameter configuration for movement when input$data$n_regions > 1
set_move(input, move)
set_move(input, move)
input |
list containing data, parameters, map, and random elements (output from |
move |
(optional) list specifying movement options: model, random effects, initial values, and parameters to fix (see details)
|
Specify model and parameter configuration for numbers at age
set_NAA(input, NAA_re = NULL)
set_NAA(input, NAA_re = NULL)
input |
list containing data, parameters, map, and random elements (output from |
NAA_re |
(optional) list specifying options for numbers-at-age random effects, initial parameter values, and recruitment model (see details) If
|
a named list with same elements as the input provided with abundance modeling options modified.
## Not run: wham.dir <- find.package("wham") path_to_examples <- system.file("extdata", package="wham") asap3 <- read_asap3_dat(file.path(path_to_examples,"ex1_SNEMAYT.dat")) input <- prepare_wham_input(asap3) NAA = list(sigma = "rec") input <- set_q(input, NAA_re = NAA) #estimate recruitment as random effects ## End(Not run)
## Not run: wham.dir <- find.package("wham") path_to_examples <- system.file("extdata", package="wham") asap3 <- read_asap3_dat(file.path(path_to_examples,"ex1_SNEMAYT.dat")) input <- prepare_wham_input(asap3) NAA = list(sigma = "rec") input <- set_q(input, NAA_re = NAA) #estimate recruitment as random effects ## End(Not run)
Set up observation vector that is used by the model for likelihood calculations and one-step-ahead residuals.
set_osa_obs(input)
set_osa_obs(input)
input |
list containing data, parameters, map, and random elements (output from |
the same input list as provided, but with $obs and $obsvec configured. This is run after any changes have been made to the data
Specify model and parameter configuration for catchability
set_q(input, catchability = NULL)
set_q(input, catchability = NULL)
input |
list containing data, parameters, map, and random elements (output from |
catchability |
(optional) list specifying options for numbers-at-age random effects, initial parameter values, and recruitment model (see details)
|
a named list with same elements as the input provided with catchability options modified.
## Not run: wham.dir <- find.package("wham") path_to_examples <- system.file("extdata", package="wham") asap3 <- read_asap3_dat(file.path(path_to_examples,"ex1_SNEMAYT.dat")) input <- prepare_wham_input(asap3) catchability = list(re = c("iid", "none")) input <- set_q(input, catchability = catchability) #independent time-varying random effects on q for first survey. ## End(Not run)
## Not run: wham.dir <- find.package("wham") path_to_examples <- system.file("extdata", package="wham") asap3 <- read_asap3_dat(file.path(path_to_examples,"ex1_SNEMAYT.dat")) input <- prepare_wham_input(asap3) catchability = list(re = c("iid", "none")) input <- set_q(input, catchability = catchability) #independent time-varying random effects on q for first survey. ## End(Not run)
Specify model and parameter configuration for selectivity
set_selectivity(input, selectivity)
set_selectivity(input, selectivity)
input |
list containing data, parameters, map, and random elements (output from |
selectivity |
(optional) list specifying options for selectivity blocks, models, initial parameter values, parameter fixing/mapping, and random effects (see details)
|
a named list with same elements as the input provided with selectivity options modified.
## Not run: wham.dir <- find.package("wham") path_to_examples <- system.file("extdata", package="wham") asap3 <- read_asap3_dat(file.path(path_to_examples,"ex1_SNEMAYT.dat")) input <- prepare_wham_input(asap3, NAA_re = list(sigma = "rec")) sel <- list(model=rep("logistic",input$data$n_selblocks), initial_pars=rep(list(c(3,3)),input$data$n_selblocks), fix_pars=rep(list(NULL),input$data$n_selblocks)) input <- set_selectivity(input, selectivity = sel) #logistic selectivity for all selectivity blocks ## End(Not run)
## Not run: wham.dir <- find.package("wham") path_to_examples <- system.file("extdata", package="wham") asap3 <- read_asap3_dat(file.path(path_to_examples,"ex1_SNEMAYT.dat")) input <- prepare_wham_input(asap3, NAA_re = list(sigma = "rec")) sel <- list(model=rep("logistic",input$data$n_selblocks), initial_pars=rep(list(c(3,3)),input$data$n_selblocks), fix_pars=rep(list(NULL),input$data$n_selblocks)) input <- set_selectivity(input, selectivity = sel) #logistic selectivity for all selectivity blocks ## End(Not run)
Writes a set of HTML files with tabbed navigation between them. Called by
plot_wham_output
if ‘out.type = ’html'' (default). Opens main file in
default browser. Modified from ['r4ss::SS_html'](https://github.com/r4ss/r4ss/blob/master/R/SS_html.R).
wham_html(dir.main = NULL, title = "WHAM Output", width = 500, openfile = TRUE)
wham_html(dir.main = NULL, title = "WHAM Output", width = 500, openfile = TRUE)
dir.main |
directory to save html file ( |
title |
Title for HTML page. |
width |
Width of plots (in pixels). |
openfile |
Automatically open index.html in default browser? |
plot_wham_output
, 'r4ss::SS_html()'