title: Finding the peak on a density plot
body: <p>I've created a series of numbers using the <code>rbeta</code> function.</p>
  
  <pre><code>set.seed(123)
  n = 100000
  p1.12.2 = rbeta(n, 0.3225928, 1.2903712)
  p4.7.2 = (rbeta(n, 0.3488823,  3.1399407)^2)
  E2 = p4.7.2*p1.12.2
  </code></pre>
  
  <p>This runs fine but I would like to find the mode of E2, so I've done this by getting the peak of the density plot.</p>
  
  <pre><code>d = density(E2)
  i = which.max(d$y)
  M2 = d$x[i]
  M2
  </code></pre>
  
  <p>I keep getting a negative value for the mode. But the beta distribution is confined to 0-1. Any ideas where the negative values are coming from or is there another way to get the mode of a bin?</p>