Repository navigation
create initial versions of composition plots - #424
ericward-noaa wants to merge 9 commits into
Conversation
Added new entries to the WORDLIST file.
- change example / diagnostic dataset from simulated to big skate - added more plots from ian's list - more / better tests
|
@ericward-noaa is this ready for review? |
|
Yes @Schiano-NOAA I think so |
| ) | ||
|
|
||
| # Reshape r4ss composition databases to stockplotr's snake_case columns | ||
| tidy_dbase <- function(dbase, comp_type, fleet_names) { |
There was a problem hiding this comment.
convert_output() accepts the returned value from r4ss::ss_output() called replist in this example so this step should not be neccessary
| #' `aggregate = TRUE` instead sums the compositions across years so that each | ||
| #' fleet is summarized in a single panel. | ||
| #' | ||
| #' @param dat A data frame of composition data in any format accepted by |
There was a problem hiding this comment.
This should be the standard output framework from convert_output(). prepare_comp_data() can be called inside of this function as done with all other functions in {stockplotr}. This ensures this function works with all assessment models compatible with convert_output() (BAM, FIMS, SS3, and Rceattle).
There was a problem hiding this comment.
I changed this per your suggestion in this commit: 2fc6036
| #' created for every fleet and year combination; use `fleet` to focus on one | ||
| #' fleet at a time. | ||
| #' | ||
| #' @section r4ss equivalent: `r4ss::SSplotComps()` subplot 1 (by year) and |
There was a problem hiding this comment.
this will need to be expanded for equivalent for other models which I can look into
There was a problem hiding this comment.
Changed this a little in this commit, but other models can be added eventually: 2fc6036
My main motivation in doing this is to show residuals / diagnostics for FIMS, and some of the plots are being brought over from SS.
| bins <- sort(unique(comps$bin)) | ||
| width <- if (length(bins) > 1) min(diff(bins)) else 1 | ||
|
|
||
| plt <- ggplot2::ggplot(comps, ggplot2::aes(x = .data$bin)) |
There was a problem hiding this comment.
Can you see this type of plot being used for anything else? In that case, this could be generalized in a separate function like plot_timeseries. If not, then no action.
| has_exp <- any(!is.na(means$mean_exp)) | ||
| has_se <- any(!is.na(means$se)) | ||
|
|
||
| # Francis weights by fleet. As in Stock Synthesis and |
There was a problem hiding this comment.
Do other regions use this as well?
| #------------------------------------------------------------------------------ | ||
|
|
||
| # Prepare comps and keep rows with residuals, or abort with a hint | ||
| comp_residuals_or_abort <- function(dat, comp_type = NULL, fleet = NULL) { |
There was a problem hiding this comment.
helpers should go into the utils_plot.R file or can shift into the utils_comp.R file in this PR
| ) | ||
| } | ||
|
|
||
| caption <- NULL |
There was a problem hiding this comment.
We can set up a space in the csv that holds captions and alternative text for figures that can be called and made into an RDA which is a cundle of the plot, caption, and alternative text that can be incorporated into a report or other thing.
There was a problem hiding this comment.
Could you expand on the use of this data set with the exception of using it for the comps plots? We the test data set for all examples in the package, example_data. I have an open PR to expand them to have samples for each model that is compatible with the convet_output function.
There was a problem hiding this comment.
Good question. I initially was going to use example_data, but couldn't because the composition plots need the observed and expected proportions in each bin. I used the Big Skate example because it's the one used in the r4ss example plots (https://r4ss.github.io/r4ss/BigSkate/), so plots can be checked against r4ss
I think once the other PR is done and example_data is expanded to include each model, then the Big Skate datasets could be dropped
Schiano-NOAA
left a comment
There was a problem hiding this comment.
This works great for the skate example data and provides a good foundation for the comp plots. I have a series of comments and questions and comments that need to be answered. If you don't have the bandwidth to make this work with the standard output, then I can take over from here. I think some of the issue is due to a divergence of the FIMS output and standard output which is not our intention and will be resolved by the end of the year.
I also am wondering how standard some of these approaches are. I apologize for my ignorance on this topic and would be interested to hear if this is done across the board or just the decision made for comp plots for FIMS or specific regions.
There are also some other minor things like function naming and locations that can easily be adjusted.
I thank you so much for this important contribution to {stockplotr} and cannot stress enough the help this brings to our team 😄
|
Thanks for the review @Schiano-NOAA -- I think most of these are pretty minor, and I"ll start to push changes to address them. I'll tag you when ready for re-review |
This PR is related to this FIMS discussion, NOAA-FIMS/FIMS#1873, and this
r4ssissue r4ss/r4ss#1104 (comment), the need to generate composition plots.Copilot summary:
This pull request adds a comprehensive set of tools for visualizing and diagnosing composition data (age/length) in fisheries stock assessment, including new plotting functions, example data, and extensive documentation. The main changes are the introduction of new plotting functions for composition data and their documentation, the addition of a simulated example dataset, and updates to the package exports and documentation to support these features.
New composition plotting and diagnostics functionality:
Added new plotting functions for composition data:
plot_comp,plot_comp_bubble,plot_comp_mean,plot_comp_residuals, andplot_comp_sex_ratio, along with a data preparation functionprepare_comp_data. These functions provide a variety of diagnostic plots for observed and expected age/length compositions, including bubble plots, mean trends, Pearson residuals, and sex ratio plots. [1] [2]Added man page documentation for all new functions, describing their usage, arguments, outputs, and examples:
plot_comp.Rd,plot_comp_bubble.Rd,plot_comp_mean.Rd,plot_comp_residuals.Rd,plot_comp_sex_ratio.Rd, andprepare_comp_data.Rd. [1] [2] [3] [4] [5] [6]Example data and reproducibility:
example_comp_data(with generation code and documentation) to demonstrate the composition plotting functions. This data includes sex-specific age compositions for a fishery and a survey, with known patterns of misfit for testing diagnostics. [1] [2] [3]Documentation and navigation updates:
These changes significantly expand the package's capabilities for composition data analysis and provide users with tools and guidance for diagnosing model fit to age/length compositions.