11.4 Binomial test

We previously learned about estimating proportions, and calculating measures of uncertainty for those estimates.

Now we’ll learn a procedure for testing hypotheses about proportions.

For this example we’ll use the damselfly dataset we used in the previous tutorial regarding hypothesis tests.

Recall that the researcher found that in 17 out of 20 circular battles (or “bouts”) the damselflies flew in the counter-clockwise direction.

The question was: should this result be considered evidence of handedness in this population?


Take a moment to refresh your memory regarding the steps to hypothesis testing.

We’ll explain first how this is a test about a proportion.

Considering the question posed above, we need to first think about what we’d expect if there was truly no “handedness” in the population of damseflies. In this case, then we’d expect the circular battles to occur with equal frequency in both clockwise and counter-clockwise directions.

In other words, if there was no handedness, we’d expect the proportion of battles that are counter-clockwise (the direction we’ll arbitrarily call a “success”) to equal \({p} = 0.5\).

  • We’ll use a binomial test here, because this is the most appropriate (and powerful) test when comparing the observed number of “successes” in a dataset to the number expected under a null hypothesis. Or put another way, we compare an observed proportion of successes in a dataset to the proportion expected under a null hypothesis.

Let’s devise an appropriate null and alternative hypothesis for this question.

H0: The proportion of damselfly battles in the population flown in the counter-clockwise direction is 0.5 (\(p_0 = 0.5\))

HA: The proportion of damselfly battles in the population flown in the counter-clockwise direction is not 0.5 (\(p_0 \ne 0.5\))

  • We’ll use an \(\alpha\) level of 0.05.
  • It is a two-tailed alternative hypothesis; there is no reason to eliminate the possibility that the damselflies exhibit right- or left-“handedness”
  • The binomial test assumes that the random trials were independent, and the probability of success was equal in each trial - we’ll assume so!
  • We don’t need a figure for this test
  • The test statistic is the number of battles that were flown predominantly in the counter-clockwise direction (the direction we arbitrarily chose as a “success”).
  • The binomial test calculates an exact P-value for us (using the binomial equation), and we don’t need to rely on an approximate null distribution, like we do for other tests.

Let’s conduct the test now.

We use the binom.test function that is from the base R package.

?binom.test

Let’s show the code then explain after:

binom.test.results <- binom.test(x = 17, n = 20, p = 0.5, alternative = "two.sided")
  • We create a new object “binom.test.results” to hold the results
  • the arguments for the binom.test function include the number of successes (x), the number of trials (n), the null hypothesized proportion (p), and we specify that the alternative hypothesis is “two.sided” - which is almost always the case

Now let’s look at the output:

binom.test.results
## 
##  Exact binomial test
## 
## data:  17 and 20
## number of successes = 17, number of trials = 20, p-value = 0.002577
## alternative hypothesis: true probability of success is not equal to 0.5
## 95 percent confidence interval:
##  0.6210732 0.9679291
## sample estimates:
## probability of success 
##                   0.85

The output from the binomial test includes the number of successes, the number of trials, and the calculated P-value. It also includes a 95% confidence interval for the proportion.

The confidence interval provided by this binom.test function is not recommended. Rather, you should ALWAYS use the Agresti-Coull method to calculate a confidence interval for a proportion, as shown in the previous tutorial.

Let’s now calculate the Agresti-Coull 95% confidence interval for the proportion, as we learned previously, using the binom.confint function from the binom package:

damsel.confint.results <- binom.confint(x = 17, n = 20, conf.level = 0.95, methods = "ac")

And look at the output:

kable(damsel.confint.results, digits = 4)
method x n mean lower upper
agresti-coull 17 20 0.85 0.6312 0.9561

Now we have all the ingredients for a proper concluding statement.

This is an example of an appropriate concluding statement for a binomial test:

Counter-clockwise battles occurred with significantly greater frequency than expected (17 of 20 battles; observed proportion of counter-clockwise battles = 0.85; Binomial test; P-value = 0.003; Agresti-Coull 95% confidence interval: 0.631 \(< {p} <\) 0.956).