Calculate the expected number of 95% confidence interval of binomial distribution Can anyone show me how to calculate the expected number of 95% confidence interval of a binomial distribution using R, such as $\text{Bin}(100,0.5)$.
 A: Confidence intervals define the spread from the mean that would give you the % of the mass that you want. For example, a 95% confidence interval of a standard normal will tell you [-1.96, 1.96] because if you integrate the PDF from -1.96 to 1.96, you'll get 0.95. 
Understandably, for discrete variables (like a binomial), this is slightly trickier (you would need to specify an integral range like 4...96 for a case when n=100, p=0.5). Also, the mean may not be integral (the mean of a binomial is $n p$). 
But, if you were to threshold these values into integers:
$\text{lower limit} = \text{int}(n p - \text{width})$
$\text{upper limit} = \text{int}(n p + \text{width})$
Then you would compute the binomial CDF (i.e. the area under the PDF) to find the width that came closest to your desired confidence:
$\text{CDF}(\text{upper limit}) - \text{CDF}(\text{lower limit}) \approx 0.95$
Then choose the (integral) width that gives you the closest result. 
I hope this helps you understand confidence intervals better!
