Package: gadget3 0.15-1-999

Jamie Lentin

gadget3: Globally-Applicable Area Disaggregated General Ecosystem Toolbox V3

A framework to assist creation of marine ecosystem models, generating either 'R' or 'C++' code which can then be optimised using the 'TMB' package and standard 'R' tools. Principally designed to reproduce gadget2 models in 'TMB', but can be extended beyond gadget2's capabilities. Kasper Kristensen, Anders Nielsen, Casper W. Berg, Hans Skaug, Bradley M. Bell (2016) <doi:10.18637/jss.v070.i05> "TMB: Automatic Differentiation and Laplace Approximation.". Begley, J., & Howell, D. (2004) <doi:10.17895/ices.pub.25349308> "An overview of Gadget, the globally applicable area-disaggregated general ecosystem toolbox. ICES.".

Authors:Jamie Lentin [aut, cre], Bjarki Thor Elvarsson [aut], William Butler [aut], Marine and Freshwater Research Institute [cph]

gadget3_0.15-1-999.tar.gz
gadget3_0.15-1-999.zip(r-4.7)gadget3_0.15-1-999.zip(r-4.6)gadget3_0.15-1-999.zip(r-4.5)
gadget3_0.15-1-999.tgz(r-4.6-any)gadget3_0.15-1-999.tgz(r-4.5-any)
gadget3_0.15-1-999.tar.gz(r-4.7-any)gadget3_0.15-1-999.tar.gz(r-4.6-any)
gadget3_0.15-1-999.tgz(r-4.6-emscripten)
manual.pdf |manual.html
DESCRIPTION |NEWS
card.svg |card.png
gadget3/json (API)

# Install 'gadget3' in R:
install.packages('gadget3', repos = c('https://gadget-framework.r-universe.dev', 'https://cloud.r-project.org'))

Bug tracker:https://github.com/gadget-framework/gadget3/issues

Pkgdown/docs site:https://gadget-framework.github.io

On CRAN:

Conda:

8.31 score 9 stars 136 scripts 594 downloads 129 exports 7 dependencies

Last updated from:5843b2f341. Checks:9 OK. Indexed: yes.

TargetResultTimeFilesSyslog
linux-devel-x86_64OK255
source / vignettesOK278
linux-release-x86_64OK252
macos-release-arm64OK216
macos-oldrel-arm64OK318
windows-develOK234
windows-releaseOK238
windows-oldrelOK247
wasm-releaseOK106

Exports:g3_action_orderg3_areasg3_array_aggg3_array_combineg3_array_plotg3_distribution_previewg3_envg3_evalg3_fleetg3_formulag3_global_formulag3_init_valg3_is_stockg3_nativeg3_param_projectg3_param_project_ar1g3_param_project_dlnormg3_param_project_dnormg3_param_project_logar1g3_param_project_rwalkg3_parameterizedg3_quotag3_quota_assessg3_quota_hockeyfleetg3_quota_hockeystickg3_stepg3_stockg3_stock_defg3_stock_instanceg3_suitability_anderseng3_suitability_andersenfleetg3_suitability_constantg3_suitability_exponentialg3_suitability_exponentiall50g3_suitability_gammag3_suitability_richardsg3_suitability_straightlineg3_timeareadatag3_timevariableg3_tmb_adfung3_tmb_fng3_tmb_lowerg3_tmb_parg3_tmb_parscaleg3_tmb_relistg3_tmb_upperg3_to_descg3_to_rg3_to_tmbg3a_ageg3a_grow_impl_bbinomg3a_grow_length_multspecg3a_grow_length_weightjonesg3a_grow_lengthvbsimpleg3a_grow_weight_multspecg3a_grow_weight_weightjonesg3a_grow_weightsimpleg3a_growmatureg3a_initialconditions_normalcvg3a_initialconditions_normalparamg3a_matureg3a_mature_constantg3a_mature_continuousg3a_migrateg3a_migrate_normalizeg3a_naturalmortalityg3a_naturalmortality_expg3a_otherfoodg3a_otherfood_normalcvg3a_otherfood_normalparamg3a_predateg3a_predate_catchability_effortfleetg3a_predate_catchability_linearfleetg3a_predate_catchability_numberfleetg3a_predate_catchability_predatorg3a_predate_catchability_projectg3a_predate_catchability_quotafleetg3a_predate_catchability_totalfleetg3a_predate_fleetg3a_predate_maxconsumptiong3a_predate_tagreleaseg3a_predate_totalfleetg3a_renewal_initabundg3a_renewal_normalcvg3a_renewal_normalparamg3a_renewal_vonbg3a_renewal_vonb_reclg3a_renewal_vonb_t0g3a_report_detailg3a_report_historyg3a_report_stockg3a_spawng3a_spawn_recruitment_bevertonholtg3a_spawn_recruitment_bevertonholt_ss3g3a_spawn_recruitment_fecundityg3a_spawn_recruitment_hockeystickg3a_spawn_recruitment_rickerg3a_spawn_recruitment_simplessbg3a_spmodelg3a_spmodel_logisticg3a_tag_sheddingg3a_timeg3a_trace_timingsg3a_trace_varg3a_weightlossg3l_abundancedistributiong3l_bounds_penaltyg3l_catchdistributiong3l_distribution_multinomialg3l_distribution_multivariateg3l_distribution_sumofsquaredlogratiosg3l_distribution_sumofsquaresg3l_distribution_surveyindices_linearg3l_distribution_surveyindices_logg3l_random_dnormg3l_random_walkg3l_sparsesampleg3l_sparsesample_linregg3l_sparsesample_sumsquaresg3l_tagging_ckmrg3l_understockingg3s_ageg3s_agegroupg3s_areagroupg3s_cloneg3s_livesonareasg3s_tagg3s_timeg3s_time_convert

Dependencies:digestlatticeMatrixRcppRcppEigenrlangTMB

Introduction to gadget3: A single stock model
Creating a (single species) model | Actions | Create time definitions | Stocks | Create stock definition for fish | Stock actions | Fleet actions | Landings data | Landings data: For each year/step/area | Length distribution data | Aggregate .raw data | Group into length bins | Report count in each length bin | Save into ldist_f_surv | Age-length distribution data | Fleet definition | Survey indices | Generate random data | fish.init.scalar & fish.rec.scalar: Overall scalar for recruitment/initial conditions, see g3a_renewal_normalcv() | fish.rec.(age): Per-age recriutment scalar, see g3a_renewal_normalcv() | fish.rec.(year): Recruitment level year-on-year, see g3a_renewal_normalcv() | init.F: Offset for initial M, see g3a_renewal_initabund() | fish.M.(age): per-age M for our species, see g3a_naturalmortality() | fish.Linf, fish.K, fish.t0: VonB parameters for our species, see g3a_renewal_vonb_t0(), g3a_grow_lengthvbsimple() | fish.walpha, fish.wbeta: Age/weight relationship for initialconditions, renewal, see g3a_renewal_normalcv() | fish.f_surv.alpha, fish.f_surv.l50: Curve/l50 for fishing suitability, see g3_suitability_exponentiall50() | fish.bbin: Beta for beta-binomial distribution for fish growth, see g3a_grow_impl_bbinom() | identity() is a do-nothing function, but it lets us finish on a new line | Appendix: Full model script

Last update: 2025-09-18
Started: 2024-01-26

Debugging a gadget3 model
Viewing & editing model code | NaN in likelihood / reports | "Error in optim(...): initial value in 'vmmin' is not finite" | Increasing objective function verbosity | TMB model crashes your R session | Interactive debugging of TMB models | Random effects | Tracing inner model | Logging messages | Missing value for m | Missing value par - parold | Separate netwton optimisation

Last update: 2025-08-28
Started: 2021-02-18

Modelling maturity & sex with multiple stocks
Stocks | Fleet actions | Landings data: For each year/step/area | Length distribution data: Generate 1000 random samples in each year/step/area | Generate random lengths for these samples | Save unagggregated data into ldist_f_surv.raw | Aggregate .raw data | Group into length bins | Report count in each length bin | Save into ldist_f_surv | Assume 100 * 100 samples in each year/step/area | Generate random whole numbers for age | Group into length/age bins | Map maturity stage data to stocks | Generate random maturity stage data from age data, our stock matures between 3..5 | Map maturity stage to the stock name: Note we don't have to use the full stock name | Remove redundant columns | Survey indices | Generate random data | Treat maturity alpha/l50 separately | Appendix: Full model script

Last update: 2025-05-30
Started: 2024-01-26

Incorporating observation data into models
length column: Length distribution data | age column: Age-Length distribution data | area column | stock column: Maturity stage distribution | fleet column | predator column

Last update: 2025-04-14
Started: 2024-01-26

Structure of a gadget3 model
R formula, or the tilde operator | Actions | Stocks | Model parameterization | Combining actions | Ordering of actions

Last update: 2025-04-14
Started: 2024-01-26

Writing G3 Actions
G3 Functions | G3 global environment | Global & native functions | Under R | Under TMB: g3_native | Stock steps | Writing R code destined for C++ | Sub-formulas and g3_global_formula | Ancillary steps

Last update: 2025-04-14
Started: 2020-10-08

Model customisation

Last update: 2024-01-26
Started: 2024-01-26

Readme and manuals

Help Manual

Help pageTopics
Gadget3 language utilitiesg3_global_formula g3_native
Gadget3 global environmentADREPORT as.numeric assert_msg as_integer avoid_zero avoid_zero_vec bounded bounded_vec g3_env g3_matrix_vec lgamma_vec logspace_add nonconform_add nonconform_div nonconform_divavz nonconform_mult normalize_vec nvl print_array ratio_add_pop REPORT REprintf Rprintf
Gadget3 age actiong3a_age
Gadget3 growth actiong3a_growmature g3a_grow_impl_bbinom g3a_grow_lengthvbsimple g3a_grow_length_multspec g3a_grow_length_weightjones g3a_grow_weightsimple g3a_grow_weight_multspec g3a_grow_weight_weightjones
Gadget3 maturity actiong3a_mature g3a_mature_constant g3a_mature_continuous
Gadget3 migration actiong3a_migrate g3a_migrate_normalize
Gadget3 natural mortality actiong3a_naturalmortality g3a_naturalmortality_exp
Standard gadget3 order of actionsg3_action_order
Gadget3 predation actionsg3a_predate g3a_predate_catchability_effortfleet g3a_predate_catchability_linearfleet g3a_predate_catchability_numberfleet g3a_predate_catchability_predator g3a_predate_catchability_project g3a_predate_catchability_quotafleet g3a_predate_catchability_totalfleet g3a_predate_fleet g3a_predate_maxconsumption g3a_predate_totalfleet
Gadget3 renewal actionsg3a_initialconditions_normalcv g3a_initialconditions_normalparam g3a_otherfood g3a_otherfood_normalcv g3a_otherfood_normalparam g3a_renewal_initabund g3a_renewal_normalcv g3a_renewal_normalparam g3a_renewal_vonb g3a_renewal_vonb_recl g3a_renewal_vonb_t0
Gadget3 report actionsg3a_report_detail g3a_report_history g3a_report_stock
Gadget3 spawning actiong3a_spawn g3a_spawn_recruitment_bevertonholt g3a_spawn_recruitment_bevertonholt_ss3 g3a_spawn_recruitment_fecundity g3a_spawn_recruitment_hockeystick g3a_spawn_recruitment_ricker g3a_spawn_recruitment_simplessb
Gadget3 surplus production modelg3a_spmodel g3a_spmodel_logistic
Gadget3 tag-release actiong3a_predate_tagrelease g3a_tag_shedding
Gadget3 timekeeping actionsg3a_time
Tracing and debugging toolsg3a_trace_timings g3a_trace_var
Gadget3 weightloss actiong3a_weightloss
Gadget3 array-handling utilitiesg3_array_agg g3_array_combine g3_array_plot
g3 env: differentiable functionsdif_pmax dif_pmin dif_pminmax
Evaluate G3 forumulasg3_eval
Gadget3 formula helpersg3_formula
Gadget3 parameter value setterg3_init_val
G3 language extensions to Rg3_idx g3_param g3_param_table g3_param_vector g3_with
Gadget3 likelihood bounds_penalty actiong3l_bounds_penalty
Gadget3 likelihood actionsg3l_abundancedistribution g3l_catchdistribution g3l_distribution_multinomial g3l_distribution_multivariate g3l_distribution_sumofsquaredlogratios g3l_distribution_sumofsquares g3l_distribution_surveyindices_linear g3l_distribution_surveyindices_log g3_distribution_preview
Gadget3 random effects likelihood actionsg3l_random_dnorm g3l_random_walk
Gadget3 likelihood actions for sparse datag3l_sparsesample g3l_sparsesample_linreg g3l_sparsesample_sumsquares
Gadget3 CKMR likelihoodg3l_tagging_ckmr
Gadget3 likelihood understocking actiong3l_understocking
Gadget3 projected parametersg3_param_project g3_param_project_ar1 g3_param_project_dlnorm g3_param_project_dnorm g3_param_project_logar1 g3_param_project_rwalk
Gadget3 parameter helpersg3_parameterized
Gadget3 projected quotasg3_quota g3_quota_assess g3_quota_hockeyfleet g3_quota_hockeystick
Gadget3 actions into R codeg3_to_desc
Gadget3 actions into R codeg3_to_r print.g3_r
Gadget3 actions into TMB codeg3_tmb_adfun g3_tmb_fn g3_tmb_lower g3_tmb_par g3_tmb_parscale g3_tmb_relist g3_tmb_upper g3_to_tmb
G3 stock_* transformation functionsdebug_label debug_trace g3_step stock_assert stock_interact stock_intersect stock_iterate stock_prepend stock_ss stock_ssinv stock_switch stock_with
Gadget3 stock storageg3s_clone g3_fleet g3_is_stock g3_stock g3_stock_def g3_stock_instance
Gadget3 stock age dimensionsg3s_age g3s_agegroup
Gadget3 stock area dimensionsg3s_areagroup g3s_livesonareas g3_areas
Gadget3 tag dimensiong3s_tag
Gadget3 stock time dimensionsg3s_time g3s_time_convert
Gadget3 suitability formulaeg3_suitability_* g3_suitability_andersen g3_suitability_andersenfleet g3_suitability_constant g3_suitability_exponential g3_suitability_exponentiall50 g3_suitability_gamma g3_suitability_richards g3_suitability_straightline
Gadget3 time-based datag3_timeareadata
Gadget3 time-based formulasg3_timevariable