Binomial Test

The statistical test used to determine whether the proportion in a binary outcome experiment is equal to a specific value. It is appropriate when we have a small sample size and want to test the success probability \(p\) against a hypothesized value \(p_0\).

Creating a sample dataset

  • We will generate a dataset where we record the outcomes of 1000 coin flips.

  • We will use the binom.test function to test if the proportion of heads is significantly different from 0.5.

set.seed(19)
coin_flips <- sample(c("H", "T"), 
                     size = 1000, 
                     replace = T,
                     prob = c(0.5, 0.5))

Now, we will count the heads and tails and summarize the data.

heads_count <- sum(coin_flips == "H")
tails_count <- sum(coin_flips == "T")
total_flips <- length(coin_flips)
heads_count
[1] 513
tails_count
[1] 487
total_flips
[1] 1000

Conducting Binomial Test

binom_test_result <- binom.test(heads_count, total_flips, p = 0.5)
binom_test_result

    Exact binomial test

data:  heads_count and total_flips
number of successes = 513, number of trials = 1000, p-value = 0.4292
alternative hypothesis: true probability of success is not equal to 0.5
95 percent confidence interval:
 0.4815213 0.5444020
sample estimates:
probability of success 
                 0.513 

Results:

The output has a p-value 0.4292098 \(> 0.05\) (chosen level of significance). Hence, we fail to reject the null hypothesis and conclude that the coin is fair.

Example of Clinical Trial Data

We load the lung dataset from survival package. We want to test if the proportion of patients with survival status 1 (dead) is significantly different from a hypothesized proportion (e.g. 50%)

We will calculate number of deaths and total number of patients.

library(survival)
attach(lung)

num_deaths <- sum(lung$status == 1)
total_pat <- nrow(lung)
num_deaths
[1] 63
total_pat
[1] 228

Conduct the Binomial Test

We will conduct the Binomial test and hypothesize that the proportin of death should be 19%.

binom_test <- binom.test(num_deaths, total_pat, p = 0.19)
binom_test

    Exact binomial test

data:  num_deaths and total_pat
number of successes = 63, number of trials = 228, p-value = 0.001683
alternative hypothesis: true probability of success is not equal to 0.19
95 percent confidence interval:
 0.2193322 0.3392187
sample estimates:
probability of success 
             0.2763158 

Results:

The output has a p-value 0.0016829 \(< 0.05\) (chosen level of significance). Hence, we reject the null hypothesis and conclude that the propotion of death is significantly different from 19%.