In addition to the
SPoRC::Setup_xxx functions, users can access several
advanced model features. These include:
Starting values can be specified in two ways:
SPoRC::Setup_xxx functions. Each
setup function accepts starting values through the ...
argument. The inputs must match the model’s parameter names and
dimensions. For more information on parameter dimensions, see the
Description of Model Parameters vignette.SPoRC::Setup_Mod_Rec
ln_global_R0, Rec_prop, steepness_h,
ln_InitDevs, ln_RecDevs, ln_sigmaR
SPoRC::Setup_Mod_Biologicals
ln_M, M_offset
SPoRC::Setup_Mod_Movement
move_pars, move_devs, move_pe_pars,
log_move_diffusion_pars, move_preference_pars
SPoRC::Setup_Mod_Tagging
ln_Init_Tag_Mort, ln_Tag_Shed, ln_tag_theta,
Tag_Reporting_Pars
SPoRC::Setup_Mod_Catch_and_F
ln_sigmaC, ln_sigmaF, ln_sigmaF_agg,
ln_F_mean, ln_F_devs, ln_F_mean_AggCatch,
ln_F_devs_AggCatch
SPoRC::Setup_Mod_FishIdx_and_Comps
ln_FishAge_theta, FishAge_corr_pars,
ln_FishAge_theta_agg, FishAge_corr_pars_agg,
ln_FishLen_theta, FishLen_corr_pars,
ln_FishLen_theta_agg, FishLen_corr_pars_agg
SPoRC::Setup_Mod_SrvIdx_and_Comps
ln_SrvAge_theta, SrvAge_corr_pars,
ln_SrvAge_theta_agg, SrvAge_corr_pars_agg,
ln_SrvLen_theta, SrvLen_corr_pars,
ln_SrvLen_theta_agg, SrvLen_corr_pars_agg
SPoRC::Setup_Mod_Fishsel_and_Q
ln_fish_fixed_sel_pars, ln_fish_q,
fishsel_pe_pars, ln_fishsel_devs
SPoRC::Setup_Mod_Srvsel_and_Q
ln_srv_fixed_sel_pars, ln_srv_q,
srvsel_pe_pars, ln_srvsel_devs
input_list$par) before running the model.In the following, we will illustrate both methods using the
recruitment module (Setup_Mod_Rec) and specify starting
values for ln_global_R0 and ln_sigmaR. First
let us load in the package and define the model dimensions.
# Load in packages
library(SPoRC)
data("sgl_rg_sable_data") # load in data
input_list <- Setup_Mod_Dim(years = 1:length(sgl_rg_sable_data$years), # vector of years
# (corresponds to year 1960 - 2024)
ages = 1:length(sgl_rg_sable_data$ages), # vector of ages
lens = seq(41,99,2), # number of lengths
n_regions = 1, # number of regions
n_sexes = sgl_rg_sable_data$n_sexes, # number of sexes == 1,
# female, == 2 male
n_fish_fleets = sgl_rg_sable_data$n_fish_fleets, # number of fishery
# fleet == 1, fixed gear, == 2 trawl gear
n_srv_fleets = sgl_rg_sable_data$n_srv_fleets, # number of survey fleets
verbose = FALSE
)We can specify starting values directly using the
Setup_Mod_Rec function. Note that all inputs passed via the
... argument must exactly match the parameter names and
their expected dimensions in the model (see the Description of Model
Parameters vignette for details).
input_list <- Setup_Mod_Rec(
input_list = input_list, # input data list from above
# Model options
do_rec_bias_ramp = 0, # disable bias ramp
sigmaR_switch = as.integer(length(1960:1975)), # switch from early to late sigmaR
dont_est_recdev_last = 1, # do not estimate last recruitment deviate
rec_model = "mean_rec", # recruitment model type
init_age_strc = 1, # geometric series for initial age structure
# Specify starting values
ln_global_R0 = log(30), # starting value for global R0
ln_sigmaR = c(log(1.5), log(1.5)) # starting values for early and late sigmaR
)In this example, the starting value for ln_global_R0 is set
to log(30), while ln_sigmaR is set to
log(1.5) for both the early (first element) and late
(second element) periods.
Alternatively, starting values can be assigned after running the setup functions without initial specifications. Users can extract the internal parameter list and modify starting values as needed:
input_list <- Setup_Mod_Rec(input_list = input_list, # input data list from above
# Model options
do_rec_bias_ramp = 0, # don't do bias ramp
sigmaR_switch = as.integer(length(1960:1975)), # when to switch from early to late sigmaR
dont_est_recdev_last = 1, # don't estimate last recruitment deviate
rec_model = "mean_rec", # recruitment model
init_age_strc = 1 # geometric series to derive age structure
)
# Specify starting values post-hoc
# R0
input_list$par$ln_global_R0 # default starting value
#> [1] 2.70805
input_list$par$ln_global_R0 <- log(30) # user specified starting value
# sigmaR
input_list$par$ln_sigmaR # default starting value
#> [1] 0 0
input_list$par$ln_sigmaR[] <- c(log(1.5), log(1.5)) # user specified starting valueMapping is a core feature of TMB and RTMB models. It allows users to either fix parameters at known values or to share parameters across different parts of the model. In the sections below, we first demonstrate how to use mapping to fix parameters. We then show how mapping can be used to share parameters across model partitions.
The SPoRC::Setup_xxx functions include arguments that
allow certain parameters to be fixed, meaning they are not estimated
during model fitting. These arguments are not available for all
parameters, but we note that all parameters can be specified to be
fixed. As an example, we use Setup_Mod_Rec to show how the
ln_sigmaR parameter can be fixed. The argument
sigmaR_spec = "fix".
input_list <- Setup_Mod_Rec(input_list = input_list, # input data list from above
# Model options
do_rec_bias_ramp = 0, # don't do bias ramp
sigmaR_switch = as.integer(length(1960:1975)), # when to switch from early to late sigmaR
dont_est_recdev_last = 1, # don't estimate last recruitment deviate
rec_model = "mean_rec", # recruitment model
init_age_strc = 1, # geometric series to derive age structure
# Parameter Fixing
sigmaR_spec = 'fix'
)
input_list$map$ln_sigmaR # both values are fixed and not estimated (specified as factor(rep(NA, 2)))
#> [1] <NA> <NA>
#> Levels:
input_list$par$ln_sigmaR # ln_sigmaR is then fixed at the default starting value
#> [1] 0 0To fix ln_sigmaR at a specific value, simply supply that value when calling the function:
input_list <- Setup_Mod_Rec(input_list = input_list, # input data list from above
# Model options
do_rec_bias_ramp = , # don't do bias ramp
sigmaR_switch = as.integer(length(1960:1975)), # when to switch from early to late sigmaR
dont_est_recdev_last = 1, # don't estimate last recruitment deviate
rec_model = "mean_rec", # recruitment model
init_age_strc = 1, # geometric series to derive age structure
# Parameter Fixing
sigmaR_spec = 'fix',
ln_sigmaR = c(log(1.5), log(1.5)) # user specified starting value
)
input_list$map$ln_sigmaR # both values are fixed and not estimated (specified as factor(rep(NA, 2)))
#> [1] <NA> <NA>
#> Levels:
input_list$par$ln_sigmaR # ln_sigmaR is then fixed at the user specified starting value
#> [1] 0.4054651 0.4054651However, not all parameters include a convenience argument like
sigmaR_spec = "fix". For example, ln_global_R0
does not. In such cases, you can fix the parameter manually by modifying
the map list directly and specifying the desired starting value:
input_list <- Setup_Mod_Rec(input_list = input_list, # input data list from above
# Model options
do_rec_bias_ramp = 0, # don't do bias ramp
sigmaR_switch = as.integer(length(1960:1975)), # when to switch from early to late sigmaR
dont_est_recdev_last = 1, # don't estimate last recruitment deviate
rec_model = "mean_rec", # recruitment model
init_age_strc = 1, # geometric series to derive age structure
)
input_list$map$ln_global_R0 <- factor(NA)
input_list$par$ln_global_R0 <- log(30)In this example, ln_global_R0 is fixed at
log(30) by setting its map entry to NA and
providing the desired value in the parameter list.