[R] Gamma curve fit to data with specific bins

Rui Barradas ruipbarradas at sapo.pt
Tue May 21 00:49:13 CEST 2013


Hello,

You are fitting a vector other than the vector 'x'.
And you are mistaking the parameter scale for rate.

est <- fitdistr(x,"gamma")$estimate


#plot the gamma curve with the found parameters
hist(x, breaks=Size, freq=FALSE, xlab="Drop Size", ylab="No. of Drops")
curve(dgamma(x, rate=est["rate"], shape=est["shape"]),from=0, to=16, 
main="Gamma
	distribution", ylab="Probability", add = TRUE, col = "red")


Hope this helps,

Rui Barradas

Em 20-05-2013 16:44, Lorentz, Andrew escreveu:
> Good afternoon,
>
> I have some rainfall drop size data (frequency count within drop size) that is already arranged into specific bins (Size). I am looking to fit a gamma curve onto a histogram of the data.
>
> At the moment I have been able to create estimate the gamma parameters from the PDF of the frequencies. And plot the points on the gamma curve.  However, the x-axis is only a count and not the specific drop size values.  Nor have I been able to plot the histogram and the curve together.
>
> Could you advise? Many thanks.
>
> Code:
> # Load the probability data from the Drop Size Distribution
> PDF=c(0.0941,0.2372,0.2923,0.1750,0.0863,0.0419,0.0207,0.0128,0.0142,0.0071,0.0041,0.0031,0.0032,0.0057,0.0022,0.0001)
>
> Freq = c(0,0,197284,497395,613062,366975,181037,87926,43432,26889,29728,14877,8691,6457,6778,1926,4543,123,37,0)
> Size = c(0.0625,0.1875,0.3125,0.4375,0.5625,0.6875,0.8125,0.937,1.063,1.188,1.375,1.625,1.875,2.125,2.375,2.75,3.25,3.75,4.25,4.75)
>
> x<-rep(Size, Freq)
>
> # histogram of probability
> hist(x, breaks=Size, freq=TRUE, xlab="Drop Size", ylab="No. of Drops")
>
> dev.new()
> # Find the parameters of the gamma curve from the PDF
> library(MASS)
> fitdistr(PDF,"gamma")
>
> # scale=0.4495207, shape=7.1923309
>
> #plot the gamma curve with the found parameters
> curve(dgamma(x, scale=.4495207, shape=7.1923309),from=0, to=16, main="Gamma
> distribution", ylab="Probability")
>
> # add the points of the PDF from the data
> points(PDF)
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list