[R] overlaying qqnorm plots...

Paul Murrell p.murrell at auckland.ac.nz
Tue Nov 27 20:40:55 CET 2001


> I know this topic has had plenty of discussion in the last couple of days,
> but....
> I've been trying to compare the effects of different fitted methods for
> systems of equations (OLS, SUR, 2SLS, 3SLS ) and would like to compare the
> residual plots (easy) and the qqnorm/qqplot of the fits for the different
> fitted methdos. For example,
> qqnorm( residuals( lm( q ~ p + f + a ) ) )
> par( new = TRUE )
> qqnorm( residuals( tsls( q ~ p + d, ~ d + f + a ) ) )
> The resulting plot contains the two qqnorm plots, and the x axis stays the
> same. The y axis ("Sample Quantiles") scales for the different plots. I
> would to fix the y axis (fix the quantiles values?) and plot the different
> plots in different colors. Is that possible?

Yep, ylim can be specified as usual ...

    y1 <- rnorm(100)
    y2 <- rexp(100)
    qqnorm(y1, ylim=range(y1, y2), col="blue")
    qqnorm(y2, ylim=range(y1, y2), col="red")

... NOTE that this does a lot of unnecessary drawing;  an alternative is to
get qqnorm to just tell you what x- and y-values it would plot and then use
points() to add the new points rather than draw a whole new plot ...

    y1 <- rnorm(100)
    y2 <- rexp(100)
    qqnorm(y1, ylim=range(y1, y2), col="blue")
    secondpts <- qqnorm(y2, plot.it=FALSE)
    points(secondpts, col="red")

Hope that helps.


r-help 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-help-request at stat.math.ethz.ch

More information about the R-help mailing list