Learn R Programming

scam (version 1.2-20)

residuals.scam: SCAM residuals

Description

This function is a copy of the mgcv library code residuals.gam, but with an additional type of residuals, (randomized) quantile residuals, implemented. It returns residuals for a fitted scam model object. Pearson, deviance, working, response, and (randomized) quantile residuals are available.

Usage

# S3 method for scam
residuals(object, type =  c("deviance", "pearson","scaled.pearson", "working", 
                        "response", "rquantile"), setseed=NULL, ...)

Value

An array of residuals.

Arguments

object

a scam fitted model object.

type

the type of residuals. Usually one of "deviance", "pearson", "scaled.pearson", "working", "response", or "rquantile".

setseed

seed to be used in getting randomized quantile residuals.

...

other arguments.

Author

Natalya Pya <nat.pya@gmail.com> based partly on residual.gam by Simon N Wood

Details

"deviance": deviance residuals defined by the model family.

"scaled.pearson": scaled Pearson residuals are raw residuals (data minus fitted values) divided by the standard deviation of the data according to the model mean variance relationship and estimated scale parameter.

"pearson": Pearson residuals are the same as scaled Pearson, but multiplied by the square root of the scale parameter (so they are independent of the scale parameter): \((y-\mu)/\sqrt{V(\mu)}\), where \(y\) is data, \(\mu\) is model fitted value, and \(V\) is model mean-variance relationship.

"working": working residuals are the residuals returned from model fitting at convergence.

"response": response residuals are the raw residuals (data minus fitted values).

"rquantile": (randomized) quantile residuals (RQRs) as suggested by Dunn and Smyth (1996). Based on the idea of inverting the estimated distribution function for each observation to get approximately normally distributed residuals. RQRs are the theoretical standard normal quantiles evaluated at the estimated CDF at each observation. For models with a continuous response distribution they are simply quantile residuals; for discrete distributions, one realization of randomized quantile residuals is produced. In case of normal responses, quantile residuals are equivalent to deviance and Pearson residuals. In non-normal situations, RQRs might be a better choice for performing model checking.

References

Dunn, P. K. and Smyth, G. K. (1996) Randomised quantile residuals, J. Comput. Graph. Statist., 5, 236--244

See Also

scam, scam.check

Examples

Run this code
# \donttest{
require(scam)
## Poisson model ...
set.seed(2)
n <- 200
x1 <- runif(n)*6-3
f1 <- 3*exp(-x1^2) # unconstrained term
x2 <- runif(n)*4-1;
f2 <- exp(4*x2)/(1+exp(4*x2)) # monotone increasing smooth
f <- f1+f2
y <- rpois(n,exp(f))
b <- scam(y~s(x1,bs="cr")+s(x2,bs="mpi"),
      family=poisson(link="log"),optimizer=c("efs","bfgs"))
scam.check(b)
## residuals plots using randomized quantile residuals with seed set...
scam.check(b, type="rquantile", setseed=2)
# }

Run the code above in your browser using DataLab