[R] Overlaying graphs
spencer.graves at pdf.com
Thu Sep 4 16:34:27 CEST 2003
Your observation that qqnorm "does not appear to be very general" is
rebutted by Venables and Ripley (2002) Modern Applied Statistics with S,
4th ed. (Springer, p.108): "One of the best ways to compare the
distribution of a sample x with a distribution is to use a Q-Q plot. ...
This idea can be applied quite generally. For example, to test a sample
against a t9 distribution, we might use
plot( qt(ppoints(x), 9), sort(x) )
Before I consider the "best-fitting probability distribution", I want
to know something about the nature of the application and what the
numbers claim to represent: If they are discrete counts, I will not
even consider a normal distribution except as an approximation. If they
are money or physical measurements like power or grams in applications
where they should never be negative, then I may want to take logarithms
first before I do anything else. If lifetime data, I will consider
lognormal and Weibull, and prepare a cumulative hazard plot before doing
much else. If a normal probability plot shows skewness, I will look for
another distribution or a transformation that makes sense with the
application. If it shows discontinuities, I will consider mixtures. By
the time you start considering mixtures, the number of alternative
distributional models becomes infinite.
hope this helps. spencer graves
Paul Meagher wrote:
> My apologies for the last email that only contained the message and not my
> reply. Here is what I meant to send.
> ----- Original Message -----
> From: "Richard A. O'Keefe" <ok at cs.otago.ac.nz>
> To: <paul at datavore.com>
> Sent: Thursday, September 04, 2003 2:56 AM
> Subject: Re: [R] Overlaying graphs
>>I do not know how to overlay the curve graphic on top of hist graphic.
>>Do you know about the "add=TRUE" option for plot()?
> I learned about it from one of the list members and it worked ok for me.
> This is the recipe I finally came up with:
> fat <- read.table("fat.dat", header=TRUE)
> mu <- mean(fat$height)
> sdev <- sd(fat$height)
> par (fin=c(4,4))
> hist(fat$height, br=20, freq=FALSE, col="lightblue",
> border="black", xlab="Male Height in Inches",
> main = paste("Histogram of" , "Male Height"))
> curve(dnorm(x, mu, sdev), add=TRUE, from=64, to=78, col="red", lwd=5)
>>I am hoping to show visually that the normal curve overlays the obtained
>>probability distribution when plotted on the same graph. Unfortunately, I
>>an not sure how to overlay them. Can anyone point me in the right
>>or show me the code.
>>This is a bad way to do it anyway. What you want is a qqnorm plot.
> Yes qqnorm looks like a better tool for this particular job. It does not
> appear to be very general in the sense that you could visually inspect
> whether poissson distributed data conforms to a theoretical poisson
> I guess this leads to two more questions:
> 1. Is the Anderson-Darling goodness-of-fit test the recommended analytic
> test for determining whether a normal distribution conforms to a theoretical
> normal distribution.
> 2. Does R have a suite of "best-fit" tools for finding the best
> fitting-probability distribution for any observed probability distribution?
> Paul Meagher
> R-help at stat.math.ethz.ch mailing list
More information about the R-help