Q-Q Plot Using a Theoretical or Empirical Distribution

DESCRIPTION:

Create a Quantile-Quantile Trellis plot comparing a theoretical distribution with the empirical distribution. A modified version of the plot is created if the data argument is a bigdata bdFrame (see the DETAILS).

USAGE:

qqmath(formula, distribution=qnorm, f.value=ppoints, ...) 
The following arguments have special meaning within this function. The common meanings for these and all other arguments are listed separately under trellis.args.

ARGUMENTS:

formula
a formula in the form ~ x | g1 * g2 * ... however the given variables g1, g2 , ... may be omitted. x is a numeric vector.
distribution
a quantile function that takes a vector of probabilities as an argument and computes corresponding theoretical or empirical quantiles of the reference distribution. Possible values include, qnorm, qunif , or your own function (see the examples).
f.value
function of a single integer, representing a sample size, that produces a vector of probabilities corresponding to which observations should be plotted. This function can be used to cut down on the number of points plotted, for example, function(n) c(.01, .05, seq(.1,.9,.1), .95, .99)

VALUE:

an object of class trellis, which is automatically plotted by print.trellis.

DETAILS:

If the data argument is a bdFrame then approximate quantiles (based on binning the data into 1000 equi-spaced bins) are computed and plotted.

SEE ALSO:

, , , ,

EXAMPLES:

# how well is a normal sample fit by a t distn on 7 df? 
qqmath( ~ rnorm(100), distribution=function(p) qt(p, df=7)) 
qqmath( ~ height | voice.part, data=singer, 
       prepanel = prepanel.qqmathline, 
       panel = function(x, y, ...) { 
         panel.grid() 
         panel.qqmathline(y, distribution=qnorm, ...) 
         panel.qqmath(x, y, ...) 
       }, 
       layout=c(2, 4), aspect=1, 
       xlab="Unit Normal Quantile", ylab="Height (inches)") 
# residuals for each voice part plotted against distn of pooled residuals 
qqmath( ~ height | voice.part, data=as.bdFrame(singer),
       prepanel = prepanel.qqmathline,
       panel = function(x, y, ...) {
         panel.grid()
         panel.bd.qqmathline(x, y, ...)
         panel.qqmath(x, y, ...)
       },
       layout=c(2, 4), aspect=1,
       xlab="Unit Normal Quantile", ylab="Height (inches)")
# like above but for bigdata.  Note x argument to panel.bd.qqmathline
# and the lack of distribution=qnorm argument.
attach(singer) 
oneway.residuals <- oneway(height ~ voice.part, spread=1)$residuals 
qqmath( ~ oneway.residuals | voice.part, 
       distribution=function(p) quantile(oneway.residuals, p), 
       panel=function(x, y) { 
         panel.grid() 
         panel.abline(0, 1) 
         panel.qqmath(x, y) 
       }, 
       aspect=1, layout=c(2, 4), 
       xlab="Pooled Residual Height (inches)", 
       ylab="Residual Height (inches)") 
# specifying different plotting parameters in the panel function
qqmath(~Weight|Fuel, panel=function(...) panel.qqmath(..., cex= 2))