Skip to content

[Feature] Add Rceattle as compatible model in convert_output(...)#209

Open
Schiano-NOAA wants to merge 27 commits into
mainfrom
conout-rceattle
Open

[Feature] Add Rceattle as compatible model in convert_output(...)#209
Schiano-NOAA wants to merge 27 commits into
mainfrom
conout-rceattle

Conversation

@Schiano-NOAA
Copy link
Copy Markdown
Collaborator

@Schiano-NOAA Schiano-NOAA commented Mar 16, 2026

Allow users to standardize Rceattle output and standardize naming conventions from elements in the model output object.

Plan release for v0.11.0

@Schiano-NOAA Schiano-NOAA linked an issue Mar 16, 2026 that may be closed by this pull request
5 tasks
@github-actions
Copy link
Copy Markdown
Contributor

New version checklist

  • Package version in DESCRIPTION has been updated
  • Release notes have been drafted/published
  • Cheatsheet content has been updated (if applicable)
  • Cheatsheet version has been updated

@github-actions
Copy link
Copy Markdown
Contributor

Code Metrics Report

Coverage Code to Test Ratio Test Execution Time
68.3% 1:0.1 4m42s

Code coverage of files in pull request scope (52.8%)

Files Coverage
R/convert_output.R 53.7%
R/utils.R 42.1%

Reported by octocov

@Schiano-NOAA Schiano-NOAA changed the base branch from main to dev April 9, 2026 20:36
@Schiano-NOAA
Copy link
Copy Markdown
Collaborator Author

Schiano-NOAA commented Apr 10, 2026

Edits:

  • Change name from total+mortality to total_mortality
  • Add indices into converter (data.list$index_data)
  • Align catch_h with indexing from data.list$catch_data
  • Align indexing for quantities$age_hat with data.list$comp_data

Note: I was unable to align log_index_hat with catch since they are different lengths of data, 101 and 74, respectively

@Schiano-NOAA Schiano-NOAA changed the title Add Rceattle as compatible model in convert_output(...) [Feature] Add Rceattle as compatible model in convert_output(...) May 5, 2026
Base automatically changed from dev to main May 8, 2026 14:11
@Schiano-NOAA Schiano-NOAA force-pushed the main branch 2 times, most recently from b057594 to 5cabc07 Compare May 8, 2026 14:30
@Schiano-NOAA Schiano-NOAA marked this pull request as ready for review May 8, 2026 20:35
@Schiano-NOAA Schiano-NOAA added enhancement New feature or request labels May 11, 2026
@Schiano-NOAA
Copy link
Copy Markdown
Collaborator Author

To test, run the following code then use the "x_model" environment objects as the dat argument in convert_output()

# Required dependencies (CRAN)
install.packages("TMB", type = "source")
install.packages("Matrix", type = "source")
install.packages("devtools")

# Rceattle (pulls remaining CRAN dependencies automatically)
devtools::install_github("grantdadams/Rceattle")

# Optional: TMBhelper provides richer optimization diagnostics.
# Rceattle falls back to plain nlminb + sdreport if it's not installed.
# devtools::install_github("kaskr/TMB_contrib_R/TMBhelper")

################################################
# Load packages
################################################

library(Rceattle)
library(readxl)

################################################
# Load data
################################################

# Pollock
data("GOApollock")
# Differences between CEATTLE and SAFE: the SAFE model penalizes the first 7 and last recruitment deviates, while I penalize them all. Besides that its parameterized the exact same.

# Cod
data("GOAcod")
GOAcod$maturity[1,2:13] <- 2 # Spawn wt from SS model includes sex-ratio and maturity already, so setting Pmature (age-at-maturity) to 2 to have CEATTLE calculations be the same
# The cod model was  a bit trickier to recreate because of the use of internal age-length estimation/conditional age-at-length and more flexible selectivity parameterization than I currently have set up in CEATTLE. I use the output weight-at-age, mortality, and terminal year age-length-key from SS as inputs into CEATTLE and set age-based selectivity in CEATTLE to be the form that is most similar to the terminal year length-based selectivity pattern in SS. I fit the same index, catch, and length-at-age data as well as marginal age- and length-comp data that the SAFE model doesn't fit. I ignore annual varying selectivity (you could do it in CEATTLE... see meta_data sheet in the Excel file, I just stopped trying after some convergence issues). I ignored the aging error (could add in, but was having convergence problems). I also do not use the Taylor and Methot 2013 recruitment bias correction thats in SS and did not have a 2016 bump in mortality from the blob.

# ATF
data("GOAatf")
# Differences between CEATTLE and SAFE: ATF composition sample sizes and non-parametric selectivity penalties are the same for each sex while they are different in the SAFE model (differences between sexes for both bits are < 5 in the SAFE model. This was a convenience for coding


################################################
# Fit models
################################################

# Pollock
GOApollock$styr = 1977 # The SAFE model starts at 1970, so change styr to 1970 to run the full time series model (data is in there). I start them all at 1977 because thats the years with overlap.
pollock_model <- Rceattle::fit_mod(
  data_list = GOApollock,
  inits = NULL, # Initial parameters = 0
  file = NULL, # Don't save
  estimateMode = 0, # 0 = Estimate, 1 = Dont run estimation
  random_rec = FALSE, # No random recruitment
  msmMode = 0, # 0 = Single species mode, 1 = MSVPA multi-species mode
  verbose = 1, # Silence optimization output
  phase = TRUE) # Use default phasing


# Arrowtooth flounder
GOAatf$styr = 1977 # The SAFE model starts at 1961, so change styr to 1961 to run the full time series model (data is in there). I start them all at 1977 because thats the years with overlap.
atf_model <- Rceattle::fit_mod(
  data_list = GOAatf,
  inits = NULL, # Initial parameters = 0
  file = NULL, # Don't save
  estimateMode = 0, # 0 = Estimate, 1 = Dont run estimation
  random_rec = FALSE, # No random recruitment
  msmMode = 0, # 0 = Single species mode, 1 = MSVPA multi-species mode
  verbose = 1, # Silence optimization output
  phase = TRUE) # Use default phasing


# Cod
# -- Cod start year is 1977 so no need to change
cod_model <- Rceattle::fit_mod(
  data_list = GOAcod,
  inits = NULL, # Initial parameters = 0
  file = NULL, # Don't save
  estimateMode = 0, # 0 = Estimate, 1 = Dont run estimation
  random_rec = FALSE, # No random recruitment
  msmMode = 0, # 0 = Single species mode, 1 = MSVPA multi-species mode
  verbose = 1, # Silence optimization output
  phase = TRUE) # Use default phasing

# Reweighting the cod model helps using Macalliser Ianelli weights
GOAcod$fleet_control$Comp_weights <- cod_model$data_list$fleet_control$Est_weights_macallister

# -- Refit
cod_model <- Rceattle::fit_mod(
  data_list = GOAcod,
  inits = cod_model$estimated_params, # Start from the unweighted model's MLEs
  file = NULL, # Don't save
  estimateMode = 0, # 0 = Estimate, 1 = Dont run estimation
  random_rec = FALSE, # No random recruitment
  msmMode = 0, # 0 = Single species mode, 1 = MSVPA multi-species mode
  verbose = 1, # Silence optimization output
  phase = TRUE) # Phase

@Schiano-NOAA
Copy link
Copy Markdown
Collaborator Author

@sbreitbart-NOAA I will leave it up to you if you want to test this functionality. The download process to get the example data can be long. Otherwise, feel free to review the rest of this PR. Thanks!

On another thought: maybe I could add the rceattle data as another test input into {stockplotr}?

@Schiano-NOAA Schiano-NOAA self-assigned this May 11, 2026
@Schiano-NOAA Schiano-NOAA modified the milestone: v0.11.0 May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add functionality in convert_output for Rceattle

1 participant