A list of functions available in the SpatialSablefishAssessment package
All of these functions have descriptions and details on expected input parameters using the standard ? R query methods. You can also use help(package = "SpatialSablefishAssessment") to get a list of functions available in this package.
Most of the functions will ask for an optional input parameter called region_key which will add a label for regions. This is a data.frame which is shown in the following code chunk. Note how the column TMB_ndx is an index made for C++ syntax not R i.e., it starts at 0 not 1.
region_key = data.frame(area = c("BS","AI","WGOA","CGOA","EGOA"), TMB_ndx = c(0:4))
region_key##   area TMB_ndx
## 1   BS       0
## 2   AI       1
## 3 WGOA       2
## 4 CGOA       3
## 5 EGOA       4
Validate functions
validate_input_data_and_parametersThis should always be run ondataandparametersapplyingTMB::MakeADFun. It should catch any issues that will likely cause your R session to crash.
Accessor functions
get_AFget age-frequency observed and predicted values from a modelget_LFget length-frequency observed and predicted values from a modelget_catchesget observed and predicted catches from a fitted modelget_fishing_mortalitiesget annual fishing mortalities from a modelget_indexget survey index from a modelget_partitionget numbers at age (units 1 = 1e6) from a fitted modelget_SSBget SSBS (kilo tonnes) from a fitted modelget_tag_recovery_obs_fitted_valuesget_tag_release_AFget age-frequency of tag-releasesget_negloglikeget negative log likelihoods for each contributionget_comp_sample_sizeget composition sample sizesimulate_observationsthis function will take a TMB object and simulate a number of observations, used to create simulated residuals.calculate_simulated_residualsthis function will take an element from an object created fromsimulate_observations. This will useDHARMa’screateDHARMafunction to calculated simulated residuals
Plotting functions
plot_AFplot age frequency observationplot_age_length_matrixplot input age-length transition matricesplot_catch_fitplot the fit to catchesplot_fishing_mortalitiesplot fishing mortalitiesplot_frequency_of_tag_release_and_recoveriesplot_index_fitplot survey indexplot_init_nageplot initial numbers at ageplot_input_catchesplot input catchesplot_input_observationsplot input observationsplot_input_timeblocksplot selectivity and catchability time-blocks in a modelplot_comp_sample_sizeplot composition sample sizeplot_LFplot length frequency observationplot_mean_ageplot mean age observationsplot_mean_lengthplot mean length observationsplot_mean_weightplot mean weight over time for males and femalesplot_movementplot movement matrix from a modelplot_partitionplot numbers at age by year and sexplot_recruitmentplot annual recruitment by regionplot_selectivitiesplot selectivity curvesplot_SSBplot regional SSBsplot_tag_recovery_obsplot tag-recovery obsplot_tag_recovery_fitsan alternative plotting function for tag-recovery obsplot_tag_release_AFplot the numbers at age by sex for each release event
Estimation functions
estimate_with_phasesEstimate a model where parameters are estimated with phasesprofile_paramRun log-likelihood profiles on an estimated parameterset_up_parametersFix parameters, usesfix_parsandset_pars_to_be_the_samefor theTagIntegratedmodelpre_optim_sanity_checksrun some checks on a TMB model of typeTagIntegratedbefore optimizationpost_optim_sanity_checksrun some checks on a TMB model of typeTagIntegratedafter optimizationcheck_gradientscheck all parameter gradients are not zeroFrancis_reweightingcalculate stage-two weights for composition dataget_tmb_fixed_effectsreturn fixed effect parameters from a modelfix_parsturn off parameters so they aren’t estimated, there are many parameters that shouldn’t be estimatedset_pars_to_be_the_sameset parameters to be estimated at the same value i.e., male female have the same selectivity parameters. or tag-reporting to be the same among regions.rmvnorm_precsimulate from a multivariate normal distribution using the precision matrix.
Projection/Reference point functions
setup_proj_datathis function will take an estimation model and create a data list that when built withTMB::MakeADFuncreates a model that will projections for a user defined number of projection years.find_regional_Fsprthis will attempt to find an F for each region and fishery assuming future deterministic (mean) recruitment that achieves some specified target percent \(B_{0}\) in each region.
Model comparison functions
Often you will run multiple models to explore alternative assumptions and hypothesis. There are a range of function available for extracting output convenient for plotting and summarizing. In order to use the following functions you need to create a list containing multiple runs e.g.
multi_runs <- list()
multi_runs[[1]] <- low_M_model$report()
multi_runs[[2]] <- high_M_model$report()
run_labels = c("M = 0.08", "M = 0.2")
ssb_df = get_multiple_ssbs(mle_ls = multi_runs, run_labels = run_labels)get_multiple_ssbsget multiple models SSBsget_multiple_catch_fitsGet multiple models catch fitsget_multiple_nllsget multiple models negative log-likelihoodsummarise_individual_modelsthis is a function that will build a Bookdown/Rmarkdown book displaying a full summary of each model individually. This functions expect users to save the following objects with these exact names for each model that you want to compare. Then pass the function all the directories with model labels and descriptions. Then it “should” automatically build you a Rmarkdown document.
saveRDS(data, file.path(fig_path, "data.RDS"))
saveRDS(parameters, file.path(fig_path, "parameters.RDS"))
saveRDS(mle_report, file.path(fig_path, "mle_report.RDS"))
saveRDS(sd_report, file.path(fig_path, "sd_report.RDS"))
saveRDS(mle_spatial, file.path(fig_path, "mle_optim.RDS"))
saveRDS(map_fixed_pars, file.path(fig_path, "map_fixed_pars.RDS"))
saveRDS(region_key, file.path(fig_path, "region_key.RDS"))summarise_multiple_modelsthis is a function that will build a Bookdown/Rmarkdown book compareing multiple models fits and quantities on the same plot. This functions expect users to save the following objects with these exact names for each model that you want to compare. Then pass the function all the directories with model labels and descriptions. Then it “should” automatically build you a Rmarkdown document.
saveRDS(data, file.path(fig_path, "data.RDS"))
saveRDS(parameters, file.path(fig_path, "parameters.RDS"))
saveRDS(mle_report, file.path(fig_path, "mle_report.RDS"))
saveRDS(sd_report, file.path(fig_path, "sd_report.RDS"))
saveRDS(mle_spatial, file.path(fig_path, "mle_optim.RDS"))
saveRDS(map_fixed_pars, file.path(fig_path, "map_fixed_pars.RDS"))
saveRDS(region_key, file.path(fig_path, "region_key.RDS"))Distribution functions
ddirichmultDirichlet-multinomial pdf functiondmultinom_updMultinomial pdf function, which is the same as TMB’s. Differs from Rs basedmultinomby allowing non-integer x values and not rounding the x values.lognormal_CIcalculate confidence intervals for the lognormal distributionlog_cvcalculate cv for the lognormal distribution given standard deviationlog_sigmacalculate standard deviation for the lognormal distribution given CV
Parameter transformation functions
restoresimplexgo from simplex to unit vectorsimplexgo from unit vector to simplexlogit_generallogistic transformation between a specified lower and upper boundlogitlogistic transformation between 0, 1 similar toqlogisinvlogit_generalinverse logistic transformation between a specified lower and upper boundinvlogitinverse logistic transformation between 0, 1 similar toplogisbound_unittransform a parameter \(X\) bound between -1 and 1 (i.e., correlation parameter) to value \(Y\) which is unbounded as \[ Y = \begin{cases} \sqrt{\frac{X^2}{1 - X^2}}, \ \ & X \geq 0 \\ -\sqrt{\frac{X^2}{1 - X^2}} , \ \ & X < 0 \end{cases} \]inv_bound_unitinverse ofbound_unitgm_meancalculate the geometric meansum_to_zero_QRtake an unconstrained vector of lengthN - 1and calculate a vector of lengthNthat sums = 1.
Data grooming functions
These aren’t related to the model per se. These are useful when grooming raw data sets that are ultimately used as inputs into the model.
record_grooming_rulethis will create a table of how much catch and how many records are removed from applying some data grooming rulesapply_grooming_ruleequivalent to thesubsetfunction