arindam fadikar wrote: > > > loglik <- function(par) > { > p=par[1] > q=par[2] > r <- 1 - p - q > if (c(p,q,r) > rep(0,3) && c(p,q,r) < rep(1,3) ) > { > -(2 * nO * log (r) + nA * log (p^2 + 2 * p * r) > + nB * log (q^2 + 2 * q * r) > + nAB * (log(2) +log(p) +log(q))) > } > else > NA > } > loglik > } > ..... >
Extending the tests in the if in loglik to if (c(p,q,r) > rep(0,3) && c(p,q,r) < rep(1,3) && (p^2 + 2*p*r)>0 && (q^2 + 2*q*r)>0) would also help. /Berend -- View this message in context: http://r.789695.n4.nabble.com/how-to-avoid-NaN-in-optim-tp2738093p2746635.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org 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.