title: Optim error: function cannot be evaluated at initial parameters
body: <pre><code>library('AER')
  data(Affairs)
  attach(Affairs)
  
  tobit.ll &lt;-function(theta,y,X){ 
  y &lt;- affairs
  X &lt;- cbind(1, age, yearsmarried, religiousness ,occupation ,rating)
  n &lt;-nrow(X)
  k &lt;-ncol(X)
  sigm &lt;-theta[k+1]
  bet &lt;- theta[1:k]  
  bet[1]&lt;-theta[1]; bet[2] &lt;- theta[2]; bet[3]&lt;- theta[3]; 
  bet[4] &lt;-theta[4]; bet[5] &lt;- theta[5]; bet[6] &lt;- theta[6]; sigm &lt;-theta[7]
  theta &lt;-c(bet, sigm)
  res &lt;- y-X%*%bet
  
  for(j in 1:k){
     for(i in 1:n){
  
         if(y[i]&gt;0){
         d=1
         } else {
         d=0
         }
      ll &lt;-sum(d*(-0.5*n*log(2*pi)-0.5*n*log(sigm)^2-sum(0.5* (t(res[i])%*%res[i])^2/sigm^2))+(1-d)*(log(1-pnorm((X[i,j]*bet[j])/sigm))))
     } 
   }  
   return(ll)
  }
  
  tobit.b &lt;- optim(c(0,0,0,0,0,0,0),tobit.ll, method="Nelder-Mead")
  </code></pre>
  
  <p>=======================================================================</p>
  
  <p>I think these parameters are vetors. I don't know why I have this error message all the time.</p>