5
$\begingroup$

I get the same p-value for a one-tailed and two-tailed exact binomial test for some combinations of x, n, and p. Does anyone know why this happens? What formula does R use to calculate the p-value for two-tailed binomial tests?

>binom.test(x=2,n=9,p=.1, alternative="greater")

Exact binomial test

data:  2 and 9
number of successes = 2, number of trials = 9, p-value = 0.2252
alternative hypothesis: true probability of success is greater than 0.1
95 percent confidence interval:
0.04102317 1.00000000
sample estimates:
probability of success 
             0.2222222 

> binom.test(x=2,n=9,p=.1, alternative="two.sided")

    Exact binomial test

data:  2 and 9
number of successes = 2, number of trials = 9, p-value = 0.2252
alternative hypothesis: true probability of success is not equal to 0.1
95 percent confidence interval:
0.02814497 0.60009357
sample estimates:
probability of success 
             0.2222222 
$\endgroup$

1 Answer 1

4
$\begingroup$

This hypothesis test is based on the so-called Clopper-Pearson interval. The one sided-test ''greater'' computes the probability to have a value at least 2 under a binomial density:

size<-9
x<-2
p<-0.1
# compute probability that outcome is >= 2, i.e. x:size
p.value<-sum(dbinom(x:size, prob=p, size=size))

p.value

If you do a two-sided test, you look at the probability that the outcome is equal to 2 (dbinom(x=2,prob=p,size=size)) and you compute the probability of all outcomes with a probability lower than or equal to that:

all.probs<-dbinom(0:size, prob=p, size=size)
# probability that the outcome is x=2
prob.x<-dbinom(x=x, prob=p, size=size)

# probability of all outcomes that have a probability lower than or equal to the probability of the outcome 2 (prob.x) 
p.value<-sum(all.probs[all.probs <= prob.x])
p.value

If you draw the plot (plot(0:size, all.probs) ) you will see that there are no outcomes with a probability smaller than or equal to that for the outcome 2 in the left queue.

If you do the same with size<-30 you will see that there are such outcomes in the left queue (and that for n=30 test.binom will give different results for one- and two-sided tests).

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.