The Binomial Distribution
Posted by Diego em Janeiro 15, 2015
In probability theory and statistics, the binomial distribution with parameters n and p is the discrete probability distribution of the number of successes in a sequence of n independent yes/no experiments, each of which yields success with probability p (source: wikipedia)
The dbinom function calculates the “probability of success” on a given experiment.
There are 3 main parameters, the number of successes for which you want to know the probability; the size (number of trials) and the probability of success on each trial.
So, for example, if we want to know the probability of success on the toss of a coin (let’s say “heads” mean success), we can do
dbinom(1, size = 1, prob = 1/2)
Clearly, the probability of “failure” (tails) is the same:
dbinom(0, size = 1, prob = 1/2)
If we want to know the probability of 2 heads on 2 tosses of a coin:
dbinom(2, size = 2, prob = 1/2)
The same way, one success can be calculated by
dbinom(1, size = 2, prob = 1/2)
Resulting 50%, which makes sense because when flipping a coin the possibilities are HH, HT, TH, TT and we can easily see that on 50% of the cases we have 1 success.
Second example, lets says you have a test to take with 5 multiple choice questions, each question has 5 alternatives.
What is the probability of getting exactly 3 questions right just answering them at random.
dbinom(3, size=5, prob=1/5)
Its 5% so you better study!
It’s easier to verify this formula if we think as 1 hit in 2 questions with 3 alternatives each. So let’s say that the correct answer is C than B, we can guess:
CB – we don’t want this because we want exactly 1 hit
4 out of 9 = 4/9 = 0.44
dbinom(1, size=2, prob=1/3)
Back to the questions, we can see the probability of getting 0 to 5 questions right
x = seq(0,5,by=1)
probx = dbinom(x, size=5, prob = 1/5)
[1,] 0 0.32768
[2,] 1 0.40960
[3,] 2 0.20480
[4,] 3 0.05120
[5,] 4 0.00640
[6,] 5 0.00032
plot(x, probx, type = ‘h’)