Returns a long-format data frame of residuals, following the convention of
stats::residuals.glm() where type selects the kind of residual. By
default residuals are returned for every applicable data source – survey
indices, fishery catches, age/length composition (comp), and conditional
age-at-length (caal); use source to restrict to particular ones.
Usage
# S3 method for class 'Rceattle'
residuals(
object,
type = "response",
source = "all",
scale = "log",
species = NULL,
...
)Arguments
- object
An object of class
"Rceattle"returned byfit_mod().- type
Residual kind: one of
"response"(default),"pearson","osa", or"process".- source
Data source(s) to include: any of
"index","catch","comp","caal", or"all"(default)."diet"(predator stomach-content composition) is also accepted but, because it uses a predator/prey schema rather than the fleet/bin layout, must be requested on its own. Ignored whentype = "process".- scale
"log"(default) or"natural". Only affects"response"residuals forindex/catch.- species
Optional species code(s) to include (matched against the
Speciescolumn). DefaultNULLkeeps all species. Mirrors thespeciesargument ofplot.rceattle_osa().- ...
Passed to
osa_residuals()(e.g.method,seed) whentype = "osa", or toprocess_residuals()whentype = "process".
Value
A data.frame with columns Source, Fleet_code, Fleet_name,
Species, Sex, Year, Length, Bin, Age0_Length1, Sample_size,
Observed, Fitted, Residual. Columns are NA where they do not apply.
Details
Residual kinds (type):
"response"Observed minus fitted. For
index/catchthis is on the log scale by default (matching the lognormal likelihood; setscale = "natural"for the arithmetic difference); forcomp/caalit is the difference in proportions, observed minus fitted."pearson"Standardized residuals. For
index/catch, \((\log o - (\log\hat{o} - b\,\sigma^2/2))/\sigma\) using the model's realized observation log-SD \(\sigma\) and the observation bias-adjustment flag \(b\) (bias_adjust_obs, default 1); forcomp/caal, \((p - \hat{p})/\sqrt{\hat{p}(1 - \hat{p})/N}\) with input sample size N."osa"One-step-ahead residuals via
osa_residuals(), which builds the composition observation data on demand from any fit."process"Process residuals via
process_residuals()for the model's random-effect deviations;sourcedoes not apply.
Composition rows are returned in long form (one row per observation x
age/length bin) and carry the Age0_Length1 flag from comp_data (0 age,
1 length); CAAL rows carry both the conditioning Length and the age Bin.