qresiduals {topmodels}R Documentation

(Randomized) Quantile Residuals

Description

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

Usage

qresiduals(object, ...)

## Default S3 method:
qresiduals(object, newdata = NULL, trafo = qnorm,
  type = c("random", "quantile"), nsim = 1L, delta = NULL, prob = NULL, ...)

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 procast.

newdata

optionally, a data frame in which to look for variables with which to predict. If omitted, the original observations are used.

trafo

function for tranforming residuals from probability scale to a different distribution scale (default: Gaussian).

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").

delta

numeric. The minimal difference to compute the range of proabilities corresponding to each observation according to get (randomized) quantile residuals. For NULL, the minimal observed difference in the resonse divided by 5e-6 is used.

prob

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

...

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 quantiles 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. Hence, in qqrplot the default is to use trafo = qnorm but other transformations can also be used, specifically using the uniform probability scale (via trafo = NULL or equivalently qunif or identity).

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

## linear regression models (homoscedastic Gaussian response)
m <- lm(dist ~ speed, data = cars)
qresiduals(m)

[Package topmodels version 0.1-0 Index]