title: Error in using optim function due to length
body: <p>I am trying to estimate the below log function using maximum likelihood method in R, but I get the following error:</p>
  
  <blockquote>
    <p>Error in optim(start, f, method = method, hessian = TRUE, ...) : objective function in optim evaluates to length 10 not 1</p>
  </blockquote>
  
  <p>My attempt was as follows:</p>
  
  <p>Generating data</p>
  
  <pre><code>set.seed(101)
  n &lt;- 10
  u &lt;- runif(n)
  theta1 &lt;- 1
  lamba1 &lt;- 0.5
  </code></pre>
  
  <p>Generating PTIR data using quantile function</p>
  
  <pre><code>x &lt;- function(u, theta1, lamba1) { 
      (-theta1/(log((1+lamba1)-sqrt((1+lamba1)^2-(4*lamba1*u)))/(2*lamba1)))^(1/(2))
  }
  x &lt;- x(u = u, theta1 = theta1, lamba1 = lamba1)
  </code></pre>
  
  <p>Declaring the Log-Likelihood function</p>
  
  <pre><code>LL &lt;- function(theta, lamba) { 
      R = suppressWarnings((n*log(2))+
        (n*log(theta))-(((2)+1)*sum(log(x)))-
        (sum(theta/(x^(2))))+
        (log(1+lamba-(2*lamba*exp(-theta/(x^(2)))))))
      return(-R) 
  }
  mle(LL, start = list(theta = 5, lamba=0.5))
  </code></pre>
  
  <p>Any advice would be greatly appreciated.</p>