title: Fitting Binomial Distribution in R using data with varying sample sizes
body: <p>I have some data that looks like this:</p>
  
  <pre><code>    x    y
  1:  3    1
  2:  6    1
  3:  1    0
  4: 31    8
  5:  1    0
  ---
  </code></pre>
  
  <p>(Edit: if it helps, here are sample vectors for x and y</p>
  
  <pre><code>    x = c(3, 6, 1, 31, 1, 18, 73, 29, 2, 1)
  
      y = c(1, 1, 0, 8, 0, 0, 8, 1, 0, 0)
  </code></pre>
  
  <p>The column on the left (x) is my sample size, and the column on the right (y) is the number successes that occur in each sample.  </p>
  
  <p>I would like to fit these data using a binomial distribution in order to find the probability of a success (p).  All examples for fitting a binomial distribution that I've found so far assume a constant sample size (n) across all data points, but here I have varying sample sizes.</p>
  
  <ol>
  <li><p>How do I fit data like these, with varying sample sizes, to a binomial distribution?  The desired outcome is p, the probability of observing a success in a sample size of 1.</p></li>
  <li><p>How do I accomplish a fit like this using R?</p></li>
  </ol>
  
  <p>(Edit #2: Response below outlines solution and related R code if I assume that the events observed in each sample can be assumed to be independent, in addition to assuming that the samples themselves are also independent.  This works for my data - thanks!)</p>