| Title: | Tools to create and maintain gadget3 models |
|---|---|
| Description: | A collection of functions to aid (1) setting up and maintaining gadget3 models, (2) optimising, analysing, and running diagnostics on gadget3 models. |
| Authors: | William Butler [aut, cre] (ORCID: <https://orcid.org/0000-0002-3286-0748>), Bjarki Thor Elvarsson [aut] (ORCID: <https://orcid.org/0000-0001-5855-1188>), Jamie Lentin [aut] (ORCID: <https://orcid.org/0000-0001-5727-2996>), Mikko Vihtakari [aut] (ORCID: <https://orcid.org/0000-0003-0371-4319>), Marine and Freshwater Research Institute (Iceland) [cph] |
| Maintainer: | William Butler <[email protected]> |
| License: | GPL-3 |
| Version: | 0.0.0.9000 |
| Built: | 2026-12-02 09:35:13 UTC |
| Source: | https://github.com/gadget-framework/gadgetutils |
Adds gadget3 attributes and missing columns to a a data frame ready to be passed to gadget3. Useful for importing data manually to gadget without the mfdb step.
add_g3_attributes(x, params, warn = 1)add_g3_attributes(x, params, warn = 1)
x |
A data frame, tibble or data table. |
params |
A list of parameters defining the grouping. See details in |
warn |
Integer value to set the handling of warning messages. See the |
Returns x with g3 attributes and missing columns as instructed by the params argument.
This function combines multiple gadget.fit objects into a single fit object. An additional column 'id' is added to each element of the resulting list to identify the individual gadget.fits
bind_fit(fit_list)bind_fit(fit_list)
fit_list |
A list of multiple gadget.fit objects. |
The 'id' column will be taken from names(fit_list). If fit_list has no names, the 'id' column will be taken from the positions, e.g., fit_list = list(a = fit1, b = fit2) will be produces id's of 'a' and 'b', whereas fit_list = list(fit1, fit2) will produce id's of '1' and '2'
A gadget.fit object
This function extracts a specific element from multiple gadget.fit objects and combines them into a single dataframe. The output has an additional column 'id' that distinguishes each input gadget.fit object
bind_fit_components(fit_list, component)bind_fit_components(fit_list, component)
fit_list |
A list of multiple gadget.fit objects. |
component |
A string specifying which list element to extract (ie, see names(fit)) |
The 'id' column will be taken from names(fit_list). If fit_list has no names, the 'id' column will be taken from the positions, e.g., fit_list = list(a = fit1, b = fit2) will be produces id's of 'a' and 'b', whereas fit_list = list(fit1, fit2) will produce id's of '1' and '2'
A data frame that contains an 'id' column
check_params_out checks for NULLs and try-errors in a list of g3 parameters
check_params_out(param_list, id_name = NULL)check_params_out(param_list, id_name = NULL)
param_list |
List of g3 parameters |
id_name |
replacement name for 'id' in the output |
A data.frame that has collated the 'summary' attribute of each element of param_list.
Estimates the weights for gadget3 likelihood components using shortcut (ie not iterative re-weighting) methods
estimate_weights(model, params)estimate_weights(model, params)
model |
A gadget3 model of class 'g3_cpp' or 'g3_r' |
params |
A gadget3 parameter dataframe |
This function attempts to estimate the weights of gadget3 likelihood components. The shortcut weights are calculated by taking the inverse of the residual variance. How the residual variance is calculated depends on the type of likelihood distribution, i.e., whether it is a catch or abundance distribution. The residual variance calculations are performed by the helper functions 'estimate_weights_cdist' (catch distributions) and 'estimate_weights_adist' (abundance distributions)
This function fits a loess model to abundance data and returns the residual variance of the model fit
estimate_weights_adist(dat)estimate_weights_adist(dat)
dat |
Abundance distribution model report (as a dataframe) |
Calculates the residual variance for catch distributions using a GLM
estimate_weights_cdist(dat)estimate_weights_cdist(dat)
dat |
Catch distribution model report (as a dataframe) |
Convert normalised bounded form back to value
eval_bounded(x, lower, upper)eval_bounded(x, lower, upper)
x |
Input normalised value |
lower |
Lower bound for x |
upper |
Upper bound for x |
Raw value for x without bounding
Gadget3 reports have a time column in the format 'YEAR-STEP'. This function creates a 'year' and 'step' column by splitting the existing 'time' column. This is useful for processing gagdet3 reports.
extract_year_step(data)extract_year_step(data)
data |
dataframe of gadget3 reports. Must include a 'time' column. |
Added parscale to a parameter template. No longer needed.
g3_add_parscale(parameters)g3_add_parscale(parameters)
parameters |
A gadget3 parameter dataframe |
Aggregates data from a data frame ready to be passed to gadget3. Useful for generating datasets for g3l_catchdistribution, g3l_abundancedistribution and g3_timeareadata. Imitates the behavior of mfdb_sample_* functions and returns the required object attributes as instructed by the params argument.
g3_data( x, params = list(), method = "count", column_names = c(year = "year", step = "month", area = "areacell"), floating_point_correction = TRUE, verbose = FALSE )g3_data( x, params = list(), method = "count", column_names = c(year = "year", step = "month", area = "areacell"), floating_point_correction = TRUE, verbose = FALSE )
x |
A data frame, tibble or data table |
params |
A list of parameters defining the grouping. See details in |
method |
A character defining the aggregation method: use |
column_names |
A named vector explaining the column names which gadget3 expects in |
floating_point_correction |
Logical indicating whether 1e-6 should be added to all numeric columns except for |
verbose |
Logical indicating whether the function should return messages about potential assumptions when expected data are not specified. |
This function attempts to do the same than mfdb_sample_* functions: summarise data ready for gadget3, with the difference that this function uses dataframes instead of a SQL database as input data. Consequently, this function should be independent of mfdb if the functions that generate groups and intervals as the mfdb package (mfdb_interval, mfdb_group) were imported to a project with this function.
Importantly, g3_data() does not attempt to filter other data than length unlike mfdb_sample_* functions that filter all columns passed to params.
Build output summary suitable for feeding into gadgetplots
g3_fit( model, params, rec.steps = 1, steps = 1, printatstart = 1, f_by_age = NULL )g3_fit( model, params, rec.steps = 1, steps = 1, printatstart = 1, f_by_age = NULL )
model |
A G3 model built using |
params |
The fitted parameters post-optimisation |
rec.steps |
Which steps should be considered recruitment steps? Vector of int, or NULL for all steps. |
steps |
Which steps to include in the annual output? Vector of int. |
printatstart |
Should the stock standard be printed at the start of the timestep (1) or the end (0) |
f_by_age |
The age range over which the annual fishing mortality (F) in
F is NA for stocks with no ages within the range. |
The fishing mortality (F) in f.by.year and res.by.year is calculated separately for each
stock and area. F in a step is , where is the number caught by fleets and is
the number at the beginning of the step. F at age is summed over the steps of the year, and averaged (unweighted)
over the ages in f_by_age. By default, F is that of the oldest age of each stock only.
List of tibbles
Set initial guesses for parameter values in g3_cpp parameter template
g3_init_guess( params, pattern, value = 0, lower = -999, upper = 999, optimise = 0 )g3_init_guess( params, pattern, value = 0, lower = -999, upper = 999, optimise = 0 )
params |
Parameter template from g3_to_tmb() |
pattern |
Regular expression of parameter names in template to change |
value |
Initial value for all parameters matching pattern |
lower |
Lower bound to set for all parameters matching pattern |
upper |
Upper bound to set for all parameters matching pattern |
optimise |
1 if parameters matching pattern should be optimised, zero otherwise. |
Updated parameter template
Perform multiple optimisation runs of a model, reweighting with each run
g3_iterative( gd, wgts = "WGTS", model, params.in, grouping = g3_iterative_default_grouping(params.in), use_parscale = TRUE, method = "BFGS", control = list(), shortcut = FALSE, cv_floor = 0, resume_final = FALSE, serial_compile = FALSE, mc.cores = parallel::detectCores() ) g3_iterative_default_grouping( params.in, nll_dist_names = c("ldist", "aldist", "matp", "sexdist", "SI", "len\\d+SI") )g3_iterative( gd, wgts = "WGTS", model, params.in, grouping = g3_iterative_default_grouping(params.in), use_parscale = TRUE, method = "BFGS", control = list(), shortcut = FALSE, cv_floor = 0, resume_final = FALSE, serial_compile = FALSE, mc.cores = parallel::detectCores() ) g3_iterative_default_grouping( params.in, nll_dist_names = c("ldist", "aldist", "matp", "sexdist", "SI", "len\\d+SI") )
gd |
Directory to store output |
wgts |
Directory name within gd to store run outputs |
model |
A G3 model, produced by g3_to_r() or g3_tmb_adfun() |
params.in |
Initial parameters to use with the model |
grouping |
List of component names to optmise together |
use_parscale |
Logical indicating whether optim(control$parscale) should be used |
method |
The optimisation method, see |
control |
List of control options for optim, see |
shortcut |
If TRUE, weights for each component will be approximated and a final optimisation performed |
cv_floor |
Minimum value of survey components (adist_surveyindices) as 1/ |
resume_final |
Logical value. If TRUE the re-weighting procedure starts at the second stage. |
serial_compile |
g3_tmb_adfun will be run in serial mode (i.e., not in parallel), potentially helping with memory issues |
mc.cores |
number of cores used, defaults to the number of available cores |
nll_dist_names |
Character vector of postfixes to consider when looking for groupings |
An implementation of the iterative reweigthing of likelihood components in gadget. It analyzes a given gadget model and, after a series of optimisations where each likelihood component is heavily weigthed, suggests a weigthing for the components based on the respective variance. If one (or more) components, other than understocking and penalty, are 0 then the gadget optimisation with the final weights will not be completed.
In Taylor et. al an objective reweighting scheme for likelihood components is described for cod in Icelandic waters. The authors nota that the issue of component weighting has been discussed for some time, as the data sources have different natural scales (e.g g vs. kg) that should not affect the outcome. A simple heuristic, where the weights are the inverse of the initial sums of squares for the respective component resulting in an initials score equal to the number of components, is therfor often used. This has the intutitive advantage of all components being normalised. There is however a drawback to this since the component scores, given the initial parametrisation, are most likely not equally far from their respective optima resulting in sub-optimal weighting. The iterative reweighting heuristic tackles this problem by optimising each component separately in order to determine the lowest possible value for each component. This is then used to determine the final weights. The resoning for this approach is as follows: Conceptually the likelihood components can be thought of as residual sums of squares, and as such their variance can be esimated by dividing the SS by the degrees of freedom. The optimal weighting strategy is the inverse of the variance. Here the iteration starts with assigning the inverse SS as the initial weight, that is the initial score of each component when multiplied with the weight is 1. Then an optimisation run for each component with the intial score for that component set to 10000. After the optimisation run the inverse of the resulting SS is multiplied by the effective number of datapoints and used as the final weight for that particular component. The effective number of datapoints is used as a proxy for the degrees of freedom is determined from the number of non-zero datapoints. This is viewed as satisfactory proxy when the dataset is large, but for smaller datasets this could be a gross overestimate. In particular, if the surveyindices are weigthed on their own while the yearly recruitment is esimated they could be overfitted. If there are two surveys within the year Taylor et. al suggest that the corresponding indices from each survey are weigthed simultaneously in order to make sure that there are at least two measurement for each yearly recruit, this is done through component grouping which is implemented.
Component grouping is oftern applied in cases where overfitting is likely, and this can also happen with catch composition data as well as survey indices.
In addition to grouping, a maximum weight can be assigned survey indices vie the cv_floor setting. The cv_floor parameter sets the minimum of the estimated component variance and thus the maximum of the inverser variance.
Weights are calculated using inverse-variance weighting (), and as 1/pmax(variance, cv_floor), hence the minimum value for survey components is 1/cv_floor. Use smaller cv_floor values to increase the weight of survey components.
This assumes that your likelihood component names are of the form (nll_group)_(nll_dist),
where (nll_dist) matches one of the regexes in nll_dist_names.
For example, afleet_ldist, afleet_aldist, bfleet_ldist. afleet & bfleet will be the groups used.
Final set of parameters
A list of component groups to component names, as required by the grouping parameter
Initial parameters for iterative re-weighting
g3_iterative_setup(lik_out, grouping = list())g3_iterative_setup(lik_out, grouping = list())
lik_out |
A likelihood summary dataframe. The output of g3_lik_out(model, param) |
grouping |
A list describing how to group likelihood components for iterative re-weighting |
Initial weights are calculated by taking the inverse SS and then multiplying these by 10000 for the components that are to be optimised
A list of G3 parameter dataframes, one for each group of likelihood components
g3_jitter performs a jitter analysis.
g3_jitter( gd, outdir = "JITTER", model, params, njits = 10, jitter_fraction = 0.1, pattern_to_ignore = NULL, within_bounds = TRUE, use_parscale = TRUE, method = "BFGS", control = list(), serial_compile = FALSE, mc.cores = parallel::detectCores() )g3_jitter( gd, outdir = "JITTER", model, params, njits = 10, jitter_fraction = 0.1, pattern_to_ignore = NULL, within_bounds = TRUE, use_parscale = TRUE, method = "BFGS", control = list(), serial_compile = FALSE, mc.cores = parallel::detectCores() )
gd |
Directory to store output |
outdir |
Directory name within gd to store run outputs |
model |
A G3 model, produced by g3_to_tmb() or g3_to_r() |
params |
Initial parameters to use with the model, this should be a TMB parameter template i.e. attr(tmb_model, 'parameter_template') |
njits |
Number of jitters to run, defaults to 10 |
jitter_fraction |
The fraction of jittering for a value |
pattern_to_ignore |
Regular expression of parameters to avoid jittering |
within_bounds |
Logical, if TRUE, jittered values that fall outside parameter bounds (params$lower, params$upper) will be adjusted to fall within the bounds |
use_parscale |
Logical indicating whether optim(control$parscale) should be used |
method |
The optimisation method, see |
control |
List of control options for optim, see |
serial_compile |
g3_tmb_adfun will be run in serial mode (i.e., not in parallel), potentially helping with memory issues |
mc.cores |
The number of cores to use, defaults to the number available |
A list of optimised parameter data frames (one for each jitter)
Perform a leave-one-out analysis. This involves running a set of optimisations, each one of which has a component (or set of components) turned off (i.e. weight = 0).
g3_leaveout( gd, outdir = "LOCV", model, params, grouping = list(), use_parscale = TRUE, method = "BFGS", control = list(), serial_compile = FALSE, mc.cores = parallel::detectCores() )g3_leaveout( gd, outdir = "LOCV", model, params, grouping = list(), use_parscale = TRUE, method = "BFGS", control = list(), serial_compile = FALSE, mc.cores = parallel::detectCores() )
gd |
Directory to store output |
outdir |
Directory name within gd to store run outputs |
model |
A G3 model, produced by g3_to_tmb() or g3_to_r() |
params |
Initial parameters to use with the model, this should be a TMB parameter template i.e. attr(tmb_model, 'parameter_template') |
grouping |
List of component names to group together. This allows you to leave out multiple components at a time, e.g. length and age-length distributions from a particular fleet |
use_parscale |
Logical indicating whether optim(control$parscale) should be used |
method |
The optimisation method, see |
control |
List of control options for optim, see |
serial_compile |
g3_tmb_adfun will be run in serial mode (i.e., not in parallel), potentially helping with memory issues |
mc.cores |
The number of cores to use, defaults to the number available |
g3_leaveout performs a leave-one-out analysis.
A list of optimised parameter data frames (one for each group)
Likelihood summary for a model run
g3_lik_out(model, param)g3_lik_out(model, param)
model |
A G3 model, produced by g3_to_r() or g3_tmb_adfun() |
param |
A G3 parameter dataframe |
Runs the model, sums the number of data points (df) and nll's for each component (value), and extracts the corresponding weights from the input parameters (weight)
A dataframe containing the likelihood component name, degrees of freedom, NLL value, and weight
Wrapper for stats::optim that returns the g3_cpp parameter template with optimised values
g3_optim( model, params, use_parscale = TRUE, method = "BFGS", control = list(), print_status = FALSE, print_id = "g3_optim", check_finite = TRUE, ... )g3_optim( model, params, use_parscale = TRUE, method = "BFGS", control = list(), print_status = FALSE, print_id = "g3_optim", check_finite = TRUE, ... )
model |
Either a g3 model of class 'g3_cpp', i.e., model <- gadget3::g3_to_tmb(actions), or an objective function from gadget3::g3_tmb_adfun(model, param) |
params |
The parameter template for a g3_cpp classed model. |
use_parscale |
Should parscale be used g3_tmb_parscale(params), see |
method |
The optimisation method, see |
control |
List of control options for optim, see |
print_status |
Print step comments, does not suppress comments from optim call (see control$trace) |
print_id |
A character string appended to the print statements (useful for when running g3_optim in parallel) |
check_finite |
boolean Should we check that initial/final conditions produce finite results before running? |
... |
Further arguments to be passed gadget3::g3_tmb_adfun, see |
A g3_cpp parameter template with optimised values
g3_retro runs an analytical retrospective model fitting run.
g3_retro( gd, outdir = "RETRO", model, params, nyears = 5, use_parscale = TRUE, method = "BFGS", control = list(), serial_compile = FALSE, mc.cores = parallel::detectCores() )g3_retro( gd, outdir = "RETRO", model, params, nyears = 5, use_parscale = TRUE, method = "BFGS", control = list(), serial_compile = FALSE, mc.cores = parallel::detectCores() )
gd |
Directory to store output |
outdir |
Directory name within gd to store run outputs |
model |
A G3 model, produced by g3_to_r() or g3_tmb_adfun() |
params |
Initial parameters to use with the model, this should be a TMB parameter template i.e. attr(tmb_model, 'parameter_template') |
nyears |
How many years back to go |
use_parscale |
Logical indicating whether optim(control$parscale) should be used |
method |
The optimisation method, see |
control |
List of control options for optim, see |
serial_compile |
g3_tmb_adfun will be run in serial mode (i.e., not in parallel), potentially helping with memory issues |
mc.cores |
The number of cores to use, defaults to the number available |
List optimised TMB parameter data.frames, the name of each list element corresponds to the number of years peeled in the retrospective analysis.
g3_sensitivity performs a sensitivity analysis for a single parameter.
g3_sensitivity( gd, outdir = "SENS", model, params, par_name, par_values, use_parscale = TRUE, method = "BFGS", control = list(), serial_compile = FALSE, return_input_parameters = FALSE, run_optimisations = TRUE, mc.cores = parallel::detectCores() )g3_sensitivity( gd, outdir = "SENS", model, params, par_name, par_values, use_parscale = TRUE, method = "BFGS", control = list(), serial_compile = FALSE, return_input_parameters = FALSE, run_optimisations = TRUE, mc.cores = parallel::detectCores() )
gd |
Directory to store output |
outdir |
Directory name within gd to store run outputs |
model |
A G3 model, produced by g3_to_tmb() or g3_to_r() |
params |
Initial parameters to use with the model, this should be a TMB parameter template i.e. attr(tmb_model, 'parameter_template') |
par_name |
A glob-like string to match parameter names, see the 'name_spec' argument for |
par_values |
A vector of values to substitute into params |
use_parscale |
Logical indicating whether optim(control$parscale) should be used |
method |
The optimisation method, see |
control |
List of control options for optim, see |
serial_compile |
g3_tmb_adfun will be run in serial mode (i.e., not in parallel), potentially helping with memory issues |
return_input_parameters |
If TRUE, returns a list of modified parameter dataframes (i.e. without optimisations) |
run_optimisations |
If TRUE, will return a list of fits using the modified (non-optimised) parameters |
mc.cores |
The number of cores to use, defaults to the number available |
A list of parameter dataframes (either optimised or not) or a list of fits based on the unoptimised parameters
Extract parts from stock name
g3_stock_name(stock, id = "full")g3_stock_name(stock, id = "full")
stock |
A g3 stock object |
id |
Part to extract, or 'full' to return the stock name |
Part from stock name
Updates weights for second stage of iterative re-weighting
g3_update_weights(lik_out_list, grouping, cv_floor)g3_update_weights(lik_out_list, grouping, cv_floor)
lik_out_list |
A list of likelihood summarys. The output of g3_lik_out(model, param) for each group of likelihood components |
grouping |
A list describing how to group likelihood components for iterative re-weighting |
cv_floor |
Minimum value of survey components (adist_surveyindices) as 1/ |
This function updates weights for the second stage of iterative re-weighting. If the cv_floor is > 0, it will be applied here.
A list of G3 parameter dataframes, one for each group of likelihood components
Generate parameterised g3a_initial_abund
init_abund( imm, mat, comp_id = "species", mature = TRUE, init_mode = 1, exp_init = FALSE, exp_init_scalar = FALSE, exp_init_f = FALSE, naturalmortality = gadget3::g3_parameterized("M", by_stock = TRUE) )init_abund( imm, mat, comp_id = "species", mature = TRUE, init_mode = 1, exp_init = FALSE, exp_init_scalar = FALSE, exp_init_f = FALSE, naturalmortality = gadget3::g3_parameterized("M", by_stock = TRUE) )
imm |
A g3 stock object for immature specimens |
mat |
A g3 stock object for mature specimens |
comp_id |
Part of stock name to use for parameters, e.g. 'species' will share parameters with both mature/immature |
mature |
Generate actions for mature (TRUE) or immature (FALSE) stock |
init_mode |
One of: 0 (A single scalar that decays with mortality), 1 (Initial parameter per age group (across stocks)), 2 (Initial parameter per age group per stock), 3 (Initialised at equilibrium, special case for cetaceans, see https://gadget-framework.github.io/gadget-course/marine-mammals.html) |
exp_init |
Logical, whether the initial age-specific parameters should be exponentiated |
exp_init_scalar |
Logical, whether the initial scalar should be exponentiated |
exp_init_f |
Logical, whether the parameter 'init.f' should be exponentiated |
naturalmortality |
A g3 parameter for natural mortality |
g3a_initial_abund formula for use in g3a_initialconditions_normalparam()
Generate parameterised initial conditions
init_sd(stock, id, parametric = FALSE, mean_len)init_sd(stock, id, parametric = FALSE, mean_len)
stock |
A g3 stock object |
id |
Part of the stock name to use in parameter name |
parametric |
Is the initial conditions stddev parameterised, or a table by age? |
mean_len |
The mean length function (only relevant if parametric = TRUE) |
A formula suitable for g3a_initialconditions_normalparam()
Creates a jittered g3_tmb parameter template
jitter_params( params, jitter_fraction = 0.1, pattern_to_ignore = NULL, within_bounds = TRUE )jitter_params( params, jitter_fraction = 0.1, pattern_to_ignore = NULL, within_bounds = TRUE )
params |
A g3 tmb parameter template |
jitter_fraction |
The fraction of jittering for a value |
pattern_to_ignore |
Regular expression of parameters to avoid jittering |
within_bounds |
Logical, if TRUE, jittered values that fall outside parameter bounds (params$lower, params$upper) will be adjusted to fall within the bounds |
Jittered set of parameters
Generate a standard set of model actions
model_actions( imm, mat, mlgg = 15, mature = TRUE, comp_id = "species", rec_id = list(imm, mat), rec_scalar_id = list(imm, mat), init_mode = 1, parametric_sd = FALSE, exp_params = c(), tv_params = c(), by_age_params = c(), recruiting = !mature )model_actions( imm, mat, mlgg = 15, mature = TRUE, comp_id = "species", rec_id = list(imm, mat), rec_scalar_id = list(imm, mat), init_mode = 1, parametric_sd = FALSE, exp_params = c(), tv_params = c(), by_age_params = c(), recruiting = !mature )
imm |
A g3 stock object for immature specimens |
mat |
A g3 stock object for mature specimens |
mlgg |
maxlengthgroupgrowth for growth of both mature/immature |
mature |
Generate actions for mature (TRUE) or immature (FALSE) stock |
comp_id |
Part of stock name to use for parameters, e.g. 'species' will share parameters with both mature/immature |
rec_id |
Part of stock name to use for recruitment parameters, e.g. 'species' will share parameters with both mature/immature |
rec_scalar_id |
Part of stock name to use for recruitment scalar parameter, e.g. 'species' will share parameters with both mature/immature |
init_mode |
One of 0 (initialised at equilibrium), 1 (Initial parameter per age group (across stocks)), 2 (Initial parameter per age group per stock) |
parametric_sd |
Is the initial conditions stddev parameterised, or a table by age? |
exp_params |
Which parameters should be exponentiated? exp_params is a vector of parameter names, possible parameters include: c('linf','k','bbin','recl','rec.sd','mat_alpha','mat_l50','init','init.scalar','rec','rec.scalar','init.f','m','walpha','wbeta'). Note that is a scalar is exponentiated the annual values will be too, and vice versa. |
tv_params |
Which parameters should be time-varying? tv_params is a vector of parameter names, possible time-varying parameters include: 'linf','k','walpha','beta','bbin','recl','rec.sd','mat_alpha','mat_l50','m' |
by_age_params |
Which parameters should be age-varying? by_age_params is a vector of parameter names, possible time-varying parameters include: 'linf','k','walpha','beta','bbin','mat_alpha','mat_l50','m' |
recruiting |
If TRUE, the renewal action will be added. Defaults to !mature, so it can be used to create a single non-maturing stock. |
A list of g3 actions
Generate parameterised g3a_initial_abund
mohnrho( fit, retrofit, vars = c("total.biomass", "F", "recruitment"), lag = c(0, 1, 1), aggregate_biomass = TRUE )mohnrho( fit, retrofit, vars = c("total.biomass", "F", "recruitment"), lag = c(0, 1, 1), aggregate_biomass = TRUE )
fit |
A g3_fit object |
retrofit |
A list of g3_fit objects that differ in their terminal year, i.e. the result of a retrospective analysis |
vars |
Which variables would you like to calculate Mohn's Rho for? They must be columns in fit$res.by.year |
lag |
vector of lags for each variable in terms of years |
aggregate_biomass |
calculate rho for biomass over stocks? Only works if 'total.biomass' is in vars |
A data.frame with mohn's rho for each variable by stock
Reads a file from write.g3.file to an object. Now depreciated, using RData files for read/write.
read.g3.param(gd, file.name)read.g3.param(gd, file.name)
gd |
Directory to write the file |
file.name |
Name of the file |
Wrapper for g3_optim. This is an internal function used by the g3_* functions
run_g3_optim( model, params, use_parscale, method, control, serial_compile, mc.cores, ... )run_g3_optim( model, params, use_parscale, method, control, serial_compile, mc.cores, ... )
model |
Either a g3 model of class 'g3_cpp', i.e., model <- gadget3::g3_to_tmb(actions), or an objective function from gadget3::g3_tmb_adfun(model, param) |
params |
A list of parameter templates for a g3_cpp classed model. |
use_parscale |
Should parscale be used g3_tmb_parscale(params), see |
method |
The optimisation method, see |
control |
List of control options for optim, see |
serial_compile |
g3_tmb_adfun will be run in serial mode (i.e., not in parallel), potentially helping with memory issues |
mc.cores |
number of cores used, defaults to the number of available cores |
... |
Further arguments to be passed gadget3::g3_tmb_adfun, see |
A g3_cpp parameter template with optimised values
Generate paramerterised stock renewal factor
stock_renewal( stock, id = "species", scalar_id = "species", exponentiate_rec = FALSE, exponentiate_rec_scalar = FALSE )stock_renewal( stock, id = "species", scalar_id = "species", exponentiate_rec = FALSE, exponentiate_rec_scalar = FALSE )
stock |
A g3 stock object |
id |
Part of the stock name to use in parameter name |
scalar_id |
Part of the stock name to use in parameter name |
exponentiate_rec |
Should the annual renewal parameters be exponentiated? |
exponentiate_rec_scalar |
Should the renewal scalar be exponentiated? |
"scalar * renew" formula, parameterised for given stock
Extract species name from stock
stock_species(stock)stock_species(stock)
stock |
A g3 stock object |
Species name from stock
Calculates likelihood component scores, including scores normalised by the minimum value
tabulate_SS(lik_out, grouping)tabulate_SS(lik_out, grouping)
lik_out |
Likelihood summary for a model run. Output of g3_lik_out(model, param) |
grouping |
A list describing how to group likelihood components for iterative re-weighting |
A list with a table of likelihood component scores (SS) and a table of normalised likelihood component scores (SS_norm)
Convert value into it's normalised form for use with bounded()
value_from_bounds(x, lower, upper)value_from_bounds(x, lower, upper)
x |
Raw value |
lower |
Lower bound for x |
upper |
Upper bound for x |
Normalised value for use with bounded()
Writes an object to a file, typically just used within gadgetutils g3_ functions
write.g3.file(obj, gd, file_name)write.g3.file(obj, gd, file_name)
obj |
An object to write to file |
gd |
Directory to write the file |
file_name |
Name of the file |
A wrapper for write.g3.file that formats a gadget3 TMB parameter data.frame for writing to file
write.g3.param(params, gd, file_name)write.g3.param(params, gd, file_name)
params |
A TMB parameter data.frame |
gd |
Directory to write the file |
file_name |
Name of the file |