Plots empirical quantiles of a variable, or of studentized residuals from a linear model, against theoretical quantiles of a comparison distribution.
qqPlot(x, ...)qqp(...)
# S3 method for default
qqPlot(x, distribution="norm", ...,
ylab=deparse(substitute(x)), xlab=paste(distribution, "quantiles"),
main=NULL, las=par("las"),
envelope=.95,
col=palette()[1], col.lines=palette()[2], lwd=2, pch=1, cex=par("cex"),
line=c("quartiles", "robust", "none"),
labels = if(!is.null(names(x))) names(x) else seq(along=x),
id.method = "y",
id.n =if(id.method[1]=="identify") Inf else 0,
id.cex=1, id.col=palette()[1], id.location="lr", grid=TRUE)
# S3 method for lm
qqPlot(x, xlab=paste(distribution, "Quantiles"),
ylab=paste("Studentized Residuals(", deparse(substitute(x)), ")",
sep=""), main=NULL,
distribution=c("t", "norm"), line=c("robust", "quartiles", "none"),
las=par("las"), simulate=TRUE, envelope=.95,
reps=100, col=palette()[1], col.lines=palette()[2], lwd=2,
pch=1, cex=par("cex"),
labels, id.method = "y",
id.n = if(id.method[1]=="identify") Inf else 0,
id.cex=1, id.col=palette()[1], id.location="lr", grid=TRUE, ...)
vector of numeric values or lm
object.
root name of comparison distribution -- e.g., "norm"
for the
normal distribution; t
for the t-distribution.
label for vertical (empirical quantiles) axis.
label for horizontal (comparison quantiles) axis.
label for plot.
confidence level for point-wise confidence envelope, or
FALSE
for no envelope.
if 0
, ticks labels are drawn parallel to the
axis; set to 1
for horizontal labels (see par
).
color for lines; the default is the second entry in the current color palette.
plotting character for points; default is 1
(a circle, see par
).
factor for expanding the size of plotted symbols; the default is
1
.
vector of text strings to be used to identify points, defaults to
names(x)
or observation numbers if names(x)
is NULL
.
point identification method. The default
id.method="y"
will identify the id.n
points with the largest value of
abs(y-mean(y))
. See showLabels
for other options.
number of points labeled. If id.n=0
, the default, no
point identification.
set size of the text for point labels; the default is cex
(which is typically 1
).
color for the point labels.
The default "lr"
identifies to the left or right of the point; the alterative "ab"
identifies above or below the point.
line width; default is 2
(see par
).
"quartiles"
to pass a line through the quartile-pairs, or
"robust"
for a robust-regression line; the latter uses the rlm
function in the MASS
package. Specifying line = "none"
suppresses the line.
if TRUE
calculate confidence envelope by parametric bootstrap;
for lm
object only. The method is due to Atkinson (1985).
integer; number of bootstrap replications for confidence envelope.
arguments such as df
to be passed to the appropriate quantile function.
If TRUE, the default, a light-gray background grid is put on the graph
These functions return the labels of identified points.
Draws theoretical quantile-comparison plots for variables and for studentized residuals from a linear model. A comparison line is drawn on the plot either through the quartiles of the two distributions, or by robust regression.
Any distribution for which quantile and
density functions exist in R (with prefixes q
and d
, respectively) may be used.
When plotting a vector, the confidence envelope is based on the SEs of the order statistics
of an independent random sample from the comparison distribution (see Fox, 2008).
Studentized residuals from linear models are plotted against the appropriate t-distribution with a point-wise
confidence envelope computed by default by a parametric bootstrap,
as described by Atkinson (1985).
The function qqp
is an abbreviation for qqPlot
.
Fox, J. (2008) Applied Regression Analysis and Generalized Linear Models, Second Edition. Sage.
Fox, J. and Weisberg, S. (2011) An R Companion to Applied Regression, Second Edition, Sage.
Atkinson, A. C. (1985) Plots, Transformations, and Regression. Oxford.
# NOT RUN {
x<-rchisq(100, df=2)
qqPlot(x)
qqPlot(x, dist="chisq", df=2)
qqPlot(lm(prestige ~ income + education + type, data=Duncan),
envelope=.99)
# }
Run the code above in your browser using DataLab