TIMMMAY ed_deroiste at yahoo.co.uk
Sun Jul 15 23:05:47 CEST 2007

```Followings someones advice on a previous post I am reposting my question
again. Here is is and I would appreciate any help with my problem. This
question is basically a mathematical question, but I am sure there must be
an easy way to achieve the answer to my problem using R as, my problem seems
to me to be quite straight forward and something that people must use quite
a lot. So if there is an easy way to do this I would appreciate the help.

I have a transition intensities at different ages in a markov model. I want
to estimate this intensity by fitting a curve to the known intensities. The
data is as follows

Age Intensity
22 0.0002
27 0.0011
32 0.0074
37 0.0159
42 0.0292
47 0.0428
52 0.0265
57 0.0301
62 0.0270
67 0.0296

When plotted as intensity vs age, the data looks like a gamma curve. I want
to fit a gamma density curve to this data, so I need to estimate the
paramaters for the gamma curve,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,p)*p))^2)
a residual sum of squares and using nlm to minimise this and find paramaters
but I cant get this to work either. Can anyone help me ?? Please :)

Thanks

TIMMMAY wrote:
>
> I posted the message below a few days ago but I have not had any
> responses. I keep thinking that there must be some easy way to answer the
> problem I am just not familiar enough with regression to answer the
> problem myself. If anyone can help me I would be very grateful. I need to
> fit a gamma curve to a set of data. ie a scatterplot of the data indicates
> that the curve looks like a truncated gamma density function and I would
> like to estimate the paramaters so that I can fit a curve to the data
> points. Its not MLE paramater estimation just a curve fitting exercise.
> The problem again is
>
> 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,p)*p))^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 :)
>
> Original message follows :(
> Fitting a Gamma Curve
> by TIMMMAY Jul 12, 2007; 03:38pm :: Rate this Message:    (use ratings to
> moderate[?])
>
>
> 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,p)*p))^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 :)
>
>
>
>
>
> Start a free forum or mailing list archive on Nabble  Help - Powered by -