Q-Q Plot with Theoretical Distribution
qqmath.RdDraw quantile-Quantile plots of a sample against a theoretical distribution, possibly conditioned on other variables.
Usage
qqmath(x, data, ...)
# S3 method for class 'formula'
qqmath(x,
data,
allow.multiple = is.null(groups) || outer,
outer = !is.null(groups),
distribution = qnorm,
f.value = NULL,
auto.key = lattice.getOption("default.args")$auto.key,
aspect = "fill",
panel = lattice.getOption("panel.qqmath"),
prepanel = NULL,
scales, strip, groups,
xlab, xlim, ylab, ylim,
drop.unused.levels = lattice.getOption("drop.unused.levels"),
...,
lattice.options = NULL,
default.scales = list(),
default.prepanel = lattice.getOption("prepanel.default.qqmath"),
subscripts,
subset)
# S3 method for class 'data.frame'
qqmath(x, data = NULL, formula = data, ...)
# S3 method for class 'numeric'
qqmath(x, data = NULL, ylab, ...)Arguments
- x
The object on which method dispatch is carried out.
For the
"formula"method,xshould be a formula of the form~ x | g1 * g2 * ..., wherexshould be a numeric variable. For the"numeric"method,xshould be a numeric vector.- data
-
For the
formulamethod, an optional data source (usually a data frame) in which variables are to be evaluated (seexyplotfor details).datashould not be specified for the other methods, and is ignored with a warning if it is. - formula
The formula to be used for the
"data.frame"methods. See documentation for argumentxfor details.- distribution
-
A quantile function that takes a vector of probabilities as argument and produces the corresponding quantiles from a theoretical distribution. Possible values are
qnorm,qunif, etc. Distributions with other required arguments need to be provided as user-defined functions (see example withqt). - f.value
-
An optional numeric vector of probabilities, quantiles corresponding to which should be plotted. This can also be a function of a single integer (representing sample size) that returns such a numeric vector. A typical value for this argument is the function
ppoints, which is also the S-PLUS default. If specified, the probabilities generated by this function is used for the plotted quantiles, through thequantilefunction for the sample, and the function specified as thedistributionargument for the theoretical distribution.f.valuedefaults toNULL, which has the effect of usingppointsfor the quantiles of the theoretical distribution, but the exact data values for the sample. This is similar to what happens forqqnorm, but different from the S-PLUS default off.value=ppoints.For large
x, this argument can be used to restrict the number of points plotted. See also thetails.nargument inpanel.qqmath. - panel
-
A function, called once for each panel, that uses the packet (subset of panel variables) corresponding to the panel to create a display. The default panel function
panel.qqmathis documented separately, and has arguments that can be used to customize its output in various ways. Such arguments can usually be directly supplied to the high-level function. - allow.multiple, outer
See
xyplot.- auto.key
See
xyplot.- aspect
See
xyplot.- prepanel
See
xyplot.- scales
See
xyplot.- strip
See
xyplot.- groups
See
xyplot.- xlab, ylab
See
xyplot.- xlim, ylim
See
xyplot.- drop.unused.levels
See
xyplot.- lattice.options
See
xyplot.- default.scales
See
xyplot.- subscripts
See
xyplot.- subset
See
xyplot.- default.prepanel
Fallback prepanel function. See
xyplot.- ...
Further arguments. See corresponding entry in
xyplotfor non-trivial details.
Value
An object of class "trellis". The
update method can be used to
update components of the object and the
print method (usually called by
default) will plot it on an appropriate plotting device.
Details
qqmath produces Q-Q plots of the given sample against a
theoretical distribution. The default behaviour of qqmath is
different from the corresponding S-PLUS function, but is similar to
qqnorm. See the entry for f.value for specifics.
The implementation details are also different from S-PLUS. In
particular, all the important calculations are done by the panel (and
prepanel function) and not qqmath itself. In fact, both the
arguments distribution and f.value are passed unchanged
to the panel and prepanel function. This allows, among other things,
display of grouped Q-Q plots, which are often useful. See the help
page for panel.qqmath for further details.
This and all other high level Trellis functions have several arguments
in common. These are extensively documented only in the help page for
xyplot, which should be consulted to learn more detailed
usage.
Author
Deepayan Sarkar Deepayan.Sarkar@R-project.org
Examples
qqmath(~ rnorm(100), distribution = function(p) qt(p, df = 10))
qqmath(~ height | voice.part, aspect = "xy", data = singer,
prepanel = prepanel.qqmathline,
panel = function(x, ...) {
panel.qqmathline(x, ...)
panel.qqmath(x, ...)
})
vp.comb <-
factor(sapply(strsplit(as.character(singer$voice.part), split = " "),
"[", 1),
levels = c("Bass", "Tenor", "Alto", "Soprano"))
vp.group <-
factor(sapply(strsplit(as.character(singer$voice.part), split = " "),
"[", 2))
qqmath(~ height | vp.comb, data = singer,
groups = vp.group, auto.key = list(space = "right"),
aspect = "xy",
prepanel = prepanel.qqmathline,
panel = function(x, ...) {
panel.qqmathline(x, ...)
panel.qqmath(x, ...)
})