R Binomial Test


binom.test() function performs binomial test of null hypothesis about binomial distribution.

binom.test(x,n,p=0.5,alternative=c("two.sided","less","greater"),
conf.level=0.95)


x: number of successes
n: number of trials
p: hypothesized probability of success
alternative: alternative hypothesis, including "two.sided","greater","less"
conf.level: confidence level

Suppose in a coin tossing, the chance to get a head or tail is 50%. In a real case, we have 100 coin tossings, and get 48 heads, is our original hypothesis true?


> binom.test(48,100)

Exact binomial test
data: 48 and 100
number of successes = 48, number of trials = 100, p-value = 0.7644
alternative hypothesis: true probability of success is not equal to 0.5
95 percent confidence interval:
0.3790055 0.5822102
sample estimates:
probability of success
0.48


Since the p-value is 0.7644, far greater than 0.05, the hypothesis is accepted.



Let's see another example. Hemophilia A is a genetic disease. If the mother has hemophilia, the possiblity of his male child has hemophilia is 50%. Suppose the mother has hemophilia only, what is the probability for one boy out of two to be hemophilia?

> dbinom(1, 2, 0.5)
[1] 0.5

what is the probability for two boys to be all hemophilia?

> dbinom(2, 2, 0.5)
[1] 0.25
> dbinom(0, 2, 0.5)  #no hemophilia to all two?
[1] 0.25


endmemo.com © 2024  | Terms of Use | Privacy | Home