qresiduals {countreg} | R Documentation |
Generic function and methods for computing (randomized) quantile residuals.
qresiduals(object, ...) ## Default S3 method: qresiduals(object, type = c("random", "quantile"), nsim = 1L, prob = 0.5, ...)
object |
an object. For the |
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 |
prob |
numeric. The probabilities at which quantile residuals should be
computed (for |
... |
further parameters passed to methods. |
(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.
A vector or matrix of quantile residuals.
Note that there is also a qresiduals
function in the statmod
package that is not generic and always returns a single random quantile residual.
Dunn KP, Smyth GK (1996). “Randomized Quantile Residuals.” Journal of Computational and Graphical Statistics, 5, 1–10.
## 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, ]