Skip to content

The difference between chisq.test binom.test and pbinom

3 messages · Tal Galili, Peter Ehlers

#
On 2012-08-20 12:24, Tal Galili wrote:
Let's first dispense with the chisq.test value; that uses the Normal
approximation and the calculation is trivial; the other two don't.

Let's do a one-sided test:

  binom.test(x=62, n=112, p=.512, alternative="greater")$p.value
  # 0.2161936

Compare with:

  pbinom(61, 112, .512, lower.tail=FALSE)
  # 0.2161936

Why '61' instead of '62'? Because we want to include 62 in the
upper tail probability.

Now it's just a matter of how to calculate the lower tail probability
in binom.test. Hint: it's not just set equal to the upper tail
probability (hence no '2*xxx').
The expected value (under H0) is 112*0.51 = 57.12.
Thus 62 is 4.88 ~ 5 units higher than the EV.
Now calculate the probability of an outcome that is 5 units *less*
(or lower) than the EV:

  pbinom(52, 112, .512)
  # 0.1799121

Add the two probabilities to get:

  0.2161936 + 0.1799121
  # 0.3961057

and that's what binom.test() reports.
For details, have a look at the binom.test code.

Peter Ehlers