We've talked about the probability distributions for both discrete random variables and continuous random
variables.
Now we want to drill down a little further into a specific type of discrete random variable, which
is the binomial random variable.
So a binomial random variable for now, we'll just call it the discrete random variable x, but it's
a special type of discrete random variable that meets these four criteria.
We often indicate the binomial random variable like this with these parameters and and p, so we might
write X of NP or B of an P for binomial.
We'll see it this way as well.
But the binomial random variable is always modeling what we call the number of successes in some sequence
of NW independent experiments.
That's where that first criteria comes in independent trials.
So let's take the simplest example of flipping a coin.
When we flip a coin multiple times and we call each coin flip one trial, those are independent trials
because each coin flip is not affected by any of the other coin flips, whether we flip heads or tails
on one flip is totally independent of whether we flip heads or tails on another flip.
So we have independent trials.
We define the outcome of each trial as a success or a failure.
And these ideas here of success or failure don't really have anything to do with indicating some measurement
of good or bad.
By success, we just mean the outcome that we're investigating or the outcome we're looking for.
So if we're looking at the number of times that we flip heads, we would just define flipping heads
as a success and anything else as a failure.
In this case, the only other possible outcome is flipping tails.
So flipping tails would be a failure.
Flipping heads would be a success.
But if we're investigating the number of tails that we flip instead, then we would simply define flipping
tails as the success and everything else, in this case flipping heads as the failure.
So we define the outcome we want as success and everything else as a failure.
We have to be able to categorize outcomes in that way, which is partly why this can only be a discrete
random variable.
In order to model this situation with a binomial random variable, we also have to have a fixed number
of trials, so we can't use a binomial random variable to model a situation where we want to look at
probability.
When we flip a coin an infinite number of times we have to specify we're flipping the coin ten times
or we're flipping the coin 50 times.
The number of trials has to be fixed.
We have to predetermine how many times we're going to run this trial.
And that fixed number of trials is this number.
And here.
So this is a fixed number of trials.
RN And then the probability of that success that we defined earlier has to be constant.
So with the coin flip for every trial, for every time we flip the coin, the probability of success
is always one half or one over two or 50% or 0.5, and that stays constant because each coin flip is
independent.
The probability of success can't change from trial to trial.
If we want to model a situation with a binomial random variable, it has to stay constant and that probability
of success is this value.
P So when we see a binomial random variable expressed as B of NP or X of NP, these values indicate
the number of trials that were performing and then the probability of success on any particular trial.
Remember too, that total probability always sums to one or 100%, which means that if we define the
probability of success as P, then the probability of failure has to be one minus P, all of the other
probability other than this probability of success.
And so we often define failure as one minus P, and sometimes we write that as Q So Q is one minus P,
This is the probability of success.
P And the probability of failure one minus P, sometimes written as.
Q So these are the criteria that we have to meet in order to model our situation with a binomial random
variable.
Keep in mind that we don't just have to limit ourselves either to a situation where there are only two
outcomes, like with a coin flip, there's only two outcomes heads or tails.
We can have more than two outcomes.
So for instance, if we are rolling a six sided die and we want to define success as rolling a two,
we would just define success as rolling a two.
And then failure is rolling a one, three, four, five or six.
It's rolling anything other than a two.
Our probability of success would of course be one over six because the probability of rolling a two
is one over six, and so the probability of success would be one over six.
The probability of failure would be five over six.
So not only can we have more than two possible outcomes, like with a die roll, but that probability
of success doesn't have to be exactly one half.
With the coin flip, we have just two equally likely outcomes heads or tails.
And.
The probability that either of those show up is equivalent.
It's one half for heads and one half for tails, but we can have more than two outcomes, and the probabilities
of success and failure don't have to be equivalent.
So we could use a binomial random variable for a coin flip because each coin flip is independent of
all other coin flips.
We can define the outcome of each trial as a success or a failure.
If we're looking at how many times we flip heads, then we would define heads as a success and tails
as a failure.
We can define a fixed number of trials.
Let's say we're flipping a coin at 20 times and the probability of success remains constant because
the probability of flipping heads remains one half for every coin flip.
But we could also use this to model a die roll If, let's say we define success as rolling a two because
every die roll is independent, the role of the die won't be affected by any of the previous roles.
We can define our success specifically.
So let's say we want to roll a two.
Then we would define rolling a two as a success and rolling anything else as a failure.
So rolling a1a3 of four of five or a six would be a failure.
We can define a fixed number of trials.
So let's say we roll the dice ten times and the probability of success remains constant.
The probability of rolling a two always remains one over six.
That probability remains constant for every trial, for every die roll.
Contrast this with something that doesn't meet the criteria for a binomial random variable, like pulling
cards from a deck of cards without replacing the cards.
So if we're pulling cards from a standard 52 card deck and we're not replacing them, then right away
we know that our trials are independent because when we pull the first card, we start out with 52 cards
in the deck.
And so the probability of pulling any one card is going to be one over 52.
If we don't replace that card and we go to pull a second card, then the probability of pulling any
of the remaining cards from the remaining deck is going to be one over the 51 remaining cards.
So right away, the trials are not independent.
The probability of success is going to be changing.
We could not model that kind of scenario with a binomial random variable Now that we know when we can
use a binomial random variable, let's talk about the probability associated with this kind of variable.
What we're interested in here is given by this formula.
This is the probability of K successes in N attempts.
So remember we said that we had a fixed number of trials.
N What we want to be able to calculate is the probability that we come up with K number of successes
in N number of fixed trials.
So if we're rolling a die 20 times and we want to know the probability that we roll heads 13 times,
then we would calculate here the probability of K equals 13 in N equals 20.
And the way that we calculate that is with this binomial coefficient here.
We talked about this earlier when we looked at permutations and combinations.
So the formula, again as a reminder for this binomial coefficient is K successes in n attempts.
It's the combination and choose K and we calculate it as nn factorial divided by k, factorial times
the quantity and minus k factorial.
This is just a combination, so we have to calculate this value first.
Plug it into this formula here for the binomial coefficient and then we multiply that by p the probability
of success for our binomial random variable raised to the power.
This is the exponent here of K, the number of successes that we're looking for, and then we multiply
that by this one minus p which remember we looked at here is the probability of failure one minus P,
we also call it Q It's the probability of failure.
Where P is the probability of success.
So one minus P is that failure probability and we raise that to the power of N minus K, where n again
is the number of trials and K is the number of successes we're looking for.
So let's just say to take an example that we're running a rideshare company, we're looking at a particular
city where we operate our ridesharing company and we want to define success as one of our drivers arriving
within 10 minutes of the moment when the passenger has requested the ride.
We're interested in that figure because we don't want our passengers waiting longer than 10 minutes
from the moment when they request a ride through our app.
So we're going to define each trial as one ride.
We're going to define success as a driver arriving within 10 minutes and failure as it takes longer
than 10 minutes for the driver to arrive.
We're just going to look at five trials or five rides.
So we're going to randomly select five rides from our database and we're going to say that from the
data we already have about the rides we've been operating in this city, that the probability of success
for any particular.
Ride is 75%.
So in the past, 75% of passengers who request a ride have their driver arrive within 10 minutes of
the request.
So PE is going to be 0.75.
So in that circumstance we meet these conditions for a binomial random variable to model this situation
with a binomial random variable.
And now let's say we want to look at the probability of finding K successes in N attempts.
So we set n was going to be five.
We're going to choose five rides randomly from our database.
What's the probability that zero of those five have the driver arrive in 10 minutes or less?
What's the probability that one in five arrives in 10 minutes or less?
So in other words, this probability that we're going to be calculating allows us to understand, basically,
if we choose five rides at random, what's the probability that the driver will arrive within 10 minutes
for zero of those rides?
One of those rides, two of those rides all the way up to five of those rides.
So here's what some of those calculations would look like.
The probability that zero drivers arrive within 10 minutes if we pull a random sample of five rides
would be calculated this way.
We have this binomial coefficient and choose k or five choose zero.
We're selecting five rides and we want the probability that we have zero successes.
Zero drivers arrive within 10 minutes and then we take our probability of success.
P which we said was 0.75.
There's a 75% chance that a driver arrives within 10 minutes.
So we raise 0.75 to the power of zero because we're looking here for zero successes, K successes.
And then we take our probability of failure, which is just one minus P, So one -0.75 is 0.25 and we
raise that to the end minus K.
In this case, that's five -0 or five.
And we can use a calculator or software to calculate an approximate decimal value.
Here we've rounded all of our decimal values to six decimal places.
Then this second line here calculates the probability that of five rides.
Exactly.
One driver arrives within 10 minutes and we could continue calculating the probability that two of the
five arrive within 10 minutes.
Three of the five, four of the five all the way down to the last option, which is that of five rides,
all five drivers arrive within 10 minutes of the ride request.
So we could build out that table of probability.
We could get a value for each of those number of successes.
k012, three, four, five And then we can use this information to build out the probability distribution
for a binomial random variable.
Remember, since that binomial random variable is a discrete random variable, it's a special kind of
discrete random variable.
Our probability distribution will be a probability mass function that looks like this.
Here is the probability distribution for this specific scenario with the ride sharing company.
This should remind us of the general form of a probability distribution, a probability mass function
for a discrete random variable along the horizontal axis.
Here on the bottom, we place all of the discrete countable possible outcomes for our variable.
These are the numbers of our possible successes.
We can have zero successes, one success, two successes, all the way up to five out of five successes.
We see these values here coming from these values of k01, two, three, four, all the way up to five.
So we put those values along the horizontal axis and then along the vertical axis for our probability
mass function, for our special type of discrete random variable.
We plot the probability of each of these particular values along the horizontal axis.
So the probability that we got zero successes in five attempts was almost zero.
We found 0.000977.
That probability is so small that our little bar of probability doesn't even appear here.
The probability that we get one success in five attempts is just over 1%.
And so we see here if this is 10% and this is 5% along our graph, we see here our 1% value, about
a 1% chance that exactly one of our five drivers arrives in 10 minutes or less and we could continue
plotting all of these probability values all the way up to the probability that all five of the five
drivers arrive in 10 minutes or less.
That probability for all five drivers arriving for five successes is just under 24%.
And we see that value here.
So we have here 20%.
And then this line here representing 25% or 0.25, and we see our just less than 24% probability right
under that line there.
So this.
Then becomes the probability distribution for this specific binomial random variable.
The probability distribution will look different for every binomial random variable depending on the
values of N and P.
So in this scenario we chose N equals five, but if we chose instead, N equals 20 to run 20 trials
to look at 20 different rides that take place in our app, then instead of just the values zero through
five along the horizontal axis, we would have the values zero through 20.
And then the exact distribution here depends on the fact that our historical data told us that we had
a 75% chance of success, but maybe in a different city.
Our chance of success or chance that a driver arrives within 10 minutes is 60% or 90% or only 20%.
Whatever value we have for that chance of success, of course, that is going to affect the shape of
our distribution.
So this distribution is unique to n equals five trials with a P equals 0.75 chance of success.
But that is how we build the probability distribution.
And of course, once we build it, it should roughly make sense to us.
If we run five trials or five experiments and our expected probability of success is 75%, well, what's
75% of five?
It's 3.75.
And so roughly, we would expect that most of our mass here, in our probability, mass function in
this distribution would be clustered around the 3.75 mark.
And we see that that's roughly true.
Most of the weight of our distribution is clustered around these three, four or five values.
More specifically, even the four value, which of course is the value closest to 3.75.
So very roughly with some general intuition, this distribution looks like it could model our scenario
where we have five trials and a 75% chance of success.
That being said, let's get a little bit more specific and look at the properties of A binomial random
variable B of P, And let's say here that yes, in fact the calculation we just did is the calculation
that we use for the mean of a binomial random variable.
So once we know that we have a binomial random variable, it meets these conditions, we're going to
use a binomial random variable to model our scenario.
Then we unlock all of these formulas that apply to the binomial random variable or the binomial distribution.
Here the mean is always going to be end times p.
In our case, five times 0.75 or 3.75.
So our mean our expected value is 3.75.
So if we randomly select five rides, then we expect roughly 3.75 of them.
In terms of sort of this long term average, we expect 3.75 of those five rides to have the driver arrive
within 10 minutes.
Of course, this is a discrete random variable.
So out of five rides we'll never actually see exactly 3.75 rides meet.
That criteria will always see either three or four or five or two or one or zero.
We'll never see exactly 3.75, but that gives us a long term average.
It gives us our expected value or our mean.
So we can always find that as n times p in this case five times 0.75.
And then the variance here is given by NP times one minus P.
Remember sometimes two, we express this one minus P probability of failure value as Q.
So we also see this written sometimes as NP.
Q In our case, that's five times 0.7, five times 0.25 or 0.9375.
That's going to be the variance of this binomial distribution for the binomial random variable.
And then standard deviation is always just the square root of variance.
So for standard deviation, we would take the square root of 0.9375, and that's approximately equal
to if we round 0.9682.
And so now we have our mean variance in standard deviation for the binomial distribution.
So to summarize, let's just say that we always have to start with these four conditions.
We have to meet these four conditions in order for a binomial random variable to even be on the table.
We can't model a situation as a binomial random variable unless we're meeting these four criteria.
So we always have to go through and verify that each of these four criteria is holding.
If we're meeting all of these criteria, then we can use a binomial random variable which then unlocks
for us all of these probability calculations.
We can specifically find the probability of K successes in N trials using this formula here.
Here where this is the binomial coefficient that we calculate this way.
We learned about this when we talked about permutations and combinations, so we can calculate the probability
for every possible value of K, and K is always going to take on values between zero and N.
So if n is our number of trials, K is always going to be given by the set of integers between zero
and N, so k can be equal to zero and then it can be one, two, three, four, five, six, etc. all
the way up to whatever our value of DN is.
So we can calculate probability for all of those different values of K, and then we can use those probability
values to build the binomial distribution.
This visual representation of the probability associated with our binomial random variable.
And then regardless of whether or not we've already calculated all of this probability or built this
binomial distribution, even if we don't have either of those things, all we need to find the mean
variance in standard deviation of this distribution are the values of GN and P, which we have from
our criteria that we unpacked at the beginning.
We know our fixed number of trials.
NW and we know the probability of success.
P And those are the only two values we need to find mean variance in standard deviation so we can go
directly to calculating these values even before we've calculated all of this probability and used it
to build this binomial distribution.