Generic function and methods for computing PIT residuals.

pitresiduals(object, ...)

# S3 method for default
pitresiduals(
  object,
  newdata = NULL,
  scale = c("uniform", "normal"),
  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.

...

further parameters passed to methods.

newdata

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

scale

On which scale should the PIT residuals be shown; on the probability scale ("uniform") or on the normal scale ("normal").

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

Value

A vector or matrix of PIT residuals.

Details

For regression models with a continuous response distribution, PIT residuals are simply the predictive cumulative distribution (CDF) evaluated at the observations (Dawid, 1984). For discrete distributions, a random value is drawn from the range of probabilities corresponding to each observation similar to the approach of Dunn and Smyth (1996) to gain (randomized) quantile residuals (qresiduals). PIT values have been used under various names, but to emphasize their similar properties to residuals we follow Warton (2017) and refer to them as PIT residuals.

With the method pitresiduals, the PIT residuals can also be transformed from the probability scale to another distribution scale. Supported quantile scales are uniformly (uniform) and normally (normal) distributed. Probabilites can be either a vector 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. For (randomized) quantile residuals (on the normal scale), as suggested by Dunn and Smyth (1996), the scale must be set to "normal" or qresiduals can be called directly.

References

Dunn KP, Smyth GK (1996). “Randomized Quantile Residuals.” Journal of Computational and Graphical Statistics, 5(3), 236--244. doi:10.2307/1390802

Dawid AP (1984). “Present Position and Potential Developments: Some Personal Views: Statistical Theory: The Prequential Approach.” Journal of the Royal Statistical Society: Series A (General), 147(2), 278--92. doi:10.2307/2981683 .

Warton DI, Thibaut L, Wang YA (2017) “The Pit-Trap--a `Model-Free' Bootstrap Procedure for Inference About Regression Models with Discrete, Multivariate Responses”. PLOS ONE, 12(7), 1--18. doi:10.1371/journal.pone.0181790 .

See also

Examples


## linear regression models (homoscedastic Gaussian response)
m <- lm(dist ~ speed, data = cars)
pitresiduals(m)
#>          1          2          3          4          5          6          7 
#> 0.60081531 0.78417002 0.34652997 0.78808978 0.55593700 0.30206903 0.40186398 
#>          8          9         10         11         12         13         14 
#> 0.61117045 0.79196758 0.28235827 0.56124732 0.15012467 0.26182583 0.35484277 
#>         15         16         17         18         19         20         21 
#> 0.45746181 0.30835554 0.51211771 0.51211772 0.79580317 0.22318530 0.46102201 
#>         22         23         24         25         26         27         28 
#> 0.93252054 0.99761426 0.07771442 0.15328579 0.79833667 0.18801555 0.36154336 
#>         29         30         31         32         33         34         35 
#> 0.12585715 0.26917859 0.51926989 0.22857810 0.57359364 0.93483116 0.97950682 
#>         36         37         38         39         40         41         42 
#> 0.08035724 0.22993764 0.76451836 0.02686025 0.19289134 0.27363944 0.36828670 
#>         43         44         45         46         47         48         49 
#> 0.57710851 0.42281412 0.10528373 0.32593113 0.84346190 0.85884627 0.99792760 
#>         50 
#> 0.61152323