Walter Anderson
2011-Mar-29 13:57 UTC
[R] How to regress data into coefficients for a gamma function
Hello, I need to regress data like the example below. The data points represent friction factors derived from observed trip length data. The function used to describe this data is a gamma function of the form, f(t) = a * t^b * e^(c*t) and I need to regress the data to obtain the a,b, and c coefficients. The gamma function can also be expressed in the log-linear form, ln[f(t)] = ln[a] + b * ln[t] + c*t, which may be easier to perform a regression on. I have performed a search for information on the subject, and have found a few possibly related sites, I can not figure out how to perform the regression in R. Any help/guidance would be appreciated. Walter t f ln(f) 1 1 952893 13 2 2 951077 13 3 3 945991 13 4 4 942358 13 5 5 939452 13 6 6 895494 13 7 7 891861 13 8 8 882416 13 9 9 873697 13 10 10 867885 13 11 11 797771 13 12 12 791595 13 13 13 779243 13 14 14 773068 13 15 15 765802 13 16 16 635383 13 17 17 628481 13 18 18 620488 13 19 19 612859 13 20 20 609590 13 21 21 508597 13 22 22 503511 13 23 23 498425 13 24 24 490069 13 25 25 486073 13 26 26 422862 12 27 27 418866 12 28 28 415233 12 29 29 408331 12 30 30 405424 12 31 31 263380 12 32 32 261201 12 33 33 257204 12 34 34 252845 12 35 35 250665 12 36 36 209978 12 37 37 205981 12 38 38 203438 12 39 39 199079 12 40 40 197263 12 41 41 154758 11 42 42 152942 11 43 43 149309 11 44 44 148583 11 45 45 147493 11 46 46 98086 11 47 47 97723 11 48 48 95906 11 49 49 94090 11 50 50 93363 11 51 51 81738 11 52 52 81012 11 53 53 80649 11 54 54 79559 11 55 55 79195 11 56 56 70477 11 57 57 70477 11 58 58 70477 11 59 59 70477 11 60 60 70477 11 61 61 42867 10 62 62 42140 10 63 63 42140 10 64 64 42140 10 65 65 41777 10 66 66 36691 10 67 67 36328 10 68 68 35965 10 69 69 35965 10 70 70 35965 10 71 71 31968 10 72 72 31968 10 73 73 31968 10 74 74 31968 10 75 75 31605 10 76 76 21070 9 77 77 20707 9 78 78 20707 9 79 79 20343 9 80 80 19980 9 81 81 15984 9 82 82 15984 9 83 83 15984 9 84 84 15984 9 85 85 15984 9 86 86 14168 9 87 87 14168 9 88 88 14168 9 89 89 14168 9 90 90 14168 9
Peter Ehlers
2011-Mar-29 18:04 UTC
[R] How to regress data into coefficients for a gamma function
On 2011-03-29 06:57, Walter Anderson wrote:> Hello, > > I need to regress data like the example below. The data points > represent friction factors derived from observed trip length data. The > function used to describe this data is a gamma function of the form, > f(t) = a * t^b * e^(c*t) and I need to regress the data to obtain the > a,b, and c coefficients. The gamma function can also be expressed in > the log-linear form, ln[f(t)] = ln[a] + b * ln[t] + c*t, which may be > easier to perform a regression on. I have performed a search for > information on the subject, and have found a few possibly related sites, > I can not figure out how to perform the regression in R. Any > help/guidance would be appreciated. > > Walter > > t f ln(f) > 1 1 952893 13 > 2 2 951077 13 > 3 3 945991 13 > 4 4 942358 13 > 5 5 939452 13[... more data snipped ...] This looks like easy grist for the nls() mill. I would usually use the log form to get reasonable starting values for the nls interations: ## assume that your data are in a data.frame DF; fm1 <- lm( log(f) ~ log(t) + t, data = DF ) coef(fm1) # (Intercept) log(t) t # 13.81370501 0.18469223 -0.05955323 startvec <- c( aa=exp(14), bb=0.2, cc=-.06 ) fm2 <- nls( f ~ aa * t^bb * exp(cc*t), data=DF, start=startvec ) #summary(fm2) coef(fm2) # aa bb cc # 9.093841e+05 2.294895e-01 -5.951806e-02 ## plot the data plot( f ~ t, data=DF ) lines( fitted(fm2) ~ t, data=DF ) I wouldn't trust the model for small t. Peter Ehlers
JLucke at ria.buffalo.edu
2011-Mar-30 13:32 UTC
[R] How to regress data into coefficients for a gamma function
Regression for the gamma distribution can be expressed as a generalized linear model. Check Chapter 8 of McCullagh, P. & Nelder, J. A. (1989), Generalized linear models, Chapman & Hall, London, UK. Walter Anderson <wandrson01@gmail.com> Sent by: r-help-bounces@r-project.org 03/29/2011 09:57 AM To r-help@r-project.org cc Subject [R] How to regress data into coefficients for a gamma function Hello, I need to regress data like the example below. The data points represent friction factors derived from observed trip length data. The function used to describe this data is a gamma function of the form, f(t) = a * t^b * e^(c*t) and I need to regress the data to obtain the a,b, and c coefficients. The gamma function can also be expressed in the log-linear form, ln[f(t)] = ln[a] + b * ln[t] + c*t, which may be easier to perform a regression on. I have performed a search for information on the subject, and have found a few possibly related sites, I can not figure out how to perform the regression in R. Any help/guidance would be appreciated. Walter t f ln(f) 1 1 952893 13 2 2 951077 13 3 3 945991 13 4 4 942358 13 5 5 939452 13 6 6 895494 13 7 7 891861 13 8 8 882416 13 9 9 873697 13 10 10 867885 13 11 11 797771 13 12 12 791595 13 13 13 779243 13 14 14 773068 13 15 15 765802 13 16 16 635383 13 17 17 628481 13 18 18 620488 13 19 19 612859 13 20 20 609590 13 21 21 508597 13 22 22 503511 13 23 23 498425 13 24 24 490069 13 25 25 486073 13 26 26 422862 12 27 27 418866 12 28 28 415233 12 29 29 408331 12 30 30 405424 12 31 31 263380 12 32 32 261201 12 33 33 257204 12 34 34 252845 12 35 35 250665 12 36 36 209978 12 37 37 205981 12 38 38 203438 12 39 39 199079 12 40 40 197263 12 41 41 154758 11 42 42 152942 11 43 43 149309 11 44 44 148583 11 45 45 147493 11 46 46 98086 11 47 47 97723 11 48 48 95906 11 49 49 94090 11 50 50 93363 11 51 51 81738 11 52 52 81012 11 53 53 80649 11 54 54 79559 11 55 55 79195 11 56 56 70477 11 57 57 70477 11 58 58 70477 11 59 59 70477 11 60 60 70477 11 61 61 42867 10 62 62 42140 10 63 63 42140 10 64 64 42140 10 65 65 41777 10 66 66 36691 10 67 67 36328 10 68 68 35965 10 69 69 35965 10 70 70 35965 10 71 71 31968 10 72 72 31968 10 73 73 31968 10 74 74 31968 10 75 75 31605 10 76 76 21070 9 77 77 20707 9 78 78 20707 9 79 79 20343 9 80 80 19980 9 81 81 15984 9 82 82 15984 9 83 83 15984 9 84 84 15984 9 85 85 15984 9 86 86 14168 9 87 87 14168 9 88 88 14168 9 89 89 14168 9 90 90 14168 9 ______________________________________________ R-help@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. [[alternative HTML version deleted]]