residuals() returns response residuals or Pearson-style residuals from a
drmTMB fit.
Details
For univariate Gaussian models, response residuals are y - mu. Pearson
residuals divide by the fitted observation standard deviation. If a dense
known sampling covariance was used, Pearson residuals are whitened by the
fitted total observation covariance.
For lognormal models, response residuals are y - fitted_mean. Pearson
residuals are computed on the log-response scale as (log(y) - mu) / sigma.
For Gamma models, response residuals are y - mu and Pearson residuals
divide by the fitted Gamma standard deviation mu * sigma, where sigma is
the coefficient of variation. For beta-binomial models, response residuals
are observed success proportions minus fitted mu, and Pearson residuals
divide by the fitted beta-binomial proportion standard deviation. For
cumulative-logit ordinal models, response residuals are the observed
ordered-category score minus the fitted expected score, and Pearson
residuals divide by the fitted category-score standard deviation. For
Poisson models, response residuals are y - mu and Pearson residuals divide
by sqrt(mu). For zero-inflated
Poisson models, response residuals are y - (1 - zi) * mu, and Pearson
residuals divide by sqrt((1 - zi) * mu * (1 + zi * mu)). For
negative-binomial 2 models, Pearson residuals divide by
sqrt(mu + sigma^2 * mu^2). For zero-truncated NB2 models, response
residuals are y - mu / (1 - Pr_NB2(0)), and Pearson residuals divide by
the conditional positive-count standard deviation. For hurdle NB2 models,
response residuals are y - (1 - hu) * mu / (1 - Pr_NB2(0)), and Pearson
residuals divide by the unconditional standard deviation implied by the
hurdle-zero mixture. For zero-inflated NB2 models, response residuals are
y - (1 - zi) * mu, and Pearson residuals divide by the unconditional
standard deviation implied by the structural-zero mixture.
For bivariate Gaussian models, response residuals are returned as a
two-column matrix. Pearson residuals are standardized and whitened using the
fitted residual sigma1, sigma2, and rho12, or using the full row-paired
observation covariance when a dense bivariate known V was supplied.