Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

envelope.glm

Normal QQ-plot with simulated envelope of model residuals


Description

Produces a normal QQ-plot with simulated envelope of residuals obtained from the fit of a generalized linear model.

Usage

## S3 method for class 'glm'
envelope(
  object,
  rep = 100,
  conf = 0.95,
  type = c("quantile", "deviance", "pearson"),
  standardized = FALSE,
  plot.it = TRUE,
  identify,
  ...
)

Arguments

object

an object of the class glm which is obtained from the fit of a generalized linear model.

rep

an (optional) positive integer indicating the number of replicates which should be used to build the simulated envelope. By default, rep is set to be 100.

conf

an (optional) value in the interval (0,1) indicating the confidence level which should be used to build the pointwise confidence intervals, which form the envelope. By default, conf is set to be 0.95.

type

a character string indicating the type of residuals which should be used. The available options are: randomized quantile ("quantile"), deviance ("deviance") and pearson ("pearson") residuals. By default, type is set to be "quantile".

standardized

an (optional) logical switch indicating if the residuals should be standardized by dividing by the square root of (1-h), where h is a measure of leverage. By default, standardized is set to be FALSE.

plot.it

an (optional) logical switch indicating if the normal QQ-plot with simulated envelope of residuals is required or just the data matrix in which it is based. By default, plot.it is set to be TRUE.

identify

an (optional) positive integer indicating the number of individuals to identify on the QQ-plot with simulated envelope of residuals. This is only appropriate if plot.it=TRUE.

...

further arguments passed to or from other methods. If plot.it=TRUE then ... may be used to include graphical parameters to customize the plot. For example, col, pch, cex, main, sub, xlab, ylab.

Details

The simulated envelope is builded by simulating rep independent realizations of the response variable for each individual, which is accomplished taking into account the following: (1) the model assumption about the distribution of the response variable; (2) the estimates of the parameters in the linear predictor; and (3) the estimate of the dispersion parameter. The interest model is re-fitted rep times, as each time the vector of observed responses is replaced by one of the simulated samples. The residuals type type are computed and then ordered for each replicate, so that for each i=1,2,...,n, where n is the number of individuals in the sample, there is a random sample of size rep of the i-th order statistic of the residuals type type. Therefore, the simulated envelope is composed of the quantiles (1-conf)/2 and (1+conf)/2 of the random sample of size rep of the i-th order statistic of the residuals type type for i=1,2,...,n. Families quasi(), quasipoisson and quasibinomial are not supported.

Value

A matrix with n rows and four columns: the first three (Lower limit, Median, and Upper limit) describe the simulated envelope, that is, each row corresponds to the quantiles (1-conf)/2, 0.5 and (1+conf)/2 of the random sample of size rep of the i-th order statistic of the residuals type type for i=1,2,...,n; and the last one column (Residuals) contains the observed type type residuals.

References

Atkinson A.C. (1985) Plots, Transformations and Regression. Oxford University Press, Oxford.

Davison A.C. and Gigli A. (1989) Deviance Residuals and Normal Scores Plots. Biometrika 76, 211-221.

Dunn P.K. and Smyth G.K. (1996) Randomized Quantile Residuals. Journal of Computational and Graphical Statistics 5, 236-244.

Pierce D.A. and Schafer D.W. (1986) Residuals in Generalized Linear Models. Journal of the American Statistical Association 81, 977-986.

See Also

Examples

# Example 1
fit1 <- glm(infections ~ frequency + location, family=poisson, data=swimmers)
envelope(fit1, type="quantile", col="red", pch=20,col.lab="blue",
         col.axis="blue",col.main="black",family="mono",cex=0.8)

# Example 2
fit2 <- glm(cbind(cells,200-cells) ~ tnf + ifn + tnf*ifn, family=binomial, data=cellular)
envelope(fit2, type="deviance",col="red", pch=20,col.lab="blue",
         col.axis="blue",col.main="black",family="mono",cex=0.8)

# Example 3
fit3 <- glm(cancer/exposed ~ dose, family=binomial, weights=exposed, data=bladder)
envelope(fit3, type="deviance", col="red", pch=20,col.lab="blue",
         col.axis="blue",col.main="black",family="mono",cex=0.8)

# Example 4
fit4 <- glm(cases ~ offset(log(population)) + city + age, family=poisson("log"), data=skincancer)
envelope(fit4, type="quantile", col="red", pch=20,col.lab="blue",
         col.axis="blue",col.main="black",family="mono",cex=0.8)

glmtoolbox

Set of Tools to Data Analysis using Generalized Linear Models

v0.1.0
GPL-2 | GPL-3
Authors
Luis Hernando Vanegas [aut, cre], Luz Marina Rondón [aut], Gilberto A. Paula [aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.