00:01
In this exercise, we simulate the coupon collector problem.
00:06
The scenario here is, cereal boxes come with one coupon each, and there are 10 unique coupons that may exist in each cereal box.
00:18
For each cereal box, each of the coupons is equally likely to be in it, but each box only comes with one coupon.
00:27
And so we are interested in the number of cereal boxes that we must purchase in order to collect all 10 coupons.
00:36
Now i've produced some code in r, which looks like this.
00:42
Now i've produced some code in r, which looks like this.
00:52
And the way the code works is i represent the 10 unique coupons with a vector of the numbers 1 through 10.
01:01
And then i start off each replication by sampling 10 from the number of coupons.
01:07
So that represents buying the first 10 boxes.
01:11
Because we know we need at least 10 boxes in order to collect all 10 coupons.
01:14
Coupons.
01:17
And then i check to see if there exists any coupon that is not in the boxes that we already have.
01:24
So that is this statement here.
01:29
It's the statement is true if any of the coupons does not exist in our collection of boxes.
01:37
So while this is true, we keep sampling one more cereal box or one more coupon and append that to our list of cereal boxes that we have or the list of coupons that we've accumulated from the cereal boxes.
01:58
And we simulate this 10 ,000 times.
02:01
So once this condition is not satisfied, that's when we break the wild boop.
02:07
And that means that we have all 10 coupons.
02:11
So we run the simulation 10 ,000 times.
02:14
And for each replication, we append the number of cereal boxes that we had to buy in order to collect all 10 coupons.
02:28
For part a, we are asked the probability of collecting all 10 coupons in the first 10 cereal boxes.
02:39
So if x is the random variable, that is the number of cereal boxes that we had to collect in order to collect all 10 coupons, we're looking for the probability that x is equal to 10, which will be approximately equal to, or hopefully approximately equal to our estimate for this probability based on our simulation...