Hi, We could use qqplot to see how two distributions are different from each other. To show better how they are different (departs from the straight line), how is it possible to plot the straight line that goes through them? I am looking for some thing like qqline for qqnorm. I thought of abline but how to determine the slope and intercept? Best wishes, Carol
On Nov 2, 2009, at 10:40 AM, carol white wrote:> Hi, > We could use qqplot to see how two distributions are different from > each other. To show better how they are different (departs from the > straight line), how is it possible to plot the straight line that > goes through them? I am looking for some thing like qqline for > qqnorm. I thought of abline but how to determine the slope and > intercept?I always assumed that the intercept was zero and the slope = unity. y <- rt(200, df = 5) qqnorm(y); qqline(y, col = 2) qqplot(y, rt(300, df = 5)) abline(0, 1, col="red") I am open to education if that assumption is too simplistic, but you have not offered anything in the way of a counter-example.>= David Winsemius, MD Heritage Laboratories West Hartford, CT
Carol, You could run a line through the pairs of first and third quartiles of the two distributions, i.e., c(quantile(x, .25), quantile(y, .25)) and c(quantile(x, .75), quantile(y, .75)). (Of course, you'd want the line to extend across the whole graph.) I hope this helps, John> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]On> Behalf Of carol white > Sent: November-02-09 10:40 AM > To: r-help at stat.math.ethz.ch > Subject: [R] qqplot > > Hi, > We could use qqplot to see how two distributions are different from each > other. To show better how they are different (departs from the straight > line), how is it possible to plot the straight line that goes throughthem? I> am looking for some thing like qqline for qqnorm. I thought of abline buthow> to determine the slope and intercept? > > Best wishes, > > Carol > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
if I have the two following matrices, abline(0,1) doesn't go through. QQplot is attached. [,1] [,2] [,3] [,4] [,5] 2.149644 1.992864 3.346375 2.793511 3.428230 1.100762 2.152981 2.735401 2.175185 3.323058 1.212406 2.131813 2.672598 2.389996 3.242490 1.183770 1.908633 2.661237 2.590545 2.906059 1.665190 1.778923 2.636062 2.475619 4.013407 0.601 0.083 0.520 0.920 -0.007 -0.778 0.427 -0.605 -0.066 -0.283 -0.599 0.348 -0.693 0.284 -0.436 -0.519 0.081 -0.590 0.678 -1.095 0.009 -0.253 -0.940 0.526 1.623 --- On Mon, 11/2/09, David Winsemius <dwinsemius at comcast.net> wrote:> From: David Winsemius <dwinsemius at comcast.net> > Subject: Re: [R] qqplot > To: "carol white" <wht_crl at yahoo.com> > Cc: r-help at stat.math.ethz.ch > Date: Monday, November 2, 2009, 8:17 AM > > On Nov 2, 2009, at 10:40 AM, carol white wrote: > > > Hi, > > We could use qqplot to see how two distributions are > different from each other. To show better how they are > different (departs from the straight line), how is it > possible to plot the straight line that goes through them? I > am looking for some thing like qqline for qqnorm. I thought > of abline but how to determine the slope and intercept? > > I always assumed that the intercept was zero and the slope > = unity. > > y <- rt(200, df = 5) > qqnorm(y); qqline(y, col = 2) > qqplot(y, rt(300, df = 5)) > abline(0, 1, col="red") > > I am open to education if that assumption is too > simplistic, but you have not offered anything in the way of > a counter-example. > > > > => > David Winsemius, MD > Heritage Laboratories > West Hartford, CT > >-------------- next part -------------- A non-text attachment was scrubbed... Name: qqplot.png Type: image/png Size: 6174 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20091102/5002dcdf/attachment-0002.png>
David Winsemius <dwinsemius at comcast.net> wrote>I always assumed that the intercept was zero and the slope = unity. > > y <- rt(200, df = 5) > qqnorm(y); qqline(y, col = 2) > qqplot(y, rt(300, df = 5)) > abline(0, 1, col="red") >Suppose you have the following x <- rnorm(500) y <- 500*(x + runif(500, 0,1)) qqplot(x,y) Then an abline(0,1) will not be useful; it will be an almost horizontal line. But m1 <- lm(y~x) abline(coef(m1)) does the trick. Peter Peter L. Flom, PhD Statistical Consultant Website: www DOT peterflomconsulting DOT com Writing; http://www.associatedcontent.com/user/582880/peter_flom.html Twitter: @peterflom
carol white <wht_crl at yahoo.com> wrote>So the conclusion is that abline(0,1) should always be used and if it doesn't go through the qqplot, the two distributions are not similar?I think it depends what you mean by "similar". E.g., if you mean "are both of these distributions (e.g.) normal?" then abline(0,1) is not always useful. But if you mean "Do these have the same mean, sd, and distribution?" then abline(0,1) is the way to go. Peter Peter L. Flom, PhD Statistical Consultant Website: www DOT peterflomconsulting DOT com Writing; http://www.associatedcontent.com/user/582880/peter_flom.html Twitter: @peterflom
John Fox <jfox at mcmaster.ca> wrote> >I assumed that Carol wanted to compare the shapes of the distributions and >to adjust for differences in centre and spread. To put a line through the >quartiles or to base a line on the medians and IQRs is more robust than >using the means and sds. >Hi John Indeed it is. It all depends on what she wants to use the QQplot for, and what she wants to adjust for. But I would guess (and I haven't done any simuls) that the method with mean and sd will usually be pretty close to the one with medians and IQRs. Maybe I will look at it a bit. Peter Peter L. Flom, PhD Statistical Consultant Website: www DOT peterflomconsulting DOT com Writing; http://www.associatedcontent.com/user/582880/peter_flom.html Twitter: @peterflom
Peter Ehlers <ehlers at ucalgary.ca> wrote> >That's not what qqline() does and for good reason - it treats >x and y asymmetrically. > >But qqline() is a very simple function, using the quartiles >as also suggested by John. Here's a modified version that >should work for Carol: > >qqline2 <- function (x, y, ...) >{ > y <- quantile(y[!is.na(y)], c(0.25, 0.75)) > x <- quantile(x[!is.na(x)], c(0.25, 0.75)) > slope <- diff(y)/diff(x) > int <- y[1L] - slope * x[1L] > abline(int, slope, ...) >} > >I've just replaced the line using Normal quantiles with >the quantiles of x (and omitted the datax option). >Peter Good point. Peter Peter L. Flom, PhD Statistical Consultant Website: www DOT peterflomconsulting DOT com Writing; http://www.associatedcontent.com/user/582880/peter_flom.html Twitter: @peterflom