qresiduals {countreg}R Documentation

(Randomized) Quantile Residuals

Description

Generic function and methods for computing (randomized) quantile residuals.

Usage

qresiduals(object, ...)

## Default S3 method:
qresiduals(object, type = c("random", "quantile"), nsim = 1L, prob = 0.5, ...)

Arguments

object

an object. For the default method this needs to be either a specification of probabilities (vector or 2-dimensional matrix of probabilities) or an object from which the these can be obtained with pit.

type

character specifying whether - in the case of discrete response distributions - randomized quantile residuals or their corresponding quantiles should be computed.

nsim

numeric. The number of simulated randomized quantile residuals per observation (for type = "numeric").

prob

numeric. The probabilities at which quantile residuals should be computed (for type = "quantile"), defaulting to the median.

...

further parameters passed to methods.

Details

(Randomized) quantile residuals have been suggested by Dunn and Smyth (1996). For regression models with a continuous response distribution this simply computes theoretical standard normal quantile corresponding to the probability integral transform of the fitted distribution. For discrete distributions, a random theoretical normal quantile is drawn from the range of probabilities corresponding to each observation.

The default qresiduals method can compute randomized quantile residuals from a vector (which essentially just calls qnorm) or a 2-column matrix of probabilities. The latter offers to either draw "random" samples from the distribution or compute corresponding "quantile"s such as the median etc.

Value

A vector or matrix of quantile residuals.

Note

Note that there is also a qresiduals function in the statmod package that is not generic and always returns a single random quantile residual.

References

Dunn KP, Smyth GK (1996). “Randomized Quantile Residuals.” Journal of Computational and Graphical Statistics, 5, 1–10.

See Also

qnorm, qqrplot

Examples

## count data regression models: crab satellites
data("CrabSatellites", package = "countreg")
cs_p <- glm(satellites ~ width + color, data = CrabSatellites, family = poisson)

qres <- cbind(
  sample = qresiduals(cs_p, nsim = 3),
  median = qresiduals(cs_p, type = "quantile"),
  mean100 = rowMeans(qresiduals(cs_p, nsim = 100)),
  range = qresiduals(cs_p, type = "quantile", prob = c(0, 1))
)
qres[1:5, ]

[Package countreg version 0.2-1 Index]