Learn R Programming

spaMM (version 3.11.3)

residuals.HLfit: Extract model residuals

Description

Extracts several types of residuals from an object of class HLfit.

Usage

# S3 method for HLfit
residuals(object, 
  type = c("deviance", "pearson", "response", "std_dev_res"), force=FALSE, ...)

Arguments

object

An object of class HLfit, as returned by the fitting functions in spaMM.

type

The type of residuals which should be returned. The alternatives are: "deviance" (default), "pearson", "response" and "std_dev_res". See residuals.glm for more information about the first three, and the Details for the last one.

force

Boolean: to force recomputation of the "std_dev_res" residuals even if they are available in the object, for checking purposes.

For consistency with the generic.

Value

A vector of residuals

Details

Following Lee et al. (2006, p.52), the standardized deviance residuals returned for type="std_dev_res" are defined as the deviance residuals divided by \(\phi\sqrt(1-q)\), where the deviance residuals are defined as for a GLM, \(\phi\) is the dispersion parameter of the response family (a vector of values, for heteroscedastic cases), and \(q\) is a vector of leverages given by hatvalues(., type="std") (see hatvalues for details about these specific standardizing leverages).

References

Lee, Y., Nelder, J. A. and Pawitan, Y. (2006). Generalized linear models with random effects: unified analysis via h-likelihood. Chapman & Hall: London.

Examples

Run this code
# NOT RUN {
data("wafers")
fit <- fitme(y ~X1+(1|batch) ,data=wafers, init=list(phi=NaN))  # : this 'init' 
#                 implies that standardized deviance residuals are saved in the 
#                 fit result, allowing the following comparison: 

r1 <- residuals(fit, type="std_dev_res") # gets stored value
r2 <- residuals(fit, type="std_dev_res", force=TRUE) # forced recomputation
if (diff(range(r1-r2))>1e-14) stop()
# }

Run the code above in your browser using DataLab