Binomial Test using R

 

Use the mpg data file with a new variable drv_front. The new drv_front variable is defined as 1 if drv = ‘f’ or 0 if not equal ‘f’.

> mpg$drv_front <- NA
> mpg[which(mpg$drv == 'f'), ]$drv_front <- 1
> mpg[which(mpg$drv != 'f'), ]$drv_front <- 0
> binom.test(sum(mpg$drv_front), length(mpg$drv_front), p = 0.5)
Exact binomial test

data: sum(mpg$drv_front) and length(mpg$drv_front)
number of successes = 106, number of trials = 234, p-value = 0.1697
alternative hypothesis: true probability of success is not equal to 0.5
95 percent confidence interval:
 0.3880315 0.5191574
sample estimates:
probability of success 
 0.4529915

Also, you can use a more general function called prop.test, which will give you a similar result.

 

 

See Also:

Do the same test in SAS

Leave a Reply

Your email address will not be published. Required fields are marked *