Re: [R] graphs of gamma, normal fit to a histogram are about half as large as they should be

From: Benjamin Caldwell <btcaldwell_at_berkeley.edu>
Date: Tue, 17 May 2011 14:20:46 -0700

Rolf,

Taking out the scalar multiples did it. Thanks for that.

*Ben Caldwell*

PhD Candidate
University of California, Berkeley

On Sun, May 15, 2011 at 10:30 PM, Rolf Turner <rolf.turner_at_xtra.co.nz>wrote:

>
> In your example it appears that you are plotting a histogram (on the
> frequency
> scale) and then superimposing scalar multiples of gamma and Gaussian
> densities.
>
> You should just plot a histogram (with frequency=FALSE) and then
> superimpose the
> densities --- without any scalar multipliers.
>
> If that doesn't work, please provide a minimal *reproducible* (no one but
> you
> has the ``rwb'' data object) example of the problem that you are having
> (as the posting guide requests).
>
> cheers,
>
> Rolf Turner
>
>
>
> On 16/05/11 17:01, Benjamin Caldwell wrote:
>
> Hmm; still missing something - hist defaults to frequencies, not prob.
> densities; and, I thought I'd scaled the fitted lines to the values in the
> data frame. Just going with it, I specified freq=FALSE, and the prob density
> was of course at a different order of magnitude than the lines.
>
> What are you trying to hint at?
>
>
> On Fri, May 13, 2011 at 6:05 PM, Rolf Turner <rolf.turner_at_xtra.co.nz>wrote:
>
>> On 14/05/11 10:00, Benjamin Caldwell wrote:
>>
>>> Hello,
>>>
>>> I'm trying to compare the fit of two distributions, normal and gamma, to
>>> a
>>> histogram of my response variable.
>>>
>>>
>>> rate<-mean(na.omit(rwb$post.f.crwn.length))/var(na.omit(rwb$post.f.crwn.length))
>>> shape<-rate*mean(na.omit(rwb$post.f.crwn.length))
>>> hist((rwb$post.f.crwn.length), main="rwb$post.f.crwn.length")
>>>
>>> lines(seq(0.01,70,0.01),length(rwb$post.f.crwn.length)*dgamma(seq(0.01,70,0.01),shape,rate))
>>>
>>> lines(seq(0,70,0.1),length(na.omit(rwb$post.f.crwn.length))*dnorm(seq(0,70,.1),mean(na.omit(rwb$post.f.crwn.length)),sqrt(var(na.omit(rwb$post.f.crwn.length))))
>>>
>>> However, the height of the two curves are about 1/3 to 1/4 the height
>>> that
>>> they should be compared to the histogram. Any ideas?
>>>
>>
>> Yes. Read the help on "hist"! (Hint: Pay particular attention to the
>> "freq" and/or "probability" arguments.)
>>
>> cheers,
>>
>> Rolf Turner
>>
>
>
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
success.png
Received on Tue 17 May 2011 - 21:24:02 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 17 May 2011 - 22:10:07 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive