Benjamin Caldwell
2011-May-13 22:00 UTC
[R] graphs of gamma, normal fit to a histogram are about half as large as they should be
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? Thanks *Ben Caldwell* PhD Candidate University of California, Berkeley
Rolf Turner
2011-May-14 01:05 UTC
[R] graphs of gamma, normal fit to a histogram are about half as large as they should be
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
Reasonably Related Threads
- using glmer to fit a mixed-effects model with gamma-distributed response variable
- using hglm to fit a gamma GLMM with nested random effects?
- hierarchical gamma model in lme4
- avoiding expression evaluation when calling a function
- using lme4 with three nested random effects