[R] Fitting a Gamma Curve
TIMMMAY
ed_deroiste at yahoo.co.uk
Thu Jul 12 16:38:34 CEST 2007
Hi there, I hope someone can help me before I tear all my hair out. I have a
set transition intensities and when plotted the curve looks like a gamma
density. I want to fit a gamma density curve to these intensities. It is
just a curve fitting problem but whats causing the trouble is that I need to
use least squares minimization to calculate the parameters for the gamma
curve. How do I do this???
The curve will be a truncated gamma function so it will have 3 paramaters a,
b, c. I tried to do the following
nls(lograte ~ log(c) + a*log(b) + (a-1)*log(age)+b*(age)-lgamma(a),
start=list(a=1,b=1,c=1)), where lograte, and age are my data. a,b the gamma
parameters and c the parameter we need because we are fitting a truncated
distribution.
I also tried defining
fn = function(p) sum((log(y)-log(dgamma(x,p[1],p[2])*p[3]))^2)
a residual sum of squares and using nlm to minimise this and find paramaters
but this doesnt work either. Can anyone help me ?? Please :)
--
View this message in context: http://www.nabble.com/Fitting-a-Gamma-Curve-tf4068543.html#a11561404
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list