# [R] Gradient problem in nlm

Date: Sat 30 Sep 2006 - 16:09:06 GMT

I am having some trouble supplying the gradient function to nlm in R for windows version 2.2.1.

What follows are the R-code I use:

fredcs39<-function(a1,b1,b2,x){return(a1+exp(b1+b2*x))} loglikcs39<-function(theta,len){
value<-sum(mcs39[1:len]*fredcs39(theta,theta,theta,c(8:(7+len))) - pcs39[1:len] * log(fredcs39(theta,theta,theta,c(8:(7+len))))) a1<-theta; b1<-theta; b2<-theta df.a1<-sum(-mcs39[1:len] + pcs39[1:len]/(a1+exp(b1+b2*c(8:(7+len)))))

```df.b1<-sum( -mcs39[1:len] * exp(b1+b2*c(8:(7+len))) + (pcs39[1:len] *
exp(b1+b2*c(8:(7+len))) ) /(a1+exp(b1+b2*c(8:(7+len)))))
df.b2<- sum(-mcs39[1:len] * exp(b1+b2*c(8:(7+len))) * c(8:(7+len))  +
```
(pcs39[1:len] * exp(b1+b2*c(8:(7+len))) * c(8:(7+len)) ) /(a1+exp(b1+b2*c(8:(7+len)))) )

}

theta.start<-c(0.01 ,-1.20, -0.0005)
outcs39<-nlm(loglikcs39,theta.start,len=50)

Error in nlm(loglikcs39, theta.start, len = 50) :

probable coding error in analytic gradient

Any light that can be shed on this would be highly appreciated. Many thanks

Singyee Ling

[[alternative HTML version deleted]]

R-help@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. Received on Sun Oct 01 02:19:44 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 14 Oct 2006 - 18:30:09 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.