Skip to content

Plot likelihood components - #538

Open
JZahner1 wants to merge 66 commits into
nmfs-ost:mainfrom
JZahner1:plot_likelihoods
Open

JZahner1 wants to merge 66 commits into
nmfs-ost:mainfrom
JZahner1:plot_likelihoods

Conversation

@JZahner1

@JZahner1 JZahner1 commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

What is the feature?

  • Plot likelihood components

How have you implemented the solution?

  • Generate a bar plot of likelihood components. Users can optionally plot fleet specific components as well as summarize total fleet specific contributions to the total likelihood.

Does the PR impact any other area of the project, maybe another repo?

NOTES TO PROJECT MAINTAINERS

This feature required updating conout_ss3 to read likelihood information into the standard stockplotr format. This was accomplished ONLY for models that are run through r4ss::SS_getoutput(). It DOES NOT work for cases where the user supplies a "Report.sso" file to be read in directly.

Furthermore, it DOES NOT work with example_data, as that dataset would need to be reconverted and compiled to add the required likelihood information. Doing this also leads to the module names changing (as the module names that are used when an r4ss object is passed to conout_ss3 vs a 'Report.sso' file are different), and has large scale, downstream, consequences on many tests.

Datasets from other model types (BAM, RCeattle, and FIMS) also do not report likelihood components in a way that is compatible with what was implemented here and thus do not function with this plot at this time.

THIS IS AN SS3 ONLY PLOT FOR NOW.

Close #486

PR contribution checklist

Thank you for contributing to stockplotr! Please check the boxes below to confirm this pull request (PR) is ready for review. Edit this PR description to add the release indicator and any explanations.

  • I have read and adhered to the contributor guide.
  • I have kept this PR focused on one plot where applicable. For multiple features, I have used separate PRs (stacked PRs are welcome if needed).
  • I have aimed to keep this PR to no more than 750 lines, excluding tests and example data (for example, up to 750 lines for a new function).
  • If I have provided an example dataset, I have explained why the existing sample datasets are not sufficient.
  • I have tested that my changes are compatible with all example outputs in the "data" folder (example_data.rda; pollock.rda; ss3_simple.rda; vermilion_snapper.rda).
  • If I didn't follow the development workflow, I have explained why in this PR.
  • If applicable, I've added the plot to save_all_plots() and updated the associated tests in test-save_all_plots.R.
  • After opening this PR, I have checked that my own tests and spellcheck pass (spelling::spell_check_package()). If other checks fail, I have flagged them for the package maintainers to help diagnose and remedy.
  • I have requested review from one package maintainer (Sam or Sophie).

currently only works for r4ss formatted inputs
Create bar chart of likelihood components
…" column

This is inline with how other models are converted
Order fleets in the plot data as "Total" (if calculated), followed by the fleets in the order they appear in the data.
…resent

when present, likelihood components for multiple models are plotted side-by-side, as a grouped barchart, allowing for comparison of likelihood components across models
currently only works for r4ss formatted inputs
Create bar chart of likelihood components
…" column

This is inline with how other models are converted
Order fleets in the plot data as "Total" (if calculated), followed by the fleets in the order they appear in the data.
…resent

when present, likelihood components for multiple models are plotted side-by-side, as a grouped barchart, allowing for comparison of likelihood components across models
@JZahner1

Copy link
Copy Markdown
Collaborator Author

Not sure why the commits duplicated again. I used rebase this time...

@JZahner1

Copy link
Copy Markdown
Collaborator Author

This is the same failing test that is reported by #520. I think this has been fixed in other pending PRs already.

Comment thread R/plot_likelihoods.R Resolved
Comment thread R/plot_likelihoods.R Resolved
Comment thread R/plot_likelihoods.R Resolved
@JZahner1

Copy link
Copy Markdown
Collaborator Author

@Schiano-NOAA are we okay with merging this in now even though its only implemented for SS3 datasets?

@Schiano-NOAA

Copy link
Copy Markdown
Collaborator

Ideally I would like it for other models as well. I am working on testing now so not merging at this moment.

@JZahner1

JZahner1 commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator Author

@Schiano-NOAA BAM does come with likelihood values but in a different format than SS3 and RCeattle. I am working on adding support for them.

BAMs likelihoods are reported at the fleet-level only. This is different than SS3 (and now RCeattle) which report both fleet-specific likelihood components and fleet-aggregated likelihoods. In the case of SS3 this happens natively. I implemented the aggregation step for RCeattle models manually.

Is aggregating fleet-specific data something that we want to be doing? If yes, is it something that convert_output should handle, or something we should try to detect in plot_likelihoods and handle there?

@Schiano-NOAA

Copy link
Copy Markdown
Collaborator

I am not the best person to ask regarding aggregating the fleet data. Maybe @nmfs-ost/asar-collaborators has any thoughts on this?

However, I don't think this should be done in the convert_output function. It should be done in the plot_likelihoods function so its more easily traceable especially if this isn't done for every model.

@iantaylor-NOAA

Copy link
Copy Markdown
Contributor

I like the idea of aggregating at the plotting stage.

One thing I'm excited about with FIMS is that the single dataframe output provides easy access to likelihood values for each observation which will make it ease of showing the impact on the likelihoods for a specific subset of the data. This will help answer questions like "How does adding new ages from recent years impact the fit to the age data from the early years with or without an additional time-block on selectivity?" This works best if you do all the aggregation in the plotting function because the user could filter the output by year (or any other category) before passing it to the plot.

currently only works for r4ss formatted inputs
Move likelihood information to "likelihood" column to mtch with FIMS output style
@JZahner1

JZahner1 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

@Schiano-NOAA this SHOULD now work for all 4 supported model types. It needs a full re-review.

@JZahner1
JZahner1 requested a review from Schiano-NOAA December 3, 2026 23:27

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feat]: include plot for likelihood components

3 participants