0

Possible Duplicate:
Fitting a density curve to a histogram in R

I'm trying to add a best fit normal over a histogram in R. Right now, I have the following:

x<-table[table$position==1,]$rt
hist(x,breaks=length(x))

And now I'd like to plot a normal curve over this plot which allows for skew and for kurtosis. How can I do this? This is what my curve looks like:

enter image description here

Community
  • 1
  • 1
CodeGuy
  • 28,427
  • 76
  • 200
  • 317
  • 1
    That may be the mother of all FAQs related to extending a histogram. Do you know SO has a search function? Here is one such find from about three seconds of searching: http://stackoverflow.com/questions/1497539/fitting-a-density-curve-to-a-histogram-in-r – Dirk Eddelbuettel Sep 30 '11 at 02:16
  • I don't see anything that works. none of the density fits look right. – CodeGuy Sep 30 '11 at 02:20
  • they all still have multiple humps. none of thoes examples have a single line distribution. – CodeGuy Sep 30 '11 at 02:38

1 Answers1

9

I would suggest not using the terms "skew" and "kurtosis" in the same sentence with "Normal curve", since Normal curves have neither. Perhaps you are looking for one or two parameter continuous density distribution that might be comparable to a function that was bounded at zero and had right skewing? If so then you should think about a) posting the data, b) consider plotting a Poisson, a log-Normal, or a gamma density on top of a histogram.

set.seed(123)
xpois <- trunc(rpois(100, 4))
hist(xpois)
lines(seq(0,10), 100*dpois(seq(0,10), 4))

enter image description here

IRTFM
  • 258,963
  • 21
  • 364
  • 487