Introduction
Achieving a steady state that matches observed biomasses and growth
rates is a critical step in MizerReef model development.
This vignette provides a step-by-step recipe for tuning a
MizerReef model to reach a satisfactory steady state, using
the Karpata reef example dataset.
The tuning process follows the 5-step recipe described in the mizer blog, with additional reef-specific steps to adjust unstructured resource parameters and refuge dynamics.
Prerequisites
Before starting, ensure you have:
- Species parameter data with reef-specific columns
- An interaction matrix defining predator-prey relationships
- Observed biomass data for calibration
- A suitable refuge profile for initial tuning
Step 1: Create the Initial Parameters Object
The first step is to create a MizerReefParams object
using your species parameters and interaction matrix. For initial
tuning, we use a simple binned refuge method rather than the full
competitive method.
Why use a tuning profile first? The competitive refuge method is density-dependent, which makes it difficult to achieve a stable steady state before the biomasses are calibrated to observed values. We start with a simpler constant binned profile so that we can tune abundances first.
# Create initial parameters object with tuning refuge profile
params <- newReefParams(species_params = caribbean_10_species,
interaction = caribbean_10_interaction,
method = "binned",
method_params = tuning_profile)
#> ℹ No h provided for some species, so using age at maturity to calculate it.
#> ℹ Using z0 = z0pre * w_inf ^ z0exp for calculated z0 values.
#> ℹ Using f0, h, lambda, kappa and the predation kernel to calculate gamma.
#> Warning: `kappa` is still at mizer's uncalibrated default (1e11) while
#> `biomass_observed` is set. `gamma` has been derived to match this placeholder
#> resource scale, so encounter with real fish/invert prey will be numerically
#> negligible until the model's scale is calibrated -- run
#> `calibrateReefBiomass()` before `matchReefGrowth()`/ `matchBiomasses()`, or
#> predators may converge on the right total biomass while eating ~0% fish prey.These messages let us know when a default value was used for some parameter you didn’t provide, and they come from two different places:
-
mizer’s own defaults – search volume
(
gamma), maximum consumption rate (h), and the like. These are exactly what you’d see callingmizer::newMultispeciesParams()directly; see mizer’s Setting Parameters reference page for what each one is and how it’s calculated. -
mizerReef’s own defaults –
refuge_user,satiation,algae_growth_initialand the rest of the reef-specific mechanism, listed invignette("mizerReef")’s [Setting species parameters] and [Creating your first model] sections and invignette("tuning-diet-composition").
Either way, you can change the value later if you have a better
estimate, using species_params() or one of the
set*() functions.
With a full species table, this wall of messages gets long.
newReefParams() (and every other model-building function in
mizerReef) takes an info_level argument to control it:
info_level = 1 keeps only the reports that say something
went differently from what you actually asked for (dropping the routine
default-value fills), and info_level = 0 is silent. For
example:
params <- newReefParams(species_params = caribbean_10_species,
interaction = caribbean_10_interaction,
method = "binned",
method_params = tuning_profile,
info_level = 1)Let’s examine the species groups and their key parameters:
Step 2: Find an Initial Steady State
Project the model forward to reach an initial steady state. This may
require multiple iterations of reefSteady().
# Project to steady state - multiple calls ensure convergence
params <- params |>
reefSteady() |> reefSteady() |> reefSteady() |>
reefSteady() |> reefSteady() |> reefSteady()
#> ℹ Reached the convergence tolerance after 57 years. The biomasses change at up to 0.0035 per year.
#> ℹ Reached the convergence tolerance after 1.5 years. The biomasses change at up to 0.0029 per year.
#> ℹ Reached the convergence tolerance after 1.5 years. The biomasses change at up to 0.0024 per year.
#> ℹ Reached the convergence tolerance after 1.5 years. The biomasses change at up to 0.002 per year.
#> ℹ Reached the convergence tolerance after 1.5 years. The biomasses change at up to 0.0017 per year.
#> ℹ Reached the convergence tolerance after 1.5 years. The biomasses change at up to 0.0014 per year.
#> Warning: ! The flux of external detritus is negative.
#> ! The following species require an unrealistic value greater than 1 for `erepro`: pred_plank, farm_damsel
# Check convergence by plotting spectra
plotSpectra(params, biomass = TRUE) +
ggtitle("Initial steady state spectra")
If you’re having trouble reaching a steady state, consider providing
the species parameter R_max or adjusting the
reproduction_level like this:
# Set reproduction levels to 0.5 for all species
rdi <- rep(0.5, nrow(caribbean_10_species))
names(rdi) <- caribbean_10_species$species
params <- setBevertonHolt(params, reproduction_level = rdi)
#> Warning: The following species require an unrealistic value greater than 1 for
#> `erepro`: pred_plank, farm_damsel
# Check the reproduction levels
reproduction_levels <- getReproductionLevel(params)
kable(data.frame(Species = names(reproduction_levels),
Reproduction_Level = reproduction_levels),
caption = "Initial reproduction levels")| Species | Reproduction_Level | |
|---|---|---|
| pred_eng | pred_eng | 0.5 |
| pred_grab | pred_grab | 0.5 |
| eels | eels | 0.5 |
| pred_crypt | pred_crypt | 0.5 |
| pred_inv | pred_inv | 0.5 |
| pred_plank | pred_plank | 0.5 |
| parrotfish | parrotfish | 0.5 |
| farm_damsel | farm_damsel | 0.5 |
| herbs | herbs | 0.5 |
| inverts | inverts | 0.5 |
Why use density-dependence? Pure density-independence (the mizer default) can cause instability in any model, but models with reef-specific non-linearities (multiple resources, refuge dynamics) are especially prone to this. Moderate density-dependence provides stabilizing feedback without creating the steep response curves that cause oscillations.
Click for detailed explanation of reproduction dynamics
Understanding Reproduction Level and Convergence
reproduction_level controls the functional form of the
Beverton-Holt stock-recruitment relationship, from 0 (maximum
compensation: recruitment saturates quickly against spawning biomass) to
1 (mizer’s default, no compensation: recruitment is directly
proportional to spawning biomass).
Reef models add several sources of non-linearity beyond a standard
mizer model – coupled algae/detritus/plankton dynamics, refuge
mechanisms whose effect on predation mortality is itself
density-dependent, and the iterative
calibrateReefBiomass()/matchReefGrowth() loops
used to reach them. With no reproductive compensation
(reproduction_level = 1), there’s nothing to damp these
interacting non-linearities, and reefSteady()’s search for
an equilibrium (where it repeatedly adjusts erepro to drive
births toward deaths) can fail to converge or oscillate. Moderate
compensation (reproduction_level = 0.5) provides just
enough stabilizing feedback to damp this without itself being steep
enough to cause the solver to overshoot, which is what happens as
compensation gets stronger still (reproduction_level near
0). This isn’t purely a numerical convenience, either: many reef fish
have an open recruitment system, with larvae dispersing widely and local
recruitment only weakly tied to local spawning stock, which is itself
closer to moderate than to zero or maximum compensation.
Recommended workflow: use
reproduction_level = 0.5 throughout calibration for stable
convergence while matching biomasses and growth rates. Afterwards, you
can move it toward 1 if you believe recruitment is very weakly
density-dependent for your system, or toward 0 to test recovery dynamics
from overfishing – but moderate values are usually both the most
numerically stable and the most biologically defensible default for reef
fish with typical connectivity.
Step 3: Calibrate Biomasses and Growth
This is the core tuning step where we iteratively match observed biomasses and growth rates.
Step 4a: Match Observed Biomasses
Use calibrateReefBiomass() to adjust reproduction
parameters so that modeled biomasses match observations.
# Calibrate biomasses to match observations
params <- calibrateReefBiomass(params)
params <- matchBiomasses(params)
params <- reefSteady(params)
# Plot comparison of observed vs modeled biomasses
plotBiomassVsSpecies(params) +
ggtitle("Biomass comparison after initial calibration")Step 4b: Match Growth Rates
Adjust growth-related parameters to match observed growth rates using
matchReefGrowth().
# Match growth rates
params <- matchReefGrowth(params)
params <- reefSteady(params)
# Check age at maturity matches observations
age_mat_observed <- caribbean_10_species$age_mat
age_mat_model <- age_mat(params)
age_comparison <- data.frame(
Species = caribbean_10_species$species,
Observed = age_mat_observed,
Model = age_mat_model,
Difference = age_mat_model - age_mat_observed
)
kable(age_comparison,
caption = "Comparison of observed vs modeled age at maturity",
digits = 2)Step 4c: Iterative Refinement
Repeat the biomass and growth matching process to fine-tune the model.
# Iterate to refine biomass and growth matches
params <- params |>
calibrateReefBiomass() |> matchBiomasses() |> matchReefGrowth() |>
reefSteady() |>
calibrateReefBiomass() |> matchBiomasses() |> matchReefGrowth() |>
reefSteady() |>
calibrateReefBiomass() |> matchBiomasses() |> matchReefGrowth() |>
reefSteady()
# Final biomass comparison
plotBiomassVsSpecies(params) +
ggtitle("Final biomass comparison after iterative tuning")Let’s examine the model performance after tuning:
# Check feeding levels
plotFeedingLevel(params) +
ggtitle("Feeding levels after tuning")
# Check predation mortality
plotPredMort(params) +
facet_wrap(~Species) +
ggtitle("Predation mortality by species")Step 5: Switch to Competitive Refuge Method
Once we have a stable steady state with the tuning refuge profile, we can switch to the full competitive refuge method, which includes density-dependent refuge dynamics.
Why switch methods? The competitive method provides more realistic refuge dynamics but requires a stable baseline to work from.
# Switch to competitive refuge method
params <- newRefuge(params,
new_method = "competitive",
new_method_params = karpata_refuge)
# Check the new refuge profile
plotRefugeProfile(params) +
ggtitle("Refuge profile with competitive method")
After switching refuge methods, we need to re-match biomasses as the refuge dynamics will have changed:
# Re-match biomasses with new refuge method
params <- params |>
matchBiomasses() |> reefSteady() |>
matchBiomasses() |> reefSteady() |>
matchBiomasses() |> reefSteady() |>
matchBiomasses() |> reefSteady()
#> ℹ `matchBiomasses()` has rescaled the model and so moved it off its steady state. Run `tuneSteadyState()` to settle it again. You can check with `getSteadyResidual()`.
#> ℹ Reached the convergence tolerance after 33 years. The biomasses change at up to 0.018 per year. The component `algae` (up to 0.57 per year) is also changing. Components are not included in the biomass drift above, although this run does advance them; see `attr(getSteadyResidual(params), "other")` for the rates themselves.
#> ℹ Reached the convergence tolerance after 25.5 years. The biomasses change at up to 0.0015 per year. The component `algae` (up to 0.21 per year) is also changing. Components are not included in the biomass drift above, although this run does advance them; see `attr(getSteadyResidual(params), "other")` for the rates themselves.
#> ℹ Reached the convergence tolerance after 21 years. The biomasses change at up to 0.0032 per year. The component `algae` (up to 0.14 per year) is also changing. Components are not included in the biomass drift above, although this run does advance them; see `attr(getSteadyResidual(params), "other")` for the rates themselves.
#> ℹ Reached the convergence tolerance after 16.5 years. The biomasses change at up to 0.0013 per year.
#> Warning: ! For the following species `erepro` has been increased to the smallest possible value: erepro[pred_eng] = 0.00293; erepro[pred_grab] = 5.79; erepro[eels] = 0.000419
#> ! The following species require an unrealistic value greater than 1 for `erepro`: pred_plank, farm_damsel
# Check vulnerability with new method
plotVulnerable(params) +
ggtitle("Vulnerability to predation with competitive refuge")
# Final biomass check
plotBiomassVsSpecies(params) +
ggtitle("Biomass match with competitive refuge method")
#> Warning: Removed 2 rows containing missing values or values outside the scale range
#> (`geom_segment()`).
Step 6: Fine-tune Reproduction Parameters
The final step involves tuning reproduction parameters to achieve the desired reproduction levels and density-dependence.
# Set reproduction efficiency to allow some density dependence
params <- setBevertonHolt(params, erepro = 0.35)
params <- reefSteady(params)
# Check reproduction levels - should be realistic for each species
final_reproduction_levels <- getReproductionLevel(params)
kable(data.frame(Species = names(final_reproduction_levels),
Reproduction_Level = final_reproduction_levels),
caption = "Final reproduction levels",
digits = 3)
# Check ratio of density-independent to density-dependent reproduction
rdi_rdd_ratio <- getRDI(params) / getRDD(params)
kable(data.frame(Species = names(rdi_rdd_ratio),
RDI_RDD_Ratio = rdi_rdd_ratio),
caption = paste0("Ratio of density-independent to ",
"density-dependent reproduction"),
digits = 2)Step 7: Rescale Algae and Detritus to a Realistic Absolute Scale
Steps 3-6 above tune algae and detritus relative to the fish
sub-model – reefSteady() calls
tuneUR()/tuneUR_cc() internally, which
balances each pool’s production against consumption (see
vignette("model-description")‘s Algae and Detritus sections
for exactly what’s held fixed for each). That balance says nothing about
the pools’ absolute scale, though, and reaching it usually
leaves algae and detritus biomass far from a realistic standing stock:
every biomass-correction step above (calibrateReefBiomass()
in particular) necessarily rescales the species’ interaction strength
with algae/detritus (rho_algae/ rho_detritus)
to preserve feeding level as fish abundances are corrected – the same
principle mizer itself uses for gamma/search volume – and
that repeated rescaling drives the absolute biomass scale down
over the course of calibration, even though nothing about it is
wrong.
The fix is a final, deliberately non-disruptive correction:
rescale_algae()/rescale_detritus() multiply a
pool’s biomass by a factor and divide the consuming species’ interaction
strength by the same factor, so total consumption – and
therefore the already-tuned fish sub-model – is completely
unaffected. detritus_lifetime() <- is a
convenience wrapper around rescale_detritus() that targets
a turnover time (biomass / consumption rate) instead of a raw factor;
there is no equivalent setter for algae, so target its standing biomass
directly with rescale_algae().
This is why the step belongs at the end of the recipe, not
earlier: because it doesn’t touch consumption, it doesn’t need to be
redone after a biomass or growth match, and running it before one would
just be undone by the next calibrateReefBiomass() call.
# Detritus: target a literature turnover time directly.
# e.g. Max, Hamilton, Gaines & Warner (2013, Mar. Ecol. Prog. Ser. 482:181-195)
# measured a 2.8-4.9 hour benthic detritus residence time at Palmyra Atoll;
# here we target the midpoint, expressed in years.
detritus_lifetime(params) <- 3.85 / (24 * 365)
# Algae: target a literature standing biomass directly with rescale_algae().
# Grazed Caribbean algal turf standing stock is commonly cited on the order
# of 10-100 g dry weight/m^2 -- convert to whatever mass units your own
# biomass_observed data uses (usually wet weight, via a site-specific
# dry:wet ratio) before using it as `target_algae_biomass` below, rather
# than reusing a number tuned for a different dataset.
params <- rescale_algae(params, target_algae_biomass / algae_biomass(params))
# Neither call requires re-running reefSteady() -- they don't change
# consumption, only the reported biomass and rho -- but it's good practice
# to confirm the biomass match is still exact:
plotBiomassObservedVsModel(params)Final Model Validation
Let’s examine the final model performance across multiple metrics:
# Overall spectra
plotSpectra(params, total = TRUE, biomass = TRUE, per_log_size = TRUE) +
ggtitle("Final total spectra")
# Diet composition
plotDiet(params) +
scale_x_log10(limits = c(1, 1e4)) +
ggtitle("Diet composition by size")
# Growth curves
plotGrowthCurves(params) +
ggtitle("Growth curves")Summary
This recipe provides a systematic approach to tuning
MizerReef models:
- Start simple: Use a binned refuge method for initial tuning
- Set intermediate reproduction: Add moderate density-dependence (0.5) for stability
- Iterative matching: Repeatedly match biomasses and growth rates
- Add complexity: Switch to competitive refuge method when stable
- Final tuning: Adjust reproduction parameters for realistic dynamics
- Rescale resources: Correct algae/detritus to a realistic absolute scale, last, since it doesn’t disturb anything tuned before it
Key Functions Used
-
newReefParams(): Create initial parameters object -
setBevertonHolt(): Set reproduction parameters -
reefSteady(): Project to steady state -
calibrateReefBiomass(): Match observed biomasses -
matchReefGrowth(): Match growth rates -
newRefuge(): Switch refuge methods -
rescale_algae(),detritus_lifetime()<-: Correct absolute resource scale without disturbing consumption - Various plotting functions for validation
Complete Tuning Script
Here’s the complete script used for the Karpata model:
# Complete tuning script for Karpata model
library(mizerReef)
library(mizer)
# Load data
data("caribbean_10_species")
data("caribbean_10_interaction")
data("tuning_profile")
data("karpata_refuge")
# 1. Create initial parameters
params <- newReefParams(species_params = caribbean_10_species,
interaction = caribbean_10_interaction,
method = "binned",
method_params = tuning_profile)
# 2. Set intermediate reproduction level (moderate density-dependence)
rdi <- rep(0.5, nrow(caribbean_10_species))
params <- setBevertonHolt(params, reproduction_level = rdi)
# 3. Initial steady state
params <- params |>
reefSteady() |> reefSteady() |> reefSteady() |>
reefSteady() |> reefSteady() |> reefSteady()
# 4. Calibrate biomasses and growth
params <- calibrateReefBiomass(params)
params <- matchBiomasses(params)
params <- reefSteady(params)
params <- matchReefGrowth(params)
params <- reefSteady(params)
# Iterative refinement
params <- params |>
calibrateReefBiomass() |> matchBiomasses() |> matchReefGrowth() |>
reefSteady() |>
calibrateReefBiomass() |> matchBiomasses() |> matchReefGrowth() |>
reefSteady() |>
calibrateReefBiomass() |> matchBiomasses() |> matchReefGrowth() |>
reefSteady()
# 5. Switch to competitive refuge
params <- newRefuge(params,
new_method = "competitive",
new_method_params = karpata_refuge)
# Re-match with new refuge
params <- params |>
matchBiomasses() |> reefSteady() |>
matchBiomasses() |> reefSteady() |>
matchBiomasses() |> reefSteady() |>
matchBiomasses() |> reefSteady()
# 6. Fine-tune reproduction
params <- setBevertonHolt(params, erepro = 0.35)
params <- setBevertonHolt(params, reproduction_level = rdi)
params <- params |>
reefSteady() |> reefSteady() |> reefSteady()
# 7. Rescale algae/detritus to a realistic absolute scale. Does not disturb
# consumption, so no further reefSteady() calls are needed for this step.
detritus_lifetime(params) <- 3.85 / (24 * 365)
params <- rescale_algae(params, target_algae_biomass / algae_biomass(params))
# Save final model
caribbean_10_model <- reefSteady(params)Further Reading
#> R version 4.6.2 (2026-10-29)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 26.04.1 LTS
#>
#> Matrix products: default
#> BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.32.so; LAPACK version 3.12.0
#>
#> locale:
#> [1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8
#> [4] LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8
#> [7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C
#> [10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C
#>
#> time zone: UTC
#> tzcode source: system (glibc)
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] knitr_1.52 dplyr_1.2.1 ggplot2_4.0.4
#> [4] mizerExperimental_3.3.1 mizerReef_2.0.3.9000 mizer_3.4.0.9003
#>
#> loaded via a namespace (and not attached):
#> [1] plotly_4.12.1 sass_0.5.0 generics_0.1.4
#> [4] tidyr_1.3.2 stringi_1.8.9 digest_0.6.39
#> [7] magrittr_2.0.5 timechange_0.4.0 evaluate_1.0.5
#> [10] grid_4.6.2 RColorBrewer_1.1-3 fastmap_1.2.0
#> [13] plyr_1.8.9 jsonlite_2.0.0 httr_1.4.9
#> [16] purrr_1.2.2 viridisLite_0.4.3 scales_1.4.0
#> [19] textshaping_1.1.0 jquerylib_0.1.4 cli_3.6.6
#> [22] rlang_1.3.0 withr_3.0.3 cachem_1.1.0
#> [25] yaml_2.3.12 otel_0.3.0 tools_4.6.2
#> [28] reshape2_1.4.5 assertthat_0.2.1 vctrs_0.7.3
#> [31] R6_2.6.1 lubridate_1.9.5 lifecycle_1.0.5
#> [34] stringr_1.6.0 fs_2.1.0 htmlwidgets_1.6.4
#> [37] ragg_1.5.2 pkgconfig_2.0.3 desc_1.4.3
#> [40] pkgdown_2.2.1 pillar_1.11.1 bslib_0.12.0
#> [43] gtable_0.3.6 glue_1.8.1 data.table_1.18.6.1
#> [46] Rcpp_1.1.2 systemfonts_1.3.4 xfun_0.63
#> [49] tibble_3.3.1 tidyselect_1.2.1 farver_2.1.2
#> [52] htmltools_0.5.9 labeling_0.4.3 rmarkdown_2.32
#> [55] compiler_4.6.2 S7_1.0.0
