# [R] How to formulate an analytical gradient?

From: francogrex <francogrex_at_mail.com>
Date: Thu 18 Jan 2007 - 10:19:39 GMT

How to formulate an analytical gradient?

Suppose I have the following function/expression:

fr<-function(x){

```x1=x
x2=x
x3=x
x4=x
x5=x
```

z<-((gamma(x1+n)))/((gamma(x1)*factorial(n))*((1+(e/x2))^x1)*((1+(x2/e))^n)) v<-((gamma(x3+n)))/((gamma(x3)*factorial(n))*((1+(e/x4))^x3)*((1+(x4/e))^n))

sum(log( (x5*z)+ ((1-x5)*v) ))
}

These are a mix of two negative binomial distributions, where n and e are know vectors, and I would like to calculate the maxiumum likelihood estimates of the parameters x1,x2,x3,x4 and X5 I am relying on numerical gradients but I think if I use an analytical one it will be more accurate especially when number of parameters is more than 4.

Thanks.

```--
View this message in context: http://www.nabble.com/How-to-formulate-an-analytical-gradient--tf3033293.html#a8428063
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help