How to calculate sample size in binominal distribution?

749 Views Asked by At

I have a task that is very time consuming if it were to be done for all cases. Let's say I have X items and I need to check them. Some turn out to be type A, others turn out to be type B. And I need to know what is the percentage of those of type A. (Is it Bernoulli?) For the sake of time I can test a small portion of X. I need to determine how large a sample I should test to get a 95% confidence interval. I have read and even found an example that deals with a similar case to mine and I am deploying that Wald Interval is something I should be interested in.

$$p = \hat{p} \pm z \sqrt{\frac{\hat{p}(1-\hat{p})}{n}}$$

so I know that $z$ shall be: $z=1.96$.

From above equation I can calculate $n$ in that case with:

$$ n = \frac{\hat{p}(1-\hat{p})}{(\frac{p-\hat{p}}{z})^2}$$

In the example I found, someone assumed that the proportion is 15% (0.15) and interval width +- 0.2%. So the confidence interval is 0.148 to 0.152 (this is p without hat). But after all, this 15% is just an assumption. Taking for example 30% we have a completely different result, different $n$. How to interpret it?

In another example I found it says that Cochran's sample size formula was used (without specifying which one). Assumed confidence interval of 95% with an error margin of approximately 0.6%. The result was that the sample must be 27000. I tested various cases in Excel and according to me in this case the proportion $\hat{p}=0.5$ was assumed, then the sample comes out exactly 26677.78 which was rounded to 27000 for certainty.

my calculations for second example

Please help.