Re: [R] Help on simple problem with optim

2010-09-13 Thread Cristian Montes
Did you check if the data in "da" has any NA in the dependent or the independent data? Remember that your function llk.mar is going to evaluate dnorm for each pair. If any of those pairs has an NA value, your function will return an NA at the end (sum(c(NA,1,2,3)) = NA) I would check if the ll

Re: [R] Help on simple problem with optim

2010-09-09 Thread Berend Hasselman
It is indeed a negative value for sigma that causes the issue. You can check this by inserting this line if(sigma <= 0 ) cat("Negative sigma=",sigma,"\n") after the line mu <- x %*% beta in function llk.mar Negative values for sigma can be avoided with the use of a transforma

Re: [R] Help on simple problem with optim

2010-09-09 Thread William Dunlap
You can record all arguments and return values of the calls that optim(par,fn) makes to fn with a function like the following. It takes your function and makes a new function that returns the same thing but also records information it its environment. Thus, after optim is done you can see its pa

Re: [R] Help on simple problem with optim

2010-09-09 Thread Peng, C
Yanwei!!! Have you tried to write the likelihood function using log-normal directly? if you haven't so, you may want to check ?rlnorm -- View this message in context: http://r.789695.n4.nabble.com/Help-on-simple-problem-with-optim-tp2533420p2533487.html Sent from the R help maili

Re: [R] Help on simple problem with optim

2010-09-09 Thread Thomas Stewart
This is only a guess because I don't have your data: sigma is must be positive in the dnorm function. My guess is that optim may attempt an iteration with a negative sigma. You may want to see help(optim) for dealing with this constraint. Specifically see the lower argument. If you specify th