Re: [R] optim or nlminb for minimization, which to believe?

2009-11-30 Thread Ravi Varadhan
Hi Harold, Hans is right. You can see this if you use BB::spg require(BB) opt2 - spg(startVal, fn) # this is fine opt3 - spg(startVal, fn,gradient) # this is not fine! opt3 - spg(startVal, fn, gradient) Gradient check details: max. relative difference in gradients= 0.001697913

[R] optim or nlminb for minimization, which to believe?

2009-11-29 Thread Doran, Harold
I have constructed the function mml2 (below) based on the likelihood function described in the minimal latex I have pasted below for anyone who wants to look at it. This function finds parameter estimates for a basic Rasch (IRT) model. Using the function without the gradient, using either

Re: [R] optim or nlminb for minimization, which to believe?

2009-11-29 Thread Hans W Borchers
Your function named 'gradient' is not the correct gradient. Take as an example the following point x0, very near to the true minimum, x0 - c(-0.2517964, 0.4898680, -0.2517962, 0.4898681, 0.7500995) then you get gradient(x0) [1] -0.0372110470 0.0001816991 -0.0372102284