residuals.galamm: Residuals of galamm objects

View source: R/residuals.galamm.R

residuals.galammR Documentation

Residuals of galamm objects

Description

Computes residuals for models fit with galamm() using the definitions in Chapter 8 of \insertCitedunnGeneralizedLinearModels2018;textualgalamm. Define y as the response and \hat{\mu} as the model fit. Importantly, \hat{\mu} includes all random effects. Also define V(\cdot) as the variance function of the model family, and w as the weight. The Pearson residual is then

r_{P} = (y - \hat{\mu})/\sqrt{V(\hat{\mu}) / w}.

Furthermore, let sgn(\cdot) be the function which returns the sign of its argument and let d(y, \hat{\mu}) be the model deviance. The deviance residual is then

r_{D} = sgn(y - \hat{\mu}) \sqrt{w d(y, \hat{\mu})}.

Usage

## S3 method for class 'galamm'
residuals(object, type = c("pearson", "deviance"), scaled = FALSE, ...)

Arguments

object

An object of class galamm returned from galamm.

type

Character of length one describing the type of residuals to be returned. One of "pearson" and "deviance". Argument is case sensitive.

scaled

Logical value specifying whether to scale the residuals by their standard deviation. Defaults to FALSE.

...

Optional arguments passed on to other methods. Currently not used.

Value

Numeric vector of residual values.

References

\insertAllCited

See Also

fitted.galamm() for model fitted values, predict.galamm() for model predictions, and plot.galamm() for diagnostic plots. The generic function is residuals().

Other details of model fit: VarCorr(), appraise.galamm(), coef.galamm(), confint.galamm(), derivatives.galamm(), deviance.galamm(), factor_loadings.galamm(), family.galamm(), fitted.galamm(), fixef(), formula.galamm(), llikAIC(), logLik.galamm(), model.frame.galamm(), nobs.galamm(), predict.galamm(), print.VarCorr.galamm(), ranef.galamm(), response(), sigma.galamm(), vcov.galamm()

Examples

# Poisson GLMM
count_mod <- galamm(
  formula = y ~ lbas * treat + lage + v4 + (1 | subj),
  data = epilep, family = poisson
)

# Extract residuals
residuals(count_mod)


galamm documentation built on Dec. 21, 2025, 5:07 p.m.