| Title: | The Fisheries Integrated Modeling System |
|---|---|
| Description: | The Fisheries Integrated Modeling System is a next-generation framework of stock assessment models, assisting fishery managers with the goal of achieving sustainable fisheries. This system, when completed in a few years, offers the NOAA Fisheries and global fisheries science communities an advanced set of stock assessment models. These tools can be used separately or in combination to incorporate ecosystem and socioeconomic data and models, as well as climate effects and other drivers within the marine environment, into stock assessment models. |
| Authors: | Kelli F. Johnson [aut, cre] (ORCID: <https://orcid.org/0000-0002-5149-451X>), Grant D. Adams [aut] (ORCID: <https://orcid.org/0000-0003-0297-8347>), Jon K. T. Brodziak [aut] (ORCID: <https://orcid.org/0000-0001-8690-5588>), Kathryn L. Doering [aut] (ORCID: <https://orcid.org/0000-0002-0396-7044>), Daniel R. Goethel [aut] (ORCID: <https://orcid.org/0000-0003-0066-431X>), Andrea M. Havron [aut] (ORCID: <https://orcid.org/0000-0002-4080-448X>), Alex Jensen [aut], Ronald Klasky [aut] (ORCID: <https://orcid.org/0009-0004-7563-7716>), Peter T. Kuriyama [aut] (ORCID: <https://orcid.org/0000-0002-6971-4015>), Emily M. Liljestrand [aut] (ORCID: <https://orcid.org/0000-0002-1118-3872>), Christopher M. Legault [aut] (ORCID: <https://orcid.org/0000-0002-0328-1376>), Bai Li [aut] (ORCID: <https://orcid.org/0000-0002-8249-1442>), Timothy J. Miller [aut] (ORCID: <https://orcid.org/0000-0003-1411-1206>), Cole C. Monnahan [aut] (ORCID: <https://orcid.org/0000-0003-0871-6700>), Elizabeth F. Perl [aut] (ORCID: <https://orcid.org/0000-0003-1608-8628>), Megumi C. Oshima [aut] (ORCID: <https://orcid.org/0009-0002-2239-1594>), Kyle W. Shertzer [aut] (ORCID: <https://orcid.org/0000-0001-7196-5959>), Christine C. Stawitz [aut] (ORCID: <https://orcid.org/0000-0003-3122-4501>), Jane Y. Sullivan [aut] (ORCID: <https://orcid.org/0000-0002-8094-1673>), Matthew Supernaw [aut] (ORCID: <https://orcid.org/0009-0007-3681-7433>), Ian G. Taylor [aut] (ORCID: <https://orcid.org/0000-0002-4232-5669>), Nathan R. Vaughan [aut] (ORCID: <https://orcid.org/0009-0000-3054-6950>), Erik H. Williams [aut] (ORCID: <https://orcid.org/0000-0001-6623-4254>), Adrianne T. Wilson [aut] (ORCID: <https://orcid.org/0009-0006-1171-6014>), Kristan Blackhart [ctb] (ORCID: <https://orcid.org/0000-0003-4232-2510>), Edward J. Dick [ctb] (ORCID: <https://orcid.org/0000-0001-7681-9176>), James N. Ianelli [ctb] (ORCID: <https://orcid.org/0000-0002-7170-8677>), Huihua Lee [ctb] (ORCID: <https://orcid.org/0009-0009-1506-9098>) |
| Maintainer: | Kelli F. Johnson <[email protected]> |
| License: | GPL (>= 3) | file LICENSE |
| Version: | 0.11.0 |
| Built: | 2026-10-05 16:47:44 UTC |
| Source: | https://github.com/noaa-fims/fims |
Returns a tidy tibble of observed-vs-expected pairs drawn from the output of
get_estimates(). Only rows that have both an observed value and a
model-expected value are included (i.e. data-likelihood rows), so parameter
rows without data observations are automatically dropped.
## S3 method for class 'FIMSFit' augment(x, include_weights = TRUE, ...)## S3 method for class 'FIMSFit' augment(x, include_weights = TRUE, ...)
x |
A |
include_weights |
Logical (default |
... |
Unused; present for S3 method compatibility. |
The returned tibble follows the conventions expected by every
yardstick::metric_set() metric function:
| Column | Role |
.truth |
Observed data value (maps from observed) |
.pred |
Model-expected value (maps from expected) |
.weight |
Inverse-variance weight from uncertainty (optional) |
label |
Parameter / quantity label, e.g. "catch_expected" |
fleet |
Fleet name for fleet rows, otherwise NA |
module_id |
Unique module identifier |
distribution |
Likelihood distribution used for this data stream |
year_i |
Year index (present when available in the estimates) |
age_i |
Age index (present when available in the estimates) |
A tibble::tibble() with at least the columns .truth, .pred,
and optional .weight, plus grouping-metadata columns.
get_fit_metrics(), get_estimates(), yardstick::metrics()
## Not run: data("data_big") data_4_model <- FIMSFrame(data_big) fit <- setup_default_parameters( data = data_4_model ) |> initialize_fims(data = data_4_model) |> fit_fims(optimize = TRUE) # Tidy tibble of observed vs. expected, ready for any yardstick metric augment(fit) ## End(Not run)## Not run: data("data_big") data_4_model <- FIMSFrame(data_big) fit <- setup_default_parameters( data = data_4_model ) |> initialize_fims(data = data_4_model) |> fit_fims(optimize = TRUE) # Tidy tibble of observed vs. expected, ready for any yardstick metric augment(fit) ## End(Not run)
Calculates Mohn's rho, a diagnostic statistic that summarizes the bias in retrospective analysis. The statistic measures the average relative difference between estimates from retrospective peels and the reference model at the corresponding terminal year of each peel. A value close to zero suggests minimal retrospective bias, while larger absolute values indicate potential model misspecification or data conflicts.
The formula for Mohn's rho is:
where n is the number of retrospective peels, is the
estimated value from peel i at its terminal year, and is
the value from the base model at that same year.
calculate_mohns_rho(retro_fit, quantity)calculate_mohns_rho(retro_fit, quantity)
retro_fit |
List returned by the |
quantity |
Character string specifying which quantity to calculate Mohn's rho for (e.g., "spawning_biomass", "expected_recruitment") |
Calculate Mohn's rho for retrospective analysis
A numeric value representing Mohn's rho. Values close to zero indicate minimal retrospective bias. Positive values mean that, on average, each peel's terminal-year estimate is higher than the reference model's estimate for the same year (retrospective overestimation), while negative values mean retrospective underestimation.
Mohn (1999). The retrospective problem in sequential population analysis: An investigation using cod fishery and simulated data. ICES Journal of Marine Science, 56(4), 473-488. https://doi.org/10.1006/jmsc.1999.0481.
Hurtado-Ferro et al. (2015). Looking in the rear-view mirror: bias and retrospective patterns in integrated, age-structured stock assessment models. ICES Journal of Marine Science, 72(1), 99-110. https://doi.org/10.1093/icesjms/fsu198.
## Not run: library(FIMS) # Use built-in dataset from FIMS data("data_big") # Prepare data for FIMS model data_4_model <- FIMSFrame(data_big) # Create parameters parameters <- setup_default_parameters(data = data_4_model) # Run retrospective analysis retro_fit <- run_fims_retrospective( years_to_remove = 0:5, data = data_big, parameters = parameters, n_cores = 1 ) # Calculate Mohn's rho for spawning biomass rho_ssb <- calculate_mohns_rho(retro_fit, quantity = "spawning_biomass") # Calculate Mohn's rho for recruitment rho_rec <- calculate_mohns_rho(retro_fit, quantity = "expected_recruitment") ## End(Not run)## Not run: library(FIMS) # Use built-in dataset from FIMS data("data_big") # Prepare data for FIMS model data_4_model <- FIMSFrame(data_big) # Create parameters parameters <- setup_default_parameters(data = data_4_model) # Run retrospective analysis retro_fit <- run_fims_retrospective( years_to_remove = 0:5, data = data_big, parameters = parameters, n_cores = 1 ) # Calculate Mohn's rho for spawning biomass rho_ssb <- calculate_mohns_rho(retro_fit, quantity = "spawning_biomass") # Calculate Mohn's rho for recruitment rho_rec <- calculate_mohns_rho(retro_fit, quantity = "expected_recruitment") ## End(Not run)
The following classes are exported from C++ via Rcpp. Their documentation is provided in the rendered C++ documentation. For detailed usage, see the C++ docs.
The following functions are exported from C++ via Rcpp. Their documentation is provided in the rendered C++ documentation. For detailed usage, see the C++ docs.
A data frame containing the information needed to run an age-structured stock
assessment model in FIMS. This data was generated using
the ASSAMC package written for the model comparison project.
The source code to make this dataset is in data-raw/data_big.R which is on
GitHub but will not be in your local installation because it is in the
.Rbuildignore file.
data_bigdata_big
A data frame with 2808 observations of 8 variables:
The type of input the row contains. Allowed types include age_comp, age_to_length_conversion, index, catch, length_bin, length_comp, and weight_at_age.
A character string providing the name of the information
source that the input was collected from, e.g., "Trawl fishery" or
"age_zero_survey". Entries can be NA for information that is not
fleet/vessel specific.
An integer age. Entry can be NA if information pertains to
multiple ages, e.g., total catch rather than catch of age-4 fish.
In this dataset, ages start at one, therefore recruitment happens at age
one not age zero.
A numeric length. Entry can be NA if information doesn't
pertain to length. For length_comp rows, this identifies the observed
length bin. For length_bin rows, this defines length-bin values used
for age-to-length conversion.
The timing, i.e., year the data was collected.
The observed measurement of interest.
A character string specifying the units of observed. Allowed
units for each data type are as follows. mt is used for index,
catch, and weight_at_age data. number or proportion are each
viable units for the composition data, where the former is the preferred
unit of measurement.
A right-handed formula specifying the distributional
assumptions for the entry in observed. See FIMSFrame() for more
information about this column.
www.github.com/NOAA-FIMS/Age_Structured_Stock_Assessment_Model_Comparison
A lookup table that maps each supported distribution family to the field name used to link observed data, the random-value generator, and the remaining parameter names for that family.
fims_distributionsfims_distributions
A data frame with columns family, sample_function, central_parameter, and
other_parameters. sample_function is a character column with function
names.
A vector of strings that define which input types are allowed in the column
labeled type in the data slot of a FIMSFrame object. Strings are composed
of words separated by underscores, e.g., "weight_at_age".
fims_input_typesfims_input_types
A vector of strings.
FIMSFit and associated child classesCreate an object with the class of FIMSFit after running a FIMS model. This
is typically done within fit_fims() but it can be create manually by the
user if they have used their own bespoke code to fit a FIMS model.
FIMSFit( input, obj, opt = list(), sdreport = list(), run_time = c(time_total = as.difftime(0, units = "secs")), version = utils::packageVersion("FIMS") )FIMSFit( input, obj, opt = list(), sdreport = list(), run_time = c(time_total = as.difftime(0, units = "secs")), version = utils::packageVersion("FIMS") )
input |
Input list as returned by |
obj |
An object returned from |
opt |
An object returned from an optimizer, typically from
|
sdreport |
An object of the |
run_time |
A vector of at least length one, where all entries are of the
|
version |
The version of FIMS that was used to optimize the model. If
|
An object with an S4 class of FIMSFit is returned. The object will have the
following slots:
input:A list containing the model setup in the same form it was passed.
obj:A list returned from TMB::MakeADFun() in the same form it was passed.
opt:A list containing the optimized model in the same form it was passed.
max_gradient:The maximum gradient found when optimizing the model. The default is
NA, which means that the model was not optimized.
report:A list containing the model report from obj[["report"]]().
sdreport:An object with the sdreport class containing the output from
TMB::sdreport(obj).
run_time:The length of time it took to run the model if it was optimized.
version:The package version of FIMS used to fit the model or at least the version used to create this output, which will not always be the same if you are running this function yourself.
model_output:The FIMS model output as a JSON string.
FIMSFrame and associated child classesAll constructor functions take a single input and build an object specific
to the needs of each model type within FIMS. FIMSFrame is the parent
class. Future, associated child classes will have the additional slots
needed for different types of models.
FIMSFrame(data)FIMSFrame(data)
data |
A |
The input data are both sorted (see the section below on sorting) and expanded to include -999 observations for all missing rows before returning them in the data slot.
Currently, ages must be integers, i.e., FIMS cannot accommodate numeric ages like age 1.5 but we hope that this is something that we will be able to accommodate in the future. Additionally, the first age in your data set will be the age at which fish recruit to the population. So, if you do not have age-0 age compositions and age two is the first age you have in your composition data, then recruitment will happen at age two. Furthermore, you must have composition entries for every integer between your first and last age in the model. For example, you cannot bin fish into bins that span multiple years, you must have age-2, age-3, and age-4 not just age-2 and age-4 fish in your composition data.
Uncertainty information for your data contains information for fitting the
model and for creating bootstrapped data sets. Right-handed formulas are
used to specify the distribution your data is assumed to follow, the derived
quantity in the model that the data is assumed to represent, and parameters
associated with the assumed distribution. For example, catch data can be
distributed using a normal or lognormal distribution and if you use a normal
distribution the observation is assumed to represent catch_expected but if
you use a lognormal distribution the observation is assumed to represent
log_catch_expected. Therefore, for the former you would specify
"~dnorm(mean = catch_expected, sd = 0.01)" and for the later you would
specify "~dlnorm(meanlog = log_catch_expected, sdlog = 0.01)". Where, the
input value for sd or sdlog is the standard deviation of the mean or
standard deviation of the log of the mean, respectively. The distribution
names and argument names match the names used in R. Use args(), e.g.,
args(dnorm), to get information on the argument names that are required
for your distribution. And, use ?distributions to get a list of
distributions that have density functions in base R. To get information on
available derived quantities to set the central tendency of the distribution
to, you can create a fleet object and inspect the available names, e.g.,
names(methods::new(Fleet)), or you can navigate to the Public Attributes
section of the doxygen documentation for Fleet by running ?Fleet.
It is important that the order of the rows in the data are correct but it is
not expected that the user will do this. Instead, the returned data are
sorted using dplyr::arrange() before placing them in the data slot. Data
are first sorted by data type, placing all weight_at_age data next to
other weight_at_age data and all catch data next to catch data.
Thus, age_comp data will come first because their type is "age" and "a" is
first in the alphabet. All other types will follow according to their order
in the alphabet.
Next, within each type, data are organized by fleet. So, age_comp
information for fleet1 will come before survey1. Next, all data within type
and fleet are arranged by timing, e.g., by year. That is the end of the
sorting for time series data like catch and indices. The biological data
are further sorted by bin. Thus, age_comp information will be arranged as
follows:
| type | name | timing | age | observed |
| age_comp | fleet1 | 2022 | 1 | 0.3 |
| age_comp | fleet1 | 2022 | 2 | 0.7 |
| age_comp | fleet1 | 2023 | 1 | 0.5 |
length_comp data are sorted the same way but by length bin instead of
by age bin. It becomes more complicated for the age_to_length_conversion
data, which are sorted by type, name, timing, age, and then length. So, a
full set of length, e.g., length 10, length 20, length 30, etc., is placed
together for a given age. After that age, another entire set of length
information will be provided for that next age. Once the year is complete
for a given fleet then the next year will begin.
An object of the S4 class FIMSFrame class, or one of its child classes, is
validated and then returned. All objects will at a minimum have a slot
called data to store the input data frame. Additional slots are dependent
on the child class. Use methods::showClass() to see all available slots.
plot,FIMSFrame,missing-method() for plotting FIMSFrame objects.
Fit a FIMS model (BETA)
fit_fims( input, get_sd = TRUE, save_sd = TRUE, number_of_loops = 3, optimize = TRUE, number_of_newton_steps = 0, control = list(eval.max = 10000, iter.max = 10000, trace = 0), filename = NULL, getReportCovariance = FALSE )fit_fims( input, get_sd = TRUE, save_sd = TRUE, number_of_loops = 3, optimize = TRUE, number_of_newton_steps = 0, control = list(eval.max = 10000, iter.max = 10000, trace = 0), filename = NULL, getReportCovariance = FALSE )
input |
Input list as returned by |
get_sd |
A boolean specifying if the |
save_sd |
A logical, with the default |
number_of_loops |
A positive integer specifying the number of iterations of the optimizer that will be performed to improve the gradient. The default is three, leading to four total optimization steps. |
optimize |
Optimize (TRUE, default) or (FALSE) build and return a list containing the obj and report slot. |
number_of_newton_steps |
The number of Newton steps using the inverse Hessian to do after optimization. Not yet implemented. |
control |
A list of optimizer settings passed to |
filename |
Character string giving a file name to save the fitted
object as an RDS object. Defaults to 'fit.RDS', and a value of NULL
indicates not to save it. If specified, it must end in .RDS. The file is
written to folder given by |
getReportCovariance |
A logical passed to |
This function is a beta version still and subject to change without warning.
An object of class FIMSFit is returned, where the structure is the same
regardless if optimize = TRUE or not. Uncertainty information is only
included in the estimates slot if get_sd = TRUE.
There is an accessor function for each slot in the S4 class FIMSFit, where
the function is named get_*() and the star can be replaced with the slot
name, e.g., get_input(). These accessor functions are the preferred way
to access objects stored in the available slots.
get_input(x) ## S4 method for signature 'FIMSFit' get_input(x) get_report(x) ## S4 method for signature 'FIMSFit' get_report(x) get_obj(x) ## S4 method for signature 'FIMSFit' get_obj(x) get_opt(x) ## S4 method for signature 'FIMSFit' get_opt(x) get_max_gradient(x) ## S4 method for signature 'FIMSFit' get_max_gradient(x) get_gradient(x) ## S4 method for signature 'FIMSFit' get_gradient(x) get_sdreport(x) ## S4 method for signature 'FIMSFit' get_sdreport(x) get_estimates(x) ## S4 method for signature 'FIMSFit' get_estimates(x) get_number_of_parameters(x) ## S4 method for signature 'FIMSFit' get_number_of_parameters(x) get_run_time(x) ## S4 method for signature 'FIMSFit' get_run_time(x) get_version(x) ## S4 method for signature 'FIMSFit' get_version(x) get_model_output(x) ## S4 method for signature 'FIMSFit' get_model_output(x)get_input(x) ## S4 method for signature 'FIMSFit' get_input(x) get_report(x) ## S4 method for signature 'FIMSFit' get_report(x) get_obj(x) ## S4 method for signature 'FIMSFit' get_obj(x) get_opt(x) ## S4 method for signature 'FIMSFit' get_opt(x) get_max_gradient(x) ## S4 method for signature 'FIMSFit' get_max_gradient(x) get_gradient(x) ## S4 method for signature 'FIMSFit' get_gradient(x) get_sdreport(x) ## S4 method for signature 'FIMSFit' get_sdreport(x) get_estimates(x) ## S4 method for signature 'FIMSFit' get_estimates(x) get_number_of_parameters(x) ## S4 method for signature 'FIMSFit' get_number_of_parameters(x) get_run_time(x) ## S4 method for signature 'FIMSFit' get_run_time(x) get_version(x) ## S4 method for signature 'FIMSFit' get_version(x) get_model_output(x) ## S4 method for signature 'FIMSFit' get_model_output(x)
x |
Output returned from |
get_input() returns the list that was used to fit the FIMS model, which
is the returned object from setup_default_parameters().
get_report() returns the TMB report, where anything that is flagged as
reportable in the C++ code is returned.
get_obj() returns the output from TMB::MakeADFun().
get_opt() returns the output from nlminb(), which is the minimizer used
in fit_fims().
get_max_gradient() returns the maximum gradient found when optimizing the
model.
get_gradient() returns the per-parameter gradient vector at the MLE as
stored during fitting. Unlike calling get_obj(x)[["gr"]](get_opt(x)[["par"]])
this function is safe to call after clear() because it reads
from a stored R vector rather than the compiled C++ objective function.
get_sdreport() returns the list from TMB::sdreport().
get_estimates() returns a tibble of parameter values and their
uncertainties from a fitted model.
get_number_of_parameters() returns a vector of integers specifying the
number of fixed-effect parameters and the number of random-effect parameters
in the model.
get_run_time() returns the amount of time it took to run the model in
seconds as a difftime object.
get_version() returns the package_version of FIMS that was used to fit
the model.
get_model_output() returns the finalized FIMS output as a JSON list.
There is an accessor function for each slot in the S4 class FIMSFrame,
where the function is named get_*() and the star can be replaced with the
slot name, e.g., get_data(). These accessor functions are the preferred
way to access objects stored in the available slots.
get_data(x) ## S4 method for signature 'FIMSFrame' get_data(x) ## S4 method for signature 'data.frame' get_data(x) get_fleets(x) ## S4 method for signature 'FIMSFrame' get_fleets(x) ## S4 method for signature 'data.frame' get_fleets(x) get_n_fleets(x) ## S4 method for signature 'FIMSFrame' get_n_fleets(x) ## S4 method for signature 'data.frame' get_n_fleets(x) get_n_years(x) ## S4 method for signature 'FIMSFrame' get_n_years(x) ## S4 method for signature 'data.frame' get_n_years(x) get_start_year(x) ## S4 method for signature 'FIMSFrame' get_start_year(x) ## S4 method for signature 'data.frame' get_start_year(x) get_end_year(x) ## S4 method for signature 'FIMSFrame' get_end_year(x) ## S4 method for signature 'data.frame' get_end_year(x) get_ages(x) ## S4 method for signature 'FIMSFrame' get_ages(x) ## S4 method for signature 'data.frame' get_ages(x) get_n_ages(x) ## S4 method for signature 'FIMSFrame' get_n_ages(x) ## S4 method for signature 'data.frame' get_n_ages(x) get_lengths(x) ## S4 method for signature 'FIMSFrame' get_lengths(x) ## S4 method for signature 'data.frame' get_lengths(x) get_n_lengths(x) ## S4 method for signature 'FIMSFrame' get_n_lengths(x) ## S4 method for signature 'data.frame' get_n_lengths(x)get_data(x) ## S4 method for signature 'FIMSFrame' get_data(x) ## S4 method for signature 'data.frame' get_data(x) get_fleets(x) ## S4 method for signature 'FIMSFrame' get_fleets(x) ## S4 method for signature 'data.frame' get_fleets(x) get_n_fleets(x) ## S4 method for signature 'FIMSFrame' get_n_fleets(x) ## S4 method for signature 'data.frame' get_n_fleets(x) get_n_years(x) ## S4 method for signature 'FIMSFrame' get_n_years(x) ## S4 method for signature 'data.frame' get_n_years(x) get_start_year(x) ## S4 method for signature 'FIMSFrame' get_start_year(x) ## S4 method for signature 'data.frame' get_start_year(x) get_end_year(x) ## S4 method for signature 'FIMSFrame' get_end_year(x) ## S4 method for signature 'data.frame' get_end_year(x) get_ages(x) ## S4 method for signature 'FIMSFrame' get_ages(x) ## S4 method for signature 'data.frame' get_ages(x) get_n_ages(x) ## S4 method for signature 'FIMSFrame' get_n_ages(x) ## S4 method for signature 'data.frame' get_n_ages(x) get_lengths(x) ## S4 method for signature 'FIMSFrame' get_lengths(x) ## S4 method for signature 'data.frame' get_lengths(x) get_n_lengths(x) ## S4 method for signature 'FIMSFrame' get_n_lengths(x) ## S4 method for signature 'data.frame' get_n_lengths(x)
x |
An object returned from |
get_data() returns a data frame of the class tbl_df containing data for
a FIMS model in a long format. The tibble will potentially have the
following columns depending if it fits to ages and lengths or just one of
them:
type, fleet, age, length, timing, observed, unit, and uncertainty.
get_fleets() returns a vector of strings containing the fleet names.
get_n_fleets() returns an integer specifying the number of fleets in the
model, where fleets is inclusive of both fishing fleets and survey vessels.
get_n_years() returns an integer specifying the number of years in the
model.
get_start_year() returns an integer specifying the start year of the
model.
get_end_year() returns an integer specifying the end year of the
model.
get_ages() returns a vector of age bins used in the model.
get_n_ages() returns an integer specifying the number of age bins used in
the model.
get_lengths() returns a vector of length bins used in the model.
get_n_lengths() returns an integer specifying the number of length bins
used in the model.
Extracts observed-vs-expected pairs from a FIMSFit object via
augment.FIMSFit() and evaluates a yardstick::metric_set() over them.
get_fit_metrics( x, metrics = yardstick::metric_set(yardstick::rmse, yardstick::mae, yardstick::rsq), group_by = NULL, weighted = FALSE, ... )get_fit_metrics( x, metrics = yardstick::metric_set(yardstick::rmse, yardstick::mae, yardstick::rsq), group_by = NULL, weighted = FALSE, ... )
x |
A |
metrics |
A |
group_by |
A character vector of column names in the augmented tibble to group by before computing metrics. Common choices:
|
weighted |
Logical (default |
... |
Additional arguments forwarded to |
By default the metrics are computed over all data streams combined.
Pass one or more column names to group_by to get per-stream breakdowns
(e.g., group_by = "label" gives one row per data-stream label such as
"catch_expected", "age_comp_expected", etc.).
A tibble::tibble() in the standard yardstick result format:
columns .metric, .estimator, .estimate, plus any grouping columns.
augment.FIMSFit(), yardstick::metric_set()
## Not run: data("data_big") data_4_model <- FIMSFrame(data_big) fit <- setup_default_parameters( data = data_4_model ) |> initialize_fims(data = data_4_model) |> fit_fims(optimize = TRUE) # Overall RMSE / MAE / R^2 across all data streams get_fit_metrics(fit) # Per-data-stream: one row-set per label # (e.g. "catch_expected", "index_expected", "age_comp_expected") get_fit_metrics(fit, group_by = "label") # Per-fleet with a custom metric set get_fit_metrics( fit, metrics = yardstick::metric_set(yardstick::rmse, yardstick::mape), group_by = "fleet" ) # Inverse-variance weighted metrics get_fit_metrics(fit, weighted = TRUE) ## End(Not run)## Not run: data("data_big") data_4_model <- FIMSFrame(data_big) fit <- setup_default_parameters( data = data_4_model ) |> initialize_fims(data = data_4_model) |> fit_fims(optimize = TRUE) # Overall RMSE / MAE / R^2 across all data streams get_fit_metrics(fit) # Per-data-stream: one row-set per label # (e.g. "catch_expected", "index_expected", "age_comp_expected") get_fit_metrics(fit, group_by = "label") # Per-fleet with a custom metric set get_fit_metrics( fit, metrics = yardstick::metric_set(yardstick::rmse, yardstick::mape), group_by = "fleet" ) # Inverse-variance weighted metrics get_fit_metrics(fit, weighted = TRUE) ## End(Not run)
Convenience filter to pull out one specific data stream (e.g. the catch for a given module) so you can pass it directly to any yardstick metric or plot it.
get_fit_stream(x, stream_label = NULL, module_id = NULL, ...)get_fit_stream(x, stream_label = NULL, module_id = NULL, ...)
x |
A |
stream_label |
Character scalar. The value of the |
module_id |
Integer scalar. The |
... |
Forwarded to |
Fleets and surveys can be told apart by the fleet column, which holds the
fleet name from the data, or by module_id, where, e.g., module_id == 1
is the first fishing fleet and module_id == 2 is the first survey in the
FIMS vignettes. To discover which values are present in your fit, inspect
augment(fit) directly.
A tibble::tibble() subset of the augmented data.
## Not run: data("data_big") data_4_model <- FIMSFrame(data_big) fit <- setup_default_parameters( data = data_4_model ) |> initialize_fims(data = data_4_model) |> fit_fims(optimize = TRUE) # Catch for the fishing fleet (module_id 1) - compute RMSE get_fit_stream(fit, stream_label = "catch_expected", module_id = 1) |> yardstick::rmse(truth = .truth, estimate = .pred) # Survey index stream (module_id 2 in the data_big example) get_fit_stream(fit, stream_label = "index_expected", module_id = 2) # All streams for fleet 1 (catch + age comp + length comp) get_fit_stream(fit, module_id = 1) ## End(Not run)## Not run: data("data_big") data_4_model <- FIMSFrame(data_big) fit <- setup_default_parameters( data = data_4_model ) |> initialize_fims(data = data_4_model) |> fit_fims(optimize = TRUE) # Catch for the fishing fleet (module_id 1) - compute RMSE get_fit_stream(fit, stream_label = "catch_expected", module_id = 1) |> yardstick::rmse(truth = .truth, estimate = .pred) # Survey index stream (module_id 2 in the data_big example) get_fit_stream(fit, stream_label = "index_expected", module_id = 2) # All streams for fleet 1 (catch + age comp + length comp) get_fit_stream(fit, module_id = 1) ## End(Not run)
Returns a single-row tibble of model-level diagnostics following the
generics::glance() convention. Standard information-criterion columns
(logLik, AIC, BIC, nobs) are included alongside FIMS-specific
diagnostics (max_gradient, marginal_nll, total_nll, converged,
terminal_ssb).
## S3 method for class 'FIMSFit' glance(x, ...)## S3 method for class 'FIMSFit' glance(x, ...)
x |
A |
... |
Unused; present for S3 method compatibility. |
A tibble::tibble() with one row and the following columns:
logLikMarginal log-likelihood at the MLE
(-opt$objective).
AICAkaike information criterion (marginal, fixed effects only).
BICBayesian information criterion (marginal, fixed effects only).
nobsTotal number of data observations (rows with both an
observed and an expected value in get_estimates()).
npar_fixedNumber of fixed-effect parameters.
npar_randomNumber of random-effect parameters.
marginal_nllMarginal negative log-likelihood
(opt$objective); NA if the model was not optimized.
total_nllTotal (joint) negative log-likelihood from the TMB
report (report$jnll).
max_gradientMaximum absolute gradient at the MLE. Values below 0.001 are generally considered well-converged.
convergedLogical; TRUE when opt$convergence == 0 and
max_gradient < 0.001.
terminal_ssbSpawning stock biomass at the terminal year, extracted from the TMB report. Returns a list-column when multiple populations are present.
fims_versionThe version of FIMS used to fit the model.
run_timeTotal wall-clock time of the fit in seconds.
AIC and BIC are computed from the marginal log-likelihood (i.e. after
integrating out random effects), using the number of fixed-effect
parameters as :
where is the marginal log-likelihood and is the total
number of data observations. These values will be NA when
optimize = FALSE was passed to fit_fims().
tidy.FIMSFit(), get_estimates(), fit_fims()
## Not run: data("data_big") data_4_model <- FIMSFrame(data_big) fit <- setup_default_parameters(data = data_4_model) |> initialize_fims(data = data_4_model) |> fit_fims(optimize = TRUE) glance(fit) # Compare sensitivity runs in one table dplyr::bind_rows( glance(age_only_fit) |> dplyr::mutate(model = "age_only"), glance(length_only_fit) |> dplyr::mutate(model = "length_only") ) ## End(Not run)## Not run: data("data_big") data_4_model <- FIMSFrame(data_big) fit <- setup_default_parameters(data = data_4_model) |> initialize_fims(data = data_4_model) |> fit_fims(optimize = TRUE) glance(fit) # Compare sensitivity runs in one table dplyr::bind_rows( glance(age_only_fit) |> dplyr::mutate(model = "age_only"), glance(length_only_fit) |> dplyr::mutate(model = "length_only") ) ## End(Not run)
Use methods::new() to set up a distribution within an existing module with
the necessary linkages between the two. For example, a fleet module will need
a distributional assumption for parts of the data associated with it, which
requires the use of initialize_data_distribution().
initialize_data_distribution( module, data_type = c("catch", "index", "age_comp", "length_comp"), uncertainty )initialize_data_distribution( module, data_type = c("catch", "index", "age_comp", "length_comp"), uncertainty )
module |
An identifier to a C++ fleet module that is linked to the data of interest. |
data_type |
A string specifying the type of data that the distribution will be fit to. Allowable types include "catch", "index", "age_comp", and "length_comp" and the default is catch. |
uncertainty |
A vector of strings specifying formulas for each data
point. See |
A reference class. is returned. Use methods::show() to view the various
Rcpp class fields, methods, and documentation.
## Not run: # Set up a new data distribution n_years <- 30 # Create a new fleet module fleet <- methods::new(Fleet) # Create a distribution for the fleet module sd_log <- rep(sqrt(log(0.01^2 + 1)), n_years) fleet_distribution <- initialize_data_distribution( module = fishing_fleet, uncertainty = glue::glue( "~dlnorm(meanlog = log_index_expected, sdlog = {sd_log})" ), data_type = "index" ) ## End(Not run)## Not run: # Set up a new data distribution n_years <- 30 # Create a new fleet module fleet <- methods::new(Fleet) # Create a distribution for the fleet module sd_log <- rep(sqrt(log(0.01^2 + 1)), n_years) fleet_distribution <- initialize_data_distribution( module = fishing_fleet, uncertainty = glue::glue( "~dlnorm(meanlog = log_index_expected, sdlog = {sd_log})" ), data_type = "index" ) ## End(Not run)
This function uses information from a parameter data frame that stores the
model specifications and aFIMSFrame object that stores the data to
instantiate, i.e., create an instance of a class, the required C++ modules.
Several C++ modules are needed to run a FIMS model and the required modules
will be different for each model type. For example, for a catch-at-age
model one needs to instantiate recruitment, growth, and maturity modules and
at least one fleet and population module.
initialize_fims(parameters, data)initialize_fims(parameters, data)
parameters |
A tibble returned from |
data |
An S4 object with the |
A list is returned with two elements, parameters and model. The list can
be passed to the input argument of fit_fims() to fit the model. The first
element of the list can also be passed to the parameters argument of
TMB::MakeADFun() if you wish to have more control over the model-fitting
process.
The model element of the returned list stores the instantiated C++ model
module, e.g., the results of methods::new(CatchAtAge) for a catch-at-age
model.
It is important that you only have one FIMS model initialized in your R
workspace at a time. Thus, after you initialize and fit the model, you should
run clear().
## Not run: # Prepare data for FIMS model data("data_big", package = "FIMS") data_4_model <- FIMSFrame(data_big) # Instantiate modules parameters_list <- setup_default_parameters(data = data_4_model) |> initialize_fims(data = data_4_model) clear() ## End(Not run)## Not run: # Prepare data for FIMS model data("data_big", package = "FIMS") data_4_model <- FIMSFrame(data_big) # Instantiate modules parameters_list <- setup_default_parameters(data = data_4_model) |> initialize_fims(data = data_4_model) clear() ## End(Not run)
Use methods::new() to set up a distribution within an existing module with
the necessary linkages between the two. For example, a recruitment
module, like the Beverton–Holt stock–recruit relationship, will need a
distribution associated with the recruitment deviations.
initialize_process_distribution( module, par, family = NULL, sd = tibble::tibble(value = 1, estimation_type = "fixed_effects") ) initialize_process_structure(module, par)initialize_process_distribution( module, par, family = NULL, sd = tibble::tibble(value = 1, estimation_type = "fixed_effects") ) initialize_process_structure(module, par)
module |
An identifier to a C++ fleet module that is linked to the data of interest. |
par |
A string specifying the parameter name the distribution applies
to. Parameters must be members of the specified module. Use
|
family |
A description of the error distribution and link function to
be used in the model. The argument takes a family class, e.g.,
|
sd |
A list of length two. The first entry is named |
A reference class. is returned. Use methods::show() to view the various
Rcpp class fields, methods, and documentation.
## Not run: # Set up a new process distribution # Create a new recruitment module recruitment <- methods::new(BevertonHoltRecruitment) # view parameter names of the recruitment module methods::show(BevertonHoltRecruitment) # Create a distribution for the recruitment module recruitment_distribution <- initialize_process_distribution( module = recruitment, par = "log_devs", family = gaussian(), sd = list(value = 0.4, estimation_type = "constant") ) ## End(Not run)## Not run: # Set up a new process distribution # Create a new recruitment module recruitment <- methods::new(BevertonHoltRecruitment) # view parameter names of the recruitment module methods::show(BevertonHoltRecruitment) # Create a distribution for the recruitment module recruitment_distribution <- initialize_process_distribution( module = recruitment, par = "log_devs", family = gaussian(), sd = list(value = 0.4, estimation_type = "constant") ) ## End(Not run)
Verbosity is set globally for FIMS using
options(rlib_message_verbosity = "quiet") to stop the printing of messages
from cli::cli_inform(). Using a global option allows for verbose to not
have to be an argument to every function. All cli::cli_abort() messages are
printed to the console no matter what the global option is set to.
is_fims_verbose()is_fims_verbose()
A logical is returned where TRUE ensures messages from cli::cli_inform()
are printed to the console.
# function is not exported ## Not run: FIMS:::is_fims_verbose() ## End(Not run)# function is not exported ## Not run: FIMS:::is_fims_verbose() ## End(Not run)
Check if an object is of class FIMSFit
is.FIMSFit(x)is.FIMSFit(x)
x |
Returned list from |
Family objects provide a convenient way to specify the details of the models
used by functions such as stats::glm(). These functions within this
package are not available within the stats package but are designed in a
similar manner.
lognormal(link = "log") multinomial(link = "logit")lognormal(link = "log") multinomial(link = "logit")
link |
A string specifying the model link function. For example,
|
An object of class family (which has a concise print method). This
particular family has a truncated length compared to other distributions in
stats::family().
family |
character: the family name. |
link |
character: the link name. |
a_family <- multinomial() a_family[["family"]] a_family[["link"]]a_family <- multinomial() a_family[["family"]] a_family[["link"]]
There is an accessor function for each data type needed to run a FIMS model.
A FIMS model accepts vectors of data and thus each of the model_*()
functions, where the star can be replaced with the data type separated by
underscores, e.g., weight_at_age. These accessor functions are the preferred
way to pass data to a FIMS module because the data will have the appropriate
indexing.
model_catch(x, fleet) ## S4 method for signature 'FIMSFrame' model_catch(x, fleet) ## S4 method for signature 'data.frame' model_catch(x, fleet) model_index(x, fleet) ## S4 method for signature 'FIMSFrame' model_index(x, fleet) ## S4 method for signature 'data.frame' model_index(x, fleet) model_age_comp(x, fleet) ## S4 method for signature 'FIMSFrame' model_age_comp(x, fleet) ## S4 method for signature 'data.frame' model_age_comp(x, fleet) model_length_comp(x, fleet) ## S4 method for signature 'FIMSFrame' model_length_comp(x, fleet) ## S4 method for signature 'data.frame' model_length_comp(x, fleet) model_weight_at_age(x) ## S4 method for signature 'FIMSFrame' model_weight_at_age(x) ## S4 method for signature 'data.frame' model_weight_at_age(x) model_age_to_length_conversion(x) ## S4 method for signature 'FIMSFrame' model_age_to_length_conversion(x) ## S4 method for signature 'data.frame' model_age_to_length_conversion(x)model_catch(x, fleet) ## S4 method for signature 'FIMSFrame' model_catch(x, fleet) ## S4 method for signature 'data.frame' model_catch(x, fleet) model_index(x, fleet) ## S4 method for signature 'FIMSFrame' model_index(x, fleet) ## S4 method for signature 'data.frame' model_index(x, fleet) model_age_comp(x, fleet) ## S4 method for signature 'FIMSFrame' model_age_comp(x, fleet) ## S4 method for signature 'data.frame' model_age_comp(x, fleet) model_length_comp(x, fleet) ## S4 method for signature 'FIMSFrame' model_length_comp(x, fleet) ## S4 method for signature 'data.frame' model_length_comp(x, fleet) model_weight_at_age(x) ## S4 method for signature 'FIMSFrame' model_weight_at_age(x) ## S4 method for signature 'data.frame' model_weight_at_age(x) model_age_to_length_conversion(x) ## S4 method for signature 'FIMSFrame' model_age_to_length_conversion(x) ## S4 method for signature 'data.frame' model_age_to_length_conversion(x)
x |
An object returned from |
fleet |
A string, or vector of strings, specifying the name of the
fleet(s) of interest that you want data for. The strings must
exactly match strings in the |
Age_to_length_conversion data, i.e., the proportion of age "a" that are
length "l", are used to convert lengths (input data) to ages (modeled) as
a way to fit length data without estimating growth.
model_catch()Returns a numeric vector of catch data (type "catch") for the
specified fleet(s).
model_index()Returns a numeric vector of index data (type "index") for the specified
fleet(s).
model_age_comp()Returns a numeric vector of age-composition data (type "age_comp") for the
specified fleet(s).
model_length_comp()Returns a numeric vector of length-composition data (type "length_comp")
for the specified fleet(s). This accessor requires that age-to-length
conversion data are present in the FIMSFrame object.
model_weight_at_age()Returns a numeric vector of weight-at-age observations (type
"weight_at_age"), ordered by age and year (plus one additional year) and
using -999 to indicate missing observations When multiple fleets are
present, values are averaged across fleets.
model_age_to_length_conversion()Returns a numeric vector of age-to-length conversion observations.
Observations are ordered by age and length in the order defined by
FIMSFrame(). When multiple observations are present across a single age
and length, they are averaged because age_to_length_conversion data cannot
vary across fleets or time.
All of the model_*() functions return vectors of data. Currently, the
order of the data is the same order as the data frame because no arranging
is done in FIMSFrame() and the function just extracts the appropriate
column.
Creates a visualization of likelihood profile results, displaying the change in log-likelihood as a function of a fixed parameter value. The plot shows profiles for different data components and the total likelihood, helping to assess parameter identifiability and uncertainty.
plot_likelihood(like_fit, group = "label")plot_likelihood(like_fit, group = "label")
like_fit |
A list returned by
|
group |
A character string or vector specifying the grouping variable(s)
for likelihood components. Default is |
Plot Likelihood Profile Results
The function generates line plots showing how the log-likelihood changes relative to its maximum value as a parameter is varied. Each data component (e.g., catch, index, age composition) is shown as a separate line, along with the total likelihood across all components. This reveals which data sources provide information about the parameter and whether there are conflicting signals.
The y-axis shows the change in log-likelihood from the maximum (best-fit) value. A parabolic shape indicates a well-identified parameter with symmetric uncertainty. Flat profiles suggest weak identifiability, while multiple local minima indicate potential convergence issues.
The plot automatically saves to "likelihood.png" in the current working directory in addition to returning a ggplot object that can be further customized. The total likelihood is shown in black as a solid line, while individual data components use colors from the viridis palette.
A ggplot object displaying likelihood profiles. The plot includes:
Line plots for each data component
Total likelihood across all components (black solid line)
Different colors (viridis palette) and line types for components
X-axis showing the profiled parameter values
Y-axis showing change in log-likelihood from maximum
NOAA-themed styling via stockplotr::theme_noaa()
The plot is also automatically saved as "likelihood.png".
Venzon, D.J. and Moolgavkar, S.H. 1988. A method for computing profile-likelihood-based confidence intervals. Applied Statistics 37: 87-94.
Hilborn, R. and Mangel, M. 1997. The Ecological Detective: Confronting Models with Data. Princeton University Press.
run_fims_likelihood() for running likelihood profile analysis
Other diagnostic_functions:
run_fims_likelihood(),
run_fims_retrospective()
## Not run: library(FIMS) # Use built-in dataset from FIMS data("data_big") data_4_model <- FIMSFrame(data_big) # Create parameters object parameters <- setup_default_parameters(data = data_4_model) # Run base model base_model <- parameters |> initialize_fims(data = data_4_model) |> fit_fims(optimize = TRUE) # Run likelihood profile like_fit <- run_fims_likelihood( model = base_model, parameters = parameters, data = data_big, parameter_name = "log_rzero", n_cores = 3, min = -1, max = 1, length = 21 ) # Plot the likelihood profile plot_likelihood(like_fit) # Plot with custom grouping plot_likelihood(like_fit, group = "label") ## End(Not run)## Not run: library(FIMS) # Use built-in dataset from FIMS data("data_big") data_4_model <- FIMSFrame(data_big) # Create parameters object parameters <- setup_default_parameters(data = data_4_model) # Run base model base_model <- parameters |> initialize_fims(data = data_4_model) |> fit_fims(optimize = TRUE) # Run likelihood profile like_fit <- run_fims_likelihood( model = base_model, parameters = parameters, data = data_big, parameter_name = "log_rzero", n_cores = 3, min = -1, max = 1, length = 21 ) # Plot the likelihood profile plot_likelihood(like_fit) # Plot with custom grouping plot_likelihood(like_fit, group = "label") ## End(Not run)
FIMSFrame objectUse ggplot2::geom_point() to plot summary information stored in the data
slot of the FIMSFrame class.
## S4 method for signature 'FIMSFrame,missing' plot(x, y, ...)## S4 method for signature 'FIMSFrame,missing' plot(x, y, ...)
x |
A |
y |
Unused (inherited from R base). |
... |
Unused (inherited from R base). |
A ggplot2 object is returned that uses stockplotr::theme_noaa().
There will be one panel per input type with fleet-specific information
denoted using colors.
## Not run: data("data_big", package = "FIMS") data_4_model <- FIMSFrame(data_big) plot(data_4_model) ## End(Not run)## Not run: data("data_big", package = "FIMS") data_4_model <- FIMSFrame(data_big) plot(data_4_model) ## End(Not run)
Intended for developers to remove test data to run the tests from fresh. Developers should run this function before testing if changes affect FIMS input or output.
remove_test_data()remove_test_data()
## Not run: remove_test_data() ## End(Not run)## Not run: remove_test_data() ## End(Not run)
This function processes the finalized FIMS JSON output and reshapes the parameter estimates into a structured tibble for easier analysis and manipulation.
reshape_json_estimates(model_output)reshape_json_estimates(model_output)
model_output |
A JSON object containing the finalized FIMS output as
returned from |
A tibble containing the reshaped parameter estimates. Parameters of
distributions for random effects, e.g., log_sd of the recruitment
deviations, are included with one row per parameter id under the module
that owns the vector they apply to.
This function processes the TMB std and reshapes them into a structured tibble for easier analysis and manipulation.
reshape_tmb_estimates( obj, sdreport = NULL, opt = NULL, parameter_names, precomputed_gradient = NULL )reshape_tmb_estimates( obj, sdreport = NULL, opt = NULL, parameter_names, precomputed_gradient = NULL )
obj |
An object returned from |
sdreport |
An object of the |
opt |
An object returned from an optimizer, typically from
|
parameter_names |
A character vector of parameter names. This is used to
identify the parameters in the |
precomputed_gradient |
A numeric vector of pre-computed gradient values
at the MLE, typically from |
A tibble containing the reshaped estimates (i.e., parameters and derived quantities).
Conducts likelihood profile analysis for a FIMS model by fixing a specified parameter at a range of values and re-optimizing all other parameters. This diagnostic tool helps assess parameter uncertainty, identifiability, and potential local minima in the likelihood surface.
run_fims_likelihood( model, parameters, data, module_name = NULL, parameter_name = "log_rzero", n_cores = NULL, min = -2, max = 2, length = 5 )run_fims_likelihood( model, parameters, data, module_name = NULL, parameter_name = "log_rzero", n_cores = NULL, min = -2, max = 2, length = 5 )
model |
A FIMSFit object returned by |
parameters |
A FIMS parameters object created by
|
data |
A data frame, tibble, or FIMSFrame object containing the model data. This should include all data types required by FIMS. |
module_name |
A character string specifying the module containing the
parameter to profile, as in the |
parameter_name |
A character string specifying the parameter to profile.
Default is |
n_cores |
An integer specifying the number of CPU cores to use for
parallel processing. If |
min |
A numeric value specifying the minimum offset from the estimated
parameter value. Default is |
max |
A numeric value specifying the maximum offset from the estimated
parameter value. Default is |
length |
An integer specifying the number of points in the likelihood
profile. Default is |
Run Likelihood Profile for a FIMS Model
Likelihood profiling involves systematically varying a parameter of interest across a range of values while optimizing all other parameters. At each fixed value, the negative log-likelihood is recorded, creating a profile of the likelihood surface. This reveals whether the parameter is well-estimated (sharp, parabolic profile) or poorly identified (flat profile), and can identify multiple modes or asymmetric confidence regions.
The function profiles over values specified relative to the estimated value
from the base model. For example, with min = -2 and max = 2, the profile
spans from 2 units below to 2 units above the estimated value. The profiled
values are evenly spaced on the parameter scale (not log scale).
Models are run in parallel for computational efficiency. Use module_name
when the same parameter label exists in more than 1 module. Parameters with
more than 1 row in a module (for example, 1 per fleet, year, or age) cannot
be profiled yet.
A list with two named elements:
vec - Numeric vector of parameter values used in the profile
estimates - Data frame containing model estimates for each profiled value,
with the following key columns:
label - Type of estimate (e.g., "spawning_biomass", "recruitment")
year_i - Year index for the estimate
age_i - Age index (if applicable)
estimated - Point estimate value
uncertainty - Standard error of the estimate
lpdf - Log probability density (negative log-likelihood component)
value_{parameter_name} - The fixed parameter value for this profile point
Venzon, D.J. and Moolgavkar, S.H. 1988. A method for computing profile-likelihood-based confidence intervals. Applied Statistics 37: 87-94.
Maunder, M.N. and Punt, A.E. 2013. A review of integrated analysis in fisheries stock assessment. Fisheries Research 142: 61-74.
plot_likelihood() for visualizing likelihood profiles
fit_fims() for fitting FIMS models
setup_default_parameters() for creating parameter objects
Other diagnostic_functions:
plot_likelihood(),
run_fims_retrospective()
## Not run: library(FIMS) # Use built-in dataset from FIMS data("data_big") data_4_model <- FIMSFrame(data_big) # Create a parameters object parameters <- setup_default_parameters(data = data_4_model) # Run the base model with optimization base_model <- parameters |> initialize_fims(data = data_4_model) |> fit_fims(optimize = TRUE) # Run likelihood profile for log_rzero like_fit <- run_fims_likelihood( model = base_model, parameters = parameters, data = data_big, parameter_name = "log_rzero", n_cores = 3, min = -1, max = 1, length = 21 ) # View the profiled parameter values like_fit$vec # View structure of estimates head(like_fit$estimates) ## End(Not run)## Not run: library(FIMS) # Use built-in dataset from FIMS data("data_big") data_4_model <- FIMSFrame(data_big) # Create a parameters object parameters <- setup_default_parameters(data = data_4_model) # Run the base model with optimization base_model <- parameters |> initialize_fims(data = data_4_model) |> fit_fims(optimize = TRUE) # Run likelihood profile for log_rzero like_fit <- run_fims_likelihood( model = base_model, parameters = parameters, data = data_big, parameter_name = "log_rzero", n_cores = 3, min = -1, max = 1, length = 21 ) # View the profiled parameter values like_fit$vec # View structure of estimates head(like_fit$estimates) ## End(Not run)
Performs retrospective analysis by fitting a FIMS model object multiple times, each time removing an increasing number of terminal years from the data. This diagnostic tool is used to detect retrospective patterns or bias in model estimates.
run_fims_retrospective(years_to_remove, data, parameters, n_cores = NULL)run_fims_retrospective(years_to_remove, data, parameters, n_cores = NULL)
years_to_remove |
A numeric vector specifying the number of terminal
years to remove for each retrospective peel. For example, |
data |
A data frame or FIMSFrame object containing the complete dataset used in the base model run. This should include all data types required by FIMS (catch, indices, composition data, biological data, etc.). |
parameters |
A FIMS parameters object created by
|
n_cores |
An integer specifying the number of CPU cores to use for
parallel processing. If |
Run Retrospective Analysis for a FIMS Model
Retrospective analysis involves refitting a model after sequentially removing one or more years of data from the end of the time series. This helps assess whether the model estimates are stable and whether there is a consistent pattern of revision as new data are added. The function runs models in parallel for computational efficiency.
The first element of years_to_remove should typically be 0 to represent
the reference model with no data removed. This allows for direct comparison
of retrospective peels to the base model.
Retrospective patterns can indicate model misspecification, time-varying
processes not captured by the model, or data quality issues. Mohn's rho,
calculated by calculate_mohns_rho(), provides a summary statistic for
retrospective bias.
A list with two named elements:
years_to_remove - The input vector of years removed for each peel
estimates - A data frame containing model estimates from all retrospective
runs, with the following key columns:
label - Type of estimate (e.g., "spawning_biomass")
year_i - Year index for the estimate
age_i - Age index (if applicable)
estimated - Point estimate value
uncertainty - Standard error of the estimate
retrospective_peel - Number of years removed for this peel
Mohn, R. 1999. The retrospective problem in sequential population analysis: An investigation using cod fishery and simulated data. ICES Journal of Marine Science 56: 473-488.
Hurtado-Ferro, F., et al. 2015. Looking in the rear-view mirror: bias and retrospective patterns in integrated, age-structured stock assessment models. ICES Journal of Marine Science 72(1): 99-110.
stockplotr::plot_spawning_biomass() for visualizing retrospective results
calculate_mohns_rho() for calculating Mohn's rho statistic
setup_default_parameters() for creating parameter objects
Other diagnostic_functions:
plot_likelihood(),
run_fims_likelihood()
## Not run: library(FIMS) # Use built-in dataset from FIMS data("data_big") data_4_model <- FIMSFrame(data_big) # Create a parameters object parameters <- setup_default_parameters(data = data_4_model) # Run base model base_model <- parameters |> initialize_fims(data = data_4_model) |> fit_fims(optimize = TRUE) # Run retrospective analysis with 5 peels retro_fit <- run_fims_retrospective( years_to_remove = 0:5, data = data_big, parameters = parameters, n_cores = 1 ) # View structure of results names(retro_fit) head(retro_fit$estimates) ## End(Not run)## Not run: library(FIMS) # Use built-in dataset from FIMS data("data_big") data_4_model <- FIMSFrame(data_big) # Create a parameters object parameters <- setup_default_parameters(data = data_4_model) # Run base model base_model <- parameters |> initialize_fims(data = data_4_model) |> fit_fims(optimize = TRUE) # Run retrospective analysis with 5 peels retro_fit <- run_fims_retrospective( years_to_remove = 0:5, data = data_big, parameters = parameters, n_cores = 1 ) # View structure of results names(retro_fit) head(retro_fit$estimates) ## End(Not run)
Intended for developers to run the google test suite from R.
run_gtest(...)run_gtest(...)
... |
Additional arguments to |
The output from running the tests should look something like the following:
Internal ctest changing into directory: C:/github/NOAA-FIMS/FIMS/build
Test project C:/github_repos/NOAA-FIMS_org/FIMS/build
Start 1: dlognorm.use_double_inputs
1/5 Test #1: dlognorm.use_double_inputs ....... Passed 0.04 sec
Start 2: dlognorm.use_int_inputs
2/5 Test #2: dlognorm.use_int_inputs .......... Passed 0.04 sec
Start 3: modelTest.eta
3/5 Test #3: modelTest.eta .................... Passed 0.04 sec
Start 4: modelTest.nll
4/5 Test #4: modelTest.nll .................... Passed 0.04 sec
Start 5: modelTest.evaluate
5/5 Test #5: modelTest.evaluate ............... Passed 0.04 sec
100% tests passed, 0 tests failed out of 5
If a test fails, the output will look something like the following:
Internal ctest changing into directory: C:/github/NOAA-FIMS/FIMS/build
Test project C:/github/NOAA-FIMS/FIMS/build
Start 1: dlognorm.use_double_inputs
1/7 Test #1: dlognorm.use_double_inputs ....... Passed 0.04 sec
Start 2: dlognorm.use_int_inputs
2/7 Test #2: dlognorm.use_int_inputs .......... Passed 0.04 sec
Start 3: modelTest.eta
3/7 Test #3: modelTest.eta .................... Passed 0.04 sec
Start 4: modelTest.nll
4/7 Test #4: modelTest.nll .................... Passed 0.04 sec
Start 5: modelTest.evaluate
5/7 Test #5: modelTest.evaluate ............... Passed 0.04 sec
Start 6: dlognormTest.DoubleInput
6/7 Test #6: dlognormTest.DoubleInput ......... Passed 0.04 sec
Start 7: dlognormTest.IntInput
7/7 Test #7: dlognormTest.IntInput ............***Failed 0.04 sec
86% tests passed, 1 tests failed out of 7
Total Test time (real) = 0.28 sec
The following tests FAILED:
7 - dlognormTest.IntInput (Failed)
Errors while running CTest
Output from these tests are in: C:/github/NOAA-FIMS/FIMS/build/Testing/Temporary/LastTest.log
Use "--rerun-failed --output-on-failure" to re-run the failed cases verbosely.
Function to remove a given number of years of data and run FIMS model. This function is called by run_fims_retrospective()
run_modified_data_fims(years_to_remove = 0, data, parameters)run_modified_data_fims(years_to_remove = 0, data, parameters)
years_to_remove |
number of years to remove |
data |
full dataset used in base model run |
parameters |
input parameters used in base FIMS model |
FIMS model fitted with years of data removed
## Not run: library(FIMS) # Use built-in dataset from FIMS data("data_big") data_4_model <- FIMSFrame(data_big) # Create a parameters object parameters <- setup_default_parameters(data = data_4_model) # Fit a FIMS model with 1 year of data removed fit <- run_modified_data_fims( years_to_remove = 1, data = data_big, parameters = parameters ) ## End(Not run)## Not run: library(FIMS) # Use built-in dataset from FIMS data("data_big") data_4_model <- FIMSFrame(data_big) # Create a parameters object parameters <- setup_default_parameters(data = data_4_model) # Fit a FIMS model with 1 year of data removed fit <- run_modified_data_fims( years_to_remove = 1, data = data_big, parameters = parameters ) ## End(Not run)
Modify a parameter input and run a FIMS model. This function is called by run_fims_likelihood()
run_modified_pars_fims( new_value, parameter_name, module_name = NULL, parameters, data )run_modified_pars_fims( new_value, parameter_name, module_name = NULL, parameters, data )
new_value |
The new value to be changed in the FIMS model. |
parameter_name |
A string specifying the parameter name to modify.
This should match a value in the |
module_name |
The name of module associated with the parameter to be changed. Default is NULL. |
parameters |
The tibble of input parameters for a FIMS model |
data |
A dataframe of input data for FIMS model |
FIMS model fitted to the new parameter input value
## Not run: library(FIMS) # Use built-in dataset from FIMS data("data_big") data_4_model <- FIMSFrame(data_big) # Create a parameters object parameters <- setup_default_parameters(data = data_4_model) # Fit a FIMS model with 1 year of data removed fit <- run_modified_pars_fims( new_value = 12.9, parameter_name = "log_rzero", parameters = parameters, data = data_big ) ## End(Not run)## Not run: library(FIMS) # Use built-in dataset from FIMS data("data_big") data_4_model <- FIMSFrame(data_big) # Create a parameters object parameters <- setup_default_parameters(data = data_4_model) # Fit a FIMS model with 1 year of data removed fit <- run_modified_pars_fims( new_value = 12.9, parameter_name = "log_rzero", parameters = parameters, data = data_big ) ## End(Not run)
Intended for developers to run the R integration tests.
run_r_integration_tests()run_r_integration_tests()
## Not run: run_r_integration_tests() ## End(Not run)## Not run: run_r_integration_tests() ## End(Not run)
Intended for developers to run the R unit tests.
run_r_unit_tests()run_r_unit_tests()
## Not run: run_r_unit_tests() ## End(Not run)## Not run: run_r_unit_tests() ## End(Not run)
Intended for developers to set up their local environment and run the google test suite from R.
setup_and_run_gtest(...)setup_and_run_gtest(...)
... |
Additional arguments to |
## Not run: setup_and_run_gtest("--rerun-failed --output-on-failure") ## End(Not run)## Not run: setup_and_run_gtest("--rerun-failed --output-on-failure") ## End(Not run)
This function sets up default parameters for a fleet module, including natural log of catchability coefficients (log_q) and fishing mortality (log_Fmort) for fleets. For fishing fleets, log_q is set to an estimation type of "constant" with a default value of 0, while log_Fmort is set to "fixed_effects". For survey fleets, log_q is set to "fixed_effects" and log_Fmort is set to "constant" with a default value of -200.
setup_default_Fleet(data, fleet)setup_default_Fleet(data, fleet)
data |
A |
fleet |
A character. Name of the fleet. |
The function builds module-specific defaults by calling helper functions for data, fleet, selectivity, recruitment, maturity, growth, and population components, then combines those defaults into one tibble. You can modify the returned tibble before fitting a model (for example, updating maturity and selectivity parameter values).
Growth defaults are chosen from the data. Models with empirical weight-at-age
data default to "EWAA". Models without empirical weight-at-age data but with
length-composition data default to "VonBertalanffySchnute".
To create the default initial numbers at age, this function uses the defaults
from setup_default_Population() and setup_default_Recruitment(), which
are passed to setup_default_init_naa() to calculate initial numbers at age.
A tibble containing the default fleet parameters. See setup_default_parameters
for full column descriptions.
## Not run: default_fleet_parameters <- setup_default_Fleet( data = FIMSFrame(data_big), fleet = "fleet1" ) ## End(Not run)## Not run: default_fleet_parameters <- setup_default_Fleet( data = FIMSFrame(data_big), fleet = "fleet1" ) ## End(Not run)
This function creates default growth parameters for a Fisheries Integrated Modeling System (FIMS) model. It generates a tibble with fields for module name, module type, label, value, and estimation type.
setup_default_Growth( data = NULL, module_type = c("EWAA", "VonBertalanffySchnute") )setup_default_Growth( data = NULL, module_type = c("EWAA", "VonBertalanffySchnute") )
data |
A |
module_type |
A character string specifying the type of growth module.
The default is |
A tibble containing default growth parameters. See setup_default_parameters
for full column descriptions.
## Not run: # Set up default growth parameters default_growth_parameters <- setup_default_Growth() ## End(Not run)## Not run: # Set up default growth parameters default_growth_parameters <- setup_default_Growth() ## End(Not run)
This function sets up default parameters for a maturity module.
setup_default_Maturity(data, module_type = c("Logistic"))setup_default_Maturity(data, module_type = c("Logistic"))
data |
A |
module_type |
A string specifying the type of maturity module. The available options are Logistic. |
The function builds module-specific defaults by calling helper functions for data, fleet, selectivity, recruitment, maturity, growth, and population components, then combines those defaults into one tibble. You can modify the returned tibble before fitting a model (for example, updating maturity and selectivity parameter values).
Growth defaults are chosen from the data. Models with empirical weight-at-age
data default to "EWAA". Models without empirical weight-at-age data but with
length-composition data default to "VonBertalanffySchnute".
To create the default initial numbers at age, this function uses the defaults
from setup_default_Population() and setup_default_Recruitment(), which
are passed to setup_default_init_naa() to calculate initial numbers at age.
A tibble containing default maturity parameters. See setup_default_parameters
for full column descriptions.
## Not run: default_maturity_parameters <- setup_default_Maturity( data = FIMSFrame(data_big), module_type = "Logistic" ) ## End(Not run)## Not run: default_maturity_parameters <- setup_default_Maturity( data = FIMSFrame(data_big), module_type = "Logistic" ) ## End(Not run)
Initializing a FIMS model, i.e., initialize_fims() requires a FIMSFrame
object and a tibble of parameters. The parameter tibble can be automatically
generated using this function or by building up your own tibble from
helper functions used within this function. The resulting tibble will have
all of the necessary parameters, specific to your data, to run a FIMS
model.
Initializing a FIMS model, i.e., initialize_fims() requires a FIMSFrame
object and a tibble of parameters. The parameter tibble can be automatically
generated using this function or by building up your own tibble from
helper functions used within this function. The resulting tibble will have
all of the necessary parameters, specific to your data, to run a FIMS
model.
setup_default_parameters(data)setup_default_parameters(data)
data |
A |
The function builds module-specific defaults by calling helper functions for data, fleet, selectivity, recruitment, maturity, growth, and population components, then combines those defaults into one tibble. You can modify the returned tibble before fitting a model (for example, updating maturity and selectivity parameter values).
Growth defaults are chosen from the data. Models with empirical weight-at-age
data default to "EWAA". Models without empirical weight-at-age data but with
length-composition data default to "VonBertalanffySchnute".
To create the default initial numbers at age, this function uses the defaults
from setup_default_Population() and setup_default_Recruitment(), which
are passed to setup_default_init_naa() to calculate initial numbers at age.
A tibble containing default parameter values and metadata for your model.
Key columns are listed below:
module_name:The name of the FIMS module (e.g., "Data", "Selectivity", "Recruitment", "Growth", "Maturity"). These entries are always written in PascalCase to match the names used in the C++ code.
fleet:The name of the fleet the module applies to. This
will be NA for non-fleet-specific modules like "Recruitment".
module_type:The specific type of the module (e.g., "Logistic" for a "Selectivity" module). This column will always be written in PascalCase to match the names used in the C++ code.
label:The parameter name (e.g., "inflection_point").
age:The age the parameter applies to.
length:The length bin the parameter applies to.
timing:The timing step (year) the parameter applies to.
value:The initial value of the parameter.
estimation_type:The estimation type (e.g., "constant", "fixed_effects", "random_effects").
distribution_type:The type of distribution (e.g., "data", "process"), where a process distribution can refer to a fixed effect or a random effect but it does not fit to data, e.g., recruitment deviation.
distribution:The distribution name (e.g., "Dlnorm", "Dmultinom"). This column will always be written in PascalCase to match the names used in the C++ code.
## Not run: # Load the example dataset and create a FIMS data frame data("data_big") fims_frame <- FIMSFrame(data_big) # Set up default parameters default_parameters <- setup_default_parameters(data = fims_frame) # Update selectivity parameters for survey1 updated_parameters <- default_parameters |> dplyr::rows_update( tibble::tibble( fleet = "survey1", label = c("inflection_point", "slope"), value = c(1.5, 2) ), by = c("fleet", "label") ) # Do the same as above except, model fleet1 with double logistic selectivity # To see required parameters for double logistic selectivity, run # show(DoubleLogisticSelectivity) and look at the Fields list parameters_with_double_logistic <- updated_parameters |> dplyr::filter(!(fleet == "fleet1" & module_name == "Selectivity")) |> dplyr::bind_rows( setup_default_Selectivity( data = fims_frame, fleet = "fleet1", module_type = "DoubleLogistic" ) ) ## End(Not run)## Not run: # Load the example dataset and create a FIMS data frame data("data_big") fims_frame <- FIMSFrame(data_big) # Set up default parameters default_parameters <- setup_default_parameters(data = fims_frame) # Update selectivity parameters for survey1 updated_parameters <- default_parameters |> dplyr::rows_update( tibble::tibble( fleet = "survey1", label = c("inflection_point", "slope"), value = c(1.5, 2) ), by = c("fleet", "label") ) # Do the same as above except, model fleet1 with double logistic selectivity # To see required parameters for double logistic selectivity, run # show(DoubleLogisticSelectivity) and look at the Fields list parameters_with_double_logistic <- updated_parameters |> dplyr::filter(!(fleet == "fleet1" & module_name == "Selectivity")) |> dplyr::bind_rows( setup_default_Selectivity( data = fims_frame, fleet = "fleet1", module_type = "DoubleLogistic" ) ) ## End(Not run)
This function sets up default parameters for a population module.
setup_default_Population( data, log_M = log(0.2), log_init_naa = NA_real_, proportion_female = 0.5 )setup_default_Population( data, log_M = log(0.2), log_init_naa = NA_real_, proportion_female = 0.5 )
data |
A |
log_M |
A numeric value or vector (length equal to the number of ages *
number of years) specifying the log natural mortality rate. Default is |
log_init_naa |
A numeric value or vector (length equal to the number of
ages) specifying the log initial numbers at age. Default is
for ages below the plus group, and for the plus group
|
proportion_female |
A numeric value between 0 and 1 specifying the
proportion of females. Default is |
The function creates a tibble of default population configurations, including log natural mortality rate, log initial numbers at age, and proportion of females. The function performs input checks to ensure that the provided arguments are valid.
A tibble of default population configurations, including initial numbers at
age, natural mortality rate, and proportion of females. See setup_default_parameters
for full column descriptions.
## Not run: default_population_parameters <- setup_default_Population(data = FIMSFrame(data_big)) ## End(Not run)## Not run: default_population_parameters <- setup_default_Population(data = FIMSFrame(data_big)) ## End(Not run)
This function sets up default parameters for a recruitment module.
setup_default_Recruitment( data, module_type = c("BevertonHolt"), distribution = c("Dnorm", NA_character_) )setup_default_Recruitment( data, module_type = c("BevertonHolt"), distribution = c("Dnorm", NA_character_) )
data |
A |
module_type |
A string specifying the type of recruitment model. The available options are BevertonHolt. |
distribution |
A string specifying the distribution for the recruitment process. The available options are Dnorm, NA. |
The function builds module-specific defaults by calling helper functions for data, fleet, selectivity, recruitment, maturity, growth, and population components, then combines those defaults into one tibble. You can modify the returned tibble before fitting a model (for example, updating maturity and selectivity parameter values).
Growth defaults are chosen from the data. Models with empirical weight-at-age
data default to "EWAA". Models without empirical weight-at-age data but with
length-composition data default to "VonBertalanffySchnute".
To create the default initial numbers at age, this function uses the defaults
from setup_default_Population() and setup_default_Recruitment(), which
are passed to setup_default_init_naa() to calculate initial numbers at age.
A tibble containing default recruitment parameters. See setup_default_parameters
for full column descriptions.
## Not run: default_recruitment_parameters <- setup_default_Recruitment( data = FIMSFrame(data_big), module_type = "BevertonHolt", distribution = "Dnorm" ) ## End(Not run)## Not run: default_recruitment_parameters <- setup_default_Recruitment( data = FIMSFrame(data_big), module_type = "BevertonHolt", distribution = "Dnorm" ) ## End(Not run)
This function sets up default parameters for a selectivity module.
setup_default_Selectivity( data, fleet, module_type = c("Logistic", "DoubleLogistic", "AgeSpecific") )setup_default_Selectivity( data, fleet, module_type = c("Logistic", "DoubleLogistic", "AgeSpecific") )
data |
A |
fleet |
A string specifying the name of the fleet for which selectivity parameters are being created. |
module_type |
A string specifying the desired form of selectivity. Allowable
forms include Logistic, DoubleLogistic, AgeSpecific
and the default is
Logistic.
See |
The function builds module-specific defaults by calling helper functions for data, fleet, selectivity, recruitment, maturity, growth, and population components, then combines those defaults into one tibble. You can modify the returned tibble before fitting a model (for example, updating maturity and selectivity parameter values).
Growth defaults are chosen from the data. Models with empirical weight-at-age
data default to "EWAA". Models without empirical weight-at-age data but with
length-composition data default to "VonBertalanffySchnute".
To create the default initial numbers at age, this function uses the defaults
from setup_default_Population() and setup_default_Recruitment(), which
are passed to setup_default_init_naa() to calculate initial numbers at age.
A tibble containing the default selectivity parameters. See setup_default_parameters
for full column descriptions.
## Not run: default_selectivity_parameters <- FIMS:::setup_default_Selectivity( data = FIMSFrame(data_big), fleet = "fleet1", module_type = "Logistic" ) ## End(Not run)## Not run: default_selectivity_parameters <- FIMS:::setup_default_Selectivity( data = FIMSFrame(data_big), fleet = "fleet1", module_type = "Logistic" ) ## End(Not run)
Intended for developers to set up their local environment prior to running the integration tests.
setup_gtest()setup_gtest()
## Not run: setup_gtest() ## End(Not run)## Not run: setup_gtest() ## End(Not run)
Returns one row per estimated parameter following the
generics::tidy() convention. Standard columns (term, estimate,
std.error, statistic, p.value) are always present; FIMS-specific
columns (module_name, module_id, estimation_type, gradient) are
appended so the full context is available for filtering and plotting.
## S3 method for class 'FIMSFit' tidy( x, parameters = c("fixed_effects", "random_effects"), conf.int = FALSE, conf.level = 0.95, ... )## S3 method for class 'FIMSFit' tidy( x, parameters = c("fixed_effects", "random_effects"), conf.int = FALSE, conf.level = 0.95, ... )
x |
A |
parameters |
Character vector controlling which |
conf.int |
Logical (default |
conf.level |
Numeric (default |
... |
Unused; present for S3 method compatibility. |
A tibble::tibble() with columns:
termParameter label (from label in get_estimates()).
estimatePoint estimate at the MLE.
std.errorStandard error from TMB::sdreport().
statisticWald z-statistic (estimate / std.error).
p.valueTwo-sided p-value for the z-test.
conf.low, conf.high
Confidence bounds (only when
conf.int = TRUE).
module_nameName of the FIMS module (e.g. "Selectivity").
module_idInteger module identifier.
estimation_typeOne of "fixed_effects", "random_effects",
or "derived_quantity".
gradientGradient of the log-likelihood at the MLE. Values close to zero indicate a well-converged parameter.
FIMS distinguishes three estimation_type values:
"fixed_effects"Directly optimized parameters (selectivity, log_Fmort, log_q, etc.).
"random_effects"Integrated-out random effects (log_devs, etc.).
"derived_quantity"Model outputs that are not parameters
(spawning biomass, expected catches, etc.). Uncertainty here comes from
the delta method via TMB::sdreport().
Pass any subset of these strings to parameters to control which rows are
returned.
statistic and p.value are computed as a two-sided Wald z-test:
z = estimate / std.error,
p = 2 * stats::pnorm(-|z|).
These are asymptotically valid for fixed effects under regularity
conditions; treat them as approximate for random effects and derived
quantities.
glance.FIMSFit(), get_estimates(), fit_fims()
## Not run: data("data_big") data_4_model <- FIMSFrame(data_big) fit <- setup_default_parameters( data = data_4_model ) |> initialize_fims(data = data_4_model) |> fit_fims(optimize = TRUE) # Fixed and random effects (default) tidy(fit) # Fixed effects only, with 95% confidence intervals tidy(fit, parameters = "fixed_effects", conf.int = TRUE) # All rows including derived quantities tidy(fit, parameters = c("fixed_effects", "random_effects", "derived_quantity")) ## End(Not run)## Not run: data("data_big") data_4_model <- FIMSFrame(data_big) fit <- setup_default_parameters( data = data_4_model ) |> initialize_fims(data = data_4_model) |> fit_fims(optimize = TRUE) # Fixed and random effects (default) tidy(fit) # Fixed effects only, with 95% confidence intervals tidy(fit, parameters = "fixed_effects", conf.int = TRUE) # All rows including derived quantities tidy(fit, parameters = c("fixed_effects", "random_effects", "derived_quantity")) ## End(Not run)
This helper function generates a Google Benchmark C++ template file for a
given workload and appends lines to tests/google_benchmark/CMakeLists.txt
to register the benchmark as a separate executable.
use_google_benchmark_template( name = "FileName_ClassName_FunctionName", type = c("simple", "fixture") )use_google_benchmark_template( name = "FileName_ClassName_FunctionName", type = c("simple", "fixture") )
name |
A string representing the name for the C++ benchmark file and
CMake executable target. It must follow the format
The generated file will be
|
type |
Benchmark template type. Use |
If successful, this function invisibly returns TRUE to allow for the
chaining of commands. If the function is unsuccessful, an error message is
returned.
Messages from the usethis package and cli indicate where the new file was
created and that the benchmark was registered in
tests/google_benchmark/CMakeLists.txt.
## Not run: # Create a new benchmark file and register it in CMake: FIMS:::use_google_benchmark_template( name = "Population_CatchAtAge_CatchNumbersAtAge" ) # Create a fixture-based benchmark template: FIMS:::use_google_benchmark_template( name = "Population_CatchAtAge_CatchNumbersAtAge", type = "fixture" ) ## End(Not run)## Not run: # Create a new benchmark file and register it in CMake: FIMS:::use_google_benchmark_template( name = "Population_CatchAtAge_CatchNumbersAtAge" ) # Create a fixture-based benchmark template: FIMS:::use_google_benchmark_template( name = "Population_CatchAtAge_CatchNumbersAtAge", type = "fixture" ) ## End(Not run)
This helper function generates a GoogleTest (gtest) C++ template file for a
given function and appends lines to CMakeLists.txt to register the test.
use_gtest_template(name = "FileName_ClassName_FunctionName")use_gtest_template(name = "FileName_ClassName_FunctionName")
name |
A string representing the combined name for the C++ test file
and CMake executable target. It must follow the format
If the function is not a member of a class, use a placeholder for
The default is |
If successful, this function invisibly returns TRUE to allow for the
chaining of commands. If the function is unsuccessful, an error message is
returned.
Three messages are also returned from the usethis package, which is used by
this function. The first states where the FIMS project is on your computer.
The second states the file path of the newly created file. The file will not
be automatically opened. The third states the test has been registered in
tests/gtest/CMakeLists.txt.
## Not run: # Create a new test file named # "test_Logistic_LogisticSelectivity_Evaluate.cpp" for # `LogisticSelectivity::evaluate()` in # `inst/include/population_dynamics/selectivity/functors/logistic.hpp`. FIMS:::use_gtest_template(name = "Logistic_LogisticSelectivity_Evaluate") ## End(Not run)## Not run: # Create a new test file named # "test_Logistic_LogisticSelectivity_Evaluate.cpp" for # `LogisticSelectivity::evaluate()` in # `inst/include/population_dynamics/selectivity/functors/logistic.hpp`. FIMS:::use_gtest_template(name = "Logistic_LogisticSelectivity_Evaluate") ## End(Not run)
This helper function creates a new test file for testthat using a template
available within the templates folder of this package. The test file is
created under the "tests/testthat" directory with a name based on the input
argument name. If the test file already exists, an error message is
returned and no changes are made.
use_testthat_template(name)use_testthat_template(name)
name |
A character string providing the name of the R function that you
want to test. The name will be used to create the file name, i.e.,
|
There are three minimum testing criteria for FIMS, which should be validated for every R function within the package. The template file sets up a section for each of the three following test criteria:
Input and output correctness (IO correctness): ensure that the function behaves as expected with correct inputs and returns the expected outputs.
Edge-case handling (Edge handling): validate the function's performance with invalid inputs and unusual scenarios.
Built-in errors and warnings (Error handling): confirm that appropriate error and warning messages are triggered under exceptional conditions.
Above every expectation within the test file there should be a call to
#' @description that fits on one line describing the test. The information
will be used in the bookdown report of the testing results.
If successful, this function invisibly returns TRUE to allow for the
chaining of commands. If the function is unsuccessful, an error message is
returned.
Two messages are also returned from the usethis package, which is used by this function. The first states where the FIMS project is on your computer. The second states the file path of the newly created file. The file will not be automatically opened.
# Create a new test file named "test-new_function" for `new_function()` ## Not run: FIMS:::use_testthat_template("new_function") ## End(Not run)# Create a new test file named "test-new_function" for `new_function()` ## Not run: FIMS:::use_testthat_template("new_function") ## End(Not run)