[R] Gamma curve fit to data with specific bins

Lorentz, Andrew a.m.lorentz at cranfield.ac.uk
Mon May 20 17:44:08 CEST 2013


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)



More information about the R-help mailing list