Skip to contents

Return keyed catch and survey rows for plotting or further checks. This is a convenience extractor: standardized residuals are the existing fitted-state residuals, affected by shrinkage, not independent prediction errors.

Usage

# S3 method for class 'tam_fit'
residuals(
  object,
  type = c("standardized", "log", "response", "osa"),
  method = "oneStepGaussianOffMode",
  ...
)

Arguments

object

A fitted tam_fit.

type

"standardized" (default), "log" (log observation minus log prediction), "response" (observation minus prediction), or "osa".

method

OSA algorithm, as in add_osa_residuals(). Only used with type = "osa". Explicitly supplying it requests a fresh calculation.

...

Computation controls passed to RTMB::oneStepPredict(), such as trace = FALSE or parallel = FALSE. subset and conditional index included observations in likelihood order; unrequested rows retain missing residuals. Explicit controls request a fresh calculation; other residual types reject them.

Value

A data frame with year, age, type (catch/index), survey, observations, predictions, residuals, and available unit/fleet columns. OSA output also identifies osa_method. The residual_type attribute names the requested scale, and osa retains available method/settings/coverage metadata.

Details

type = "osa" reuses cached OSA columns when no computation controls or method are supplied. Otherwise both catch and index residuals are calculated together, using one algorithm at fitted parameter values. It can be expensive, but does not rerun fit_tam() or re-estimate fixed parameters. Temporary objectives protect the fitted object's state. Other residual types remain simple extractors. Excluded observations, including zeros, retain rows with missing residuals. The supplied fit is not modified or implicitly cached. To retain results for later extraction and dashboard use, assign fit_osa <- add_osa_residuals(fit, method = "oneStepGeneric", trace = FALSE).

Examples

if (FALSE) { # \dontrun{
residuals(fit)
residuals(fit, type = "log")
residuals(fit, type = "osa", method = "oneStepGeneric", trace = FALSE)
} # }