On Tue, 23 May 2006, Mehmet Balcilar wrote: > Hi, > > I am using optim to estimate the parameters of a smooth transition > autoregressive model. I wrote a function to return the gradient for > each observation. So, for k parameters and n observations my function > returns a (n x k) matrix. The gr argument of optim expects a (k x 1) > vector. Now, what is the correct way of passing my gradient matrix to > optim?
gr is documented to be a function, not a vector! Since you are optimizing a numeric function such as the log-likelihood, the derivative is a vector, not a matrix, and your gr function should return a vector. We have far too few details, but for example did you forget to sum over observations? -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
