title: R uniroot: Solving an unknown variable in uniroot from a function with multiple arguments
body: <p>I am trying to obtain the value of a variable that is inside a log by using the uniroot function. In the function with the equation I want to solve, I intend on having a vector argument so that I can multiply values from that vector to each log.</p>
  <p>I have tried the method shown in this thread: <a href="https://stackoverflow.com/questions/21842819/call-a-function-with-multiple-arguments-inside-uniroot-in-r">Call a function with multiple arguments inside uniroot in R</a>
  but have not been successful. Please help. Thank you.</p>
  <pre><code>prob.vals &lt;- c()
  x &lt;- 1
  for (i in 0:4) {
    prob.calcs = q^(i)*(1-q)^(4-i)
    prob.vals[x] = prob.calcs
    x &lt;- x + 1
  }
  
  # want to find the value of P
  f = function(P, B = c()) {
    log(5 + 4*P - 4)*B[5] + log(5 + 4*P - 3)*B[4]
    + log(5 + 4*P - 2)*B[3]+log(5 + 4*P - 1)*B[2] +
      log(5 + 4*P)*B[1] - log(5)
  }
  
  uniroot(function(P) f(P, B = prob.vals), lower = 0, upper = 99999999)$root
  </code></pre>