Skip to contents

Adds CPUE, length-composition, and weight-composition OSA diagnostics to an Opal object. Use plot_osa_sdnr() for the dataset-level SDNR comparison.

Usage

opal_osa(x, seed = 123L, conf = 0.95, name = "osa")

Arguments

x

A fitted opal_obj.

seed

Random seed for discrete residuals; restored on exit. NULL uses and advances the current random-number stream.

conf

Confidence level for approximate chi-squared SDNR intervals.

name

Name under x$derived for the diagnostics.

Value

An updated object. opal_derived() returns its residual table, dataset summaries, and calculation settings.

Details

For fixed-effect fits, CPUE uses its lognormal CDF, and composition residuals use exact sequential binomial, beta, or beta-binomial CDFs for multinomial, Dirichlet, or Dirichlet-multinomial observations. Parameters are held at their fitted values. For random-effect models, RTMB's oneStepPredict() integrates latent states using its Laplace-based OSA approximation. Other observation streams remain conditioned on. There is no silent substitution of conditional residuals for marginal residuals.

Observation order is the stored input order, then ascending composition bin. Composition tables include each observed bin's lower and upper boundaries, including row-specific schemes. The final composition bin is constrained and omitted from residual calculations. Removed fisheries, zero lambdas, zero sample sizes, exhausted counts, and numerical failures remain in the table with explicit exclusion reasons. For fixed-effect fits, multinomial counts are rounded to the nearest integer using floor(count + 0.5) for the sequential binomial PIT. A message is emitted once per call if fractional counts in an included LF or WF row are rounded. This diagnostic approximation does not change the fitted likelihood. The latent RTMB OSA path does not round observations. No new pseudocounts are added. Rows assigned a zero likelihood lambda are excluded with reason "lambda = 0". For fixed-effect fits, fractional CPUE, LF, or WF lambdas temper the fitted estimates, but the residuals use the untempered observation model at those estimates; prior, recruitment, and penalty lambdas only affect the estimates. For random-effect models, oneStepPredict() integrates the tape, which already includes every lambda, so any non-unit lambda (other than a zero observation lambda, whose rows are excluded) makes the residuals come from a tempered joint density that is not a proper predictive distribution. A warning is given in both cases. SDNR should be near one, but its interval is approximate because fitted parameters and finite samples affect calibration. Catch is conditioned on and has no observation likelihood; process priors are not observations.