Add getMeanLength() and report the weight-length defaults - #576
Merged
Conversation
getMeanLength() is the counterpart of getMeanWeight() and shares its man page, now titled "Calculate the mean size of the community". It divides the total length of all individuals in the selected species and size range by their number, converting weight to length with each species' `a` and `b`. The integral goes through sizeIntegral(), so it follows the model's own quadrature and is tested under both schemes. Writing it showed that the length-weight defaults `a = 0.01` and `b = 3` were filled in silently. They are now reported like mizer's other defaults, and setFishing() reports them a second time when a gear selects on length, which is the case where an invented weight-length relationship changes the dynamics rather than just a diagnostic. Whether a gear selects on length is read off the selectivity function's formals, so a custom sel_func taking species_params is covered too. Also corrects the build-model guide, which said the defaults were 0.006 and 3. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Over the full size range the mean is dominated by the larvae, and for the mean length it extrapolates the length-weight relationship far below the sizes it was fitted to. Say so on the man page and lead the examples with a minimum size, which is also what makes the indicator comparable to one calculated from survey data. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
gustavdelius
force-pushed
the
getMeanLength-and-length-weight-defaults
branch
from
August 27, 2026 12:16
62ca04c to
e231409
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
getMeanLength()The counterpart of
getMeanWeight(), sharing its man page under the new titleCalculate the mean size of the community. It divides the total length of all
individuals in the selected species and size range by their number:
The integral goes through
sizeIntegral()with the species × size length matrixas the weighting factor, so the size-range mask, the bin-averaging under
second_order_w(bin_average = TRUE)and theMizerParams/MizerSimshapehandling all come for free, and the bin integral is still performed in exactly
one place. Methods for both classes, plus the internal helper
length_at_size(), which errors ifa/bare missing orNAasget_size_range_array()does.Reporting the weight-length defaults
Writing that showed
a = 0.01andb = 3were being filled in silently.At the point the default is filled in —
species_params.data.frame()nowpasses a
messagetoset_species_param_default(), which is the existingmechanism (
signal_info(),severity = "info",level = 3), so the reportsits alongside the ones for
h,gammaandks:At the point the conversion happens —
calc_selectivity()reports a gearwhose selectivity is set from a length while the species'
aorbwasdefaulted. That is the case where an invented weight-length relationship changes
the dynamics rather than just a diagnostic, so it is
level = 1(survives thesetting that silences the routine chatter) and
unhandled = "show"(bothsetFishing()andcalc_selectivity()are exported and get called outside anywith_info_level()). It names only the affected species and only the parameterthat was actually missing. Whether a gear selects on length is read off the
selectivity function's formals — mizer hands a selectivity function the species
parameters only so it can convert between length and weight — so a custom
sel_functakingspecies_paramsis covered, andknife_edge/sigmoid_weightnever trigger it.Why it is worth saying:
a = 0.01, b = 3with weights in grams and lengths incm is Fulton's K = 1, the textbook fusiform fish. The exponent is a good
default, but
afollows body shape over about two orders of magnitude. Againstthe twelve North Sea species shipped with mizer (fitted
a= 0.001–0.010,b= 2.94–3.43) the default gives lengths 1–42% short at a weight of 1 g — 35%short for the eel-like Sandeel.
Documentation
NEWS.md; new section ininst/skills/upgrade-mizer-code/references/mizer-3.4.mdwith two rows in the symptom index;
getMeanLength()added to theanalyse-and-plot skill and quick reference;
inst/llms.txt/docs/llms.txt;guides regenerated with
build_guides().inst/skills/build-model/SKILL.md, which said the defaults were0.006and3— wrong since 0b5b661 introduceda = 0.01, and it feeds thepublished guide.
Testing
devtools::test()on this commit: FAIL 0 | WARN 0 | SKIP 49 | PASS 4937.New tests in
test-indicator_functions.R(MizerSimandMizerParamsagainsthand-rolled sums, the
min_l/min_wequivalence, thea = b = 1case wheremean length must equal mean weight, both error paths),
test-second_order_summary.R(the required
bin_average = TRUEtest),test-species_params.Randtest-setFishing.R(the two reports, and silence when the parameters aresupplied or the gear selects on weight).
🤖 Generated with Claude Code