I am trying to estimate a binomial proportion p, say, from a sample of binomials. There are k subjects. Associated with each subject is a sample size $n_i$ and a count $x_i$ of items, where $x_i$ is distributed as a binomial $(p, n_i)$. I can assume that the sample sizes are not a function of $p$.
In sampling terms, the sampling unit is the subject, not the number of items $x_i$.
I want to estimate p and provide a confidence interval for it.
Should I take $$\hat{p}=\frac{\sum_i x_i}{\sum_i n_i}$$ or should I take the average of the cluster means? $$ \frac{1}{k} \sum_i \frac{x_i}{n_i}$$
And how should I estimate the standard deviation?