How to formulate an analytical gradient? Suppose I have the following function/expression: fr<-function(x){ x1=x[1] x2=x[2] x3=x[3] x4=x[4] x5=x[5] 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.