envelope.lm: Normal QQ-plot with simulated envelope of residuals for...

View source: R/glms.R

envelope.lmR Documentation

Normal QQ-plot with simulated envelope of residuals for normal linear models

Description

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

Usage

## S3 method for class 'lm'
envelope(
  object,
  rep = 100,
  conf = 0.95,
  type = c("external", "internal"),
  plot.it = TRUE,
  identify,
  ...
)

Arguments

object

an object of the class lm.

rep

an (optional) positive integer indicating the number of replicates which should be used to build the simulated envelope. As default, rep is set to 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. As default, conf is set to 0.95.

type

a character string indicating the type of residuals which should be used. The available options are: internally Studentized ("internal") and externally Studentized ("external") residuals. See Cook and Weisberg (1982, pages 18-20).

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. As default, plot.it is set to TRUE.

identify

an (optional) positive integer value 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 built 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 type-type residuals are computed and then sorted 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 type-type residuals. 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 type-type residuals for i=1,2,...,n.

Value

A matrix with the following four columns:

Lower limit the quantile (1 - conf)/2 of the random sample of size rep of the i-th order
statistic of the type-type residuals for i=1,2,...,n,
Median the quantile 0.5 of the random sample of size rep of the i-th order
statistic of the type-type residuals for i=1,2,...,n,
Upper limit the quantile (1 + conf)/2 of the random sample of size rep of the i-th order
statistic of the type-type residuals for i=1,2,...,n,
Residuals the observed type-type residuals,

References

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

Cook R.D., Weisberg S. (1982) Residuals and Influence in Regression. Chapman and Hall, New York.

See Also

envelope.glm, envelope.overglm

Examples

###### Example 1: Fuel consumption of automobiles
fit1 <- lm(mpg ~ log(hp) + log(wt), data=mtcars)
envelope(fit1, rep=100, conf=0.95, type="external", col="red", pch=20, col.lab="blue",
         col.axis="blue", col.main="black", family="mono", cex=0.8)

###### Example 2: Species richness in plots
data(richness)
fit2 <- lm(Species ~ Biomass + pH + Biomass*pH, data=richness)
envelope(fit2, rep=100, conf=0.95, type="internal", col="red", pch=20, col.lab="blue",
         col.axis="blue", col.main="black", family="mono", cex=0.8)

###### Example 3: Gas consumption in a home before and after insulation
whiteside <- MASS::whiteside
fit3 <- lm(Gas ~ Temp + Insul + Temp*Insul, data=whiteside)
envelope(fit3, rep=100, conf=0.95, type="internal", col="red", pch=20, col.lab="blue",
         col.axis="blue", col.main="black", family="mono", cex=0.8)


glmtoolbox documentation built on Sept. 11, 2024, 7:32 p.m.