[Rd] qqline (PR#764)

Setzer.Woodrow@epamail.epa.gov Setzer.Woodrow@epamail.epa.gov
Tue, 12 Dec 2000 00:15:37 +0100 (MET)


I think qqline does not do exactly what it is advertised to do ("`qqline'
adds a line to a normal quantile-quantile plot which passes through the
first and third quartiles.").  Consider the graph:

tmp <- qnorm(ppoints(10))
qqnorm(tmp)
qqline(tmp)

The line (which I expected go through all the points), has a slightly
shallower slope than does the points plotted by qqnorm.  I think the
problem is that qqline bases its line on the relationship between the
quartiles in the data and the large sample expected quartiles for a normal
distribution; qqnorm bases its plot on the relationship between the
quantiles in the data and an approximation to the (finite-sample) expected
quantiles for a normal distribution.  In qqnorm, the x-coordinates of the
first and third quartiles of the data vector ('tmp' in this case) are not
qnorm(c(0.25,0.75)) (as qqline does), but rather something like
quantile(qnorm(ppoints(length(tmp))),c(0.25,0.75)).  I say "something like"
because it is exactly right when the quartiles fall on data points, and an
approximation otherwise.

The following definition for qqline reflects this point:

function (y, ...)
{
  y <- y[!is.na(y)]
  n <- length(y)
    y <- quantile(y, c(0.25, 0.75))
    x <- quantile(qnorm(ppoints(n)),c(0.25, 0.75))
    slope <- diff(y)/diff(x)
    int <- y[1] - slope * x[1]
    abline(int, slope, ...)
}

I'm not sure it makes very much of a difference, though, for looking at
real data, instead of something like expected quantiles.

--please do not edit the information below--

Version:
 platform = Windows
 arch = x86
 os = Win32
 system = x86, Win32
 status =
 major = 1
 minor = 1.1
 year = 2000
 month = August
 day = 15
 language = R

Windows 9x 4.10 (build 1998)

Search Path:
 .GlobalEnv, package:MASS, package:logspline, Autoloads, package:base

R. Woodrow Setzer, Jr.                                            Phone:
(919) 541-0128
Experimental Toxicology Division                       Fax:  (919) 541-5394
Pharmacokinetics Branch
NHEERL MD-74; US EPA; RTP, NC 27711


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._