[R] using nls for gamma distribution (a,b,d)

Walmes Zeviani walmeszeviani at hotmail.com
Thu Apr 15 19:25:23 CEST 2010


I never had seen someone using a density function for a mean function in
nonlinear regression. The convergence problem observed can be due the model
derivatives respect to the parameters. How could computationally be
d.gamma/d.alpha? digamma function? Does R understand this?

If your phenomena exhibit a gamma density form you could use a mean function
like:

fun <- function(x, alpha, beta, theta){
  x*(alpha+beta*x)^(-1/theta)
}

da <- data.frame(x=1:20)
da$y <- fun(da$x, 1, 2, 0.9)+rnorm(da$x,0,0.001)

plot(y~x, da)
curve(fun(x, 1,2,0.9), 1, 100, add=TRUE)

n0 <- nls(y~fun(x, alpha, beta, theta), data=da,
          start=list(alpha=1, beta=2, theta=0.9))

Or you can use a gamma density without the integration equal one. So, you
can replace the gamma(alpha) for B term:

gammafun <- function(x, alpha, B, b){
  (1/B)*alpha^b*x^(b-1)*exp(-x/alpha)
}

curve(gammafun(x, 5, 1, 2), 0, 20)

da <- data.frame(x=1:20)
da$z <- gammafun(da$x, 5, 1, 2)+rnorm(da$x,0,1)

plot(z~x, da)
curve(gammafun(x, 5, 1, 2), add=TRUE)

n1 <- nls(z~gammafun(x, alpha, B, b), data=da,
          start=list(alpha=5, B=1, b=2))

Sincerely.
Walmes.

-----
..ooo0
...................................................................................................
..(....)... 0ooo...                              Walmes Zeviani
...\..(.....(.....)...     Master in Statistics and Agricultural
Experimentation
....\_)..... )../....       walmeszeviani at hotmail.com, Lavras - MG, Brasil
............
(_/............................................................................................
-- 
View this message in context: http://n4.nabble.com/using-nls-for-gamma-distribution-a-b-d-tp1899967p1909193.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list