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[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 :) Original message follows :( Fitting a Gamma Curve by TIMMMAY Jul 12, 2007; 03:38pm :: Rate this Message: (use ratings to moderate[?]) Reply | Reply to Author | Show Only this Message 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 :) ? Return to forum Start a free forum or mailing list archive on Nabble Help - Powered by - Terms of Use - Jobs at Nabble - Nabble Support -- View this message in context: http://www.nabble.com/Please-Please-Help-me%21%21%21-tf4081887.html#a11601686 Sent from the R help mailing list archive at Nabble.com.
The reason no one answered may be that you did not follow the last line to every r-help message or read and follow the posting guide. Its time consuming to develop a test environment and data needed to clarify and test the answer to a question. By providing data and reproducible code you reduce the amount of time it takes responders to answer thereby making it more likely someone will. On 7/15/07, TIMMMAY <ed_deroiste at yahoo.co.uk> 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[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 :) > > Original message follows :( > Fitting a Gamma Curve > by TIMMMAY Jul 12, 2007; 03:38pm :: Rate this Message: (use ratings to > moderate[?]) > > Reply | Reply to Author | Show Only this Message > > 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 :) > > > > > ? Return to forum > > Start a free forum or mailing list archive on Nabble Help - Powered by - > Terms of Use - Jobs at Nabble - Nabble Support > > -- > View this message in context: http://www.nabble.com/Please-Please-Help-me%21%21%21-tf4081887.html#a11601686 > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >
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[1],p[2])*p[3]))^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[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 :) > > Original message follows :( > Fitting a Gamma Curve > by TIMMMAY Jul 12, 2007; 03:38pm :: Rate this Message: (use ratings to > moderate[?]) > > Reply | Reply to Author | Show Only this Message > > 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 :) > > > > > ? Return to forum > > Start a free forum or mailing list archive on Nabble Help - Powered by - > Terms of Use - Jobs at Nabble - Nabble Support > >-- View this message in context: http://www.nabble.com/Please-Please-Help-me%21%21%21-tf4081887.html#a11606008 Sent from the R help mailing list archive at Nabble.com.