title: How can the OPTIM function works properly?
body: <p>Here, my function nd works properly but when I used that in OPTIM function it gives error.
  What is my mistake? Codes are </p>
  
  <pre><code>ta=c(2.0, 4.0);       
  n=500;                
  
  x=runif(n);        
  
  TT=rexp(n,1);       
  D=matrix(0,n,1);        
  
  for (j in 1:n) {
  D[j]=ifelse(TT[j]&gt;x[j],1,0)
  }
  
  xt=matrix(0,length(ta),1);
  for (ii in 1:length(ta)) {
   xt[ii]=sum(I(TT&lt;ta[ii])*D)      
  }
  
  nd&lt;- function(params) {
  tta=c(params[1],params[2]);
  ss1=0;
  
  ss1=xt[1]*log(xt[1]/sum(pmin(TT,tta[1])))+(xt[2]-xt[1])*log((xt[2]-xt[1])/sum((pmin(TT,tta[2])-tta[1])*I(TT&gt;tta[1])))+(sum(D)-xt[2])*log((sum(D)-xt[2])/sum((TT-tta[2])*I(TT&gt;tta[2])));
  ll=-ss1;
  
  return (ll)  
   }
  
  
  nn&lt;-optim(par=c(0.5,2.5),fn=nd, method = "L-BFGS-B", lower=c(0.01,2.01), upper=c(3.99, 9.99));
  </code></pre>
  
  <p>I found the following error;</p>
  
  <p>Error in optim(par = c(0.5, 2.5), fn = nd, method = "L-BFGS-B", lower = c(0.01,  : 
    L-BFGS-B needs finite values of 'fn'</p>