Quick binomial test for high number of trials

1.1k Views Asked by At

I just wanted to perform a quick binomial test for an experiment (Bernoulli trial) with 185 successes out of 459 trials and a (hypothesized) success probability of 0.2. I do not have any mathematical software installed right now and would like to get the result without much effort, i.e., without installing a huge software suite just to perform this one calculation.

I tried a lot of online calculators as well as Excel (which happens to be installed on the PC I am currently working on), but the results I get are either invalid (larger than 1, smaller than zero) or "NaN". I suspect that this is due to floating point errors and/or the limited precision of the underlying floating point calculations. After all, the intermediate values for the CDF calculation will be quite large for my values described above.

WolframAlpha outputs 1 for the following expression

CDF[BinomialDistribution[459, 0.2], 185]

and 0 for the complement:

1-CDF[BinomialDistribution[459, 0.2], 185]

(http://www.wolframalpha.com/input/?i=1-CDF%5BBinomialDistribution%5B459%2C+0.2%5D%2C+185%5D)

Similarly, Excel 2010 outputs 1 for the following formula

=BINOMDIST(185;459;0.2;TRUE)

and a very small negative value (around -2.6E-14) for the complement:

=1-BINOMDIST(185;459;0.2;TRUE)

Is there any way to get a better approximation for this? I think that the values I am looking for are very close to 1 and 0, respectively, but I would like to know whether they are close enough for practical purposes, i.e., whether they are significant (say, at a significance level of 1 or 5%).

Best regards Andreas

2

There are 2 best solutions below

4
On BEST ANSWER

The sample size is big enough that we can approximate the binomial distribution with a normal distribution that under the null hypothesis has mean $0.2 \times 459=91.8$ and variance $0.2\times 0.8\times 459=73.44$. Then $$ Pr(X \geq 185)=Pr(Z\geq (185-91.8)/8.57) =Pr(Z\geq 10.88) $$ The probability that the success probability is $0.2$ is very small.

3
On

If you want to add very small positive numbers, compute the log of each number instead of the number (easy for binomial distribution, the multiplication/division turns into a sum) and then sort the logged values from smallest to largest. Suppose you have computed $A$, the log of the sum of the first $k$ numbers, and let $B$ be the log of the $k+1$th number. Assume without loss of generality that $A \leq B$ (otherwise just swap them). Then

$$\log(e^A + e^B) = A + \log(1 + e^{B-A})$$

and if $A$ and $B$ are close enough then this will give you a non-trivial result and avoid underflow and overflow. If you're doing a one-sided statistical test, then just add up the (log) probabilities of getting that many successes or higher, all the way up to the maximum possible number of successes.