Question

In: Statistics and Probability

The birthday problem considers the probability that two people in a group of a given size...

The birthday problem considers the probability that two people in a group of a given size have the same birth date. We will assume a 365 day year (no leap year birthdays).

Code set-up

Dobrow 2.28 provides useful R code for simulating the birthday problem. Imagine we want to obtain an empirical estimate of the probability that two people in a class of a given size will have the same birth date. The code

trial = sample(1:365, numstudents, replace=TRUE)

simulates birthdays from a group of numstudents students. So you can assign numstudents or just replace numstudents with the number of students in the class of interest.

If we store the list of birthdays in the variable trial, the code

2 %in% table(trial)

will create a frequency table of birthdays and then determine if there is a match (2 birthdays the same). We can use this code in an if-else statement to record whether a class has at least one pair of students with the same birth date. We then can embed the code within a for-loop to repeat the experiment, store successes in a vector, and then take the average number of successes (a birthday match) across the repeated tasks.

The problems

  • Simulate the birthday problem to obtain an empirical estimate of the probability that two people in a class of 23 will have the same birth date. In particular, simulate birthdays for 1000 classes (for(i in 1:1000){...}) each of size 23 and compute the proportion of these classes in which at least one pair of students has the same birth date.

Recall that the true probability is 1-prod(seq(343,365))/(365)^23 which is approximately 50%.

  • Using your simulation code, estimate the number of students needed in the class so that the probability of a match is 95%. (You may do this by trial and error.)
  • Using your simulation code, find the approximate probability that three people have the same birthday in a class of 50 students.

# [Place code here]

Place your answers to the three items below here:

  • [Ans 1]

    The birthday problem considers the probability that two people in a group of a given size have the same birth date. We will assume a 365 day year (no leap year birthdays).

    Code set-up

    Dobrow 2.28 provides useful R code for simulating the birthday problem. Imagine we want to obtain an empirical estimate of the probability that two people in a class of a given size will have the same birth date. The code

    trial = sample(1:365, numstudents, replace=TRUE)

    simulates birthdays from a group of numstudents students. So you can assign numstudents or just replace numstudents with the number of students in the class of interest.

    If we store the list of birthdays in the variable trial, the code

    2 %in% table(trial)

    will create a frequency table of birthdays and then determine if there is a match (2 birthdays the same). We can use this code in an if-else statement to record whether a class has at least one pair of students with the same birth date. We then can embed the code within a for-loop to repeat the experiment, store successes in a vector, and then take the average number of successes (a birthday match) across the repeated tasks.

    The problems

  • Simulate the birthday problem to obtain an empirical estimate of the probability that two people in a class of 23 will have the same birth date. In particular, simulate birthdays for 1000 classes (for(i in 1:1000){...}) each of size 23 and compute the proportion of these classes in which at least one pair of students has the same birth date.
  • Recall that the true probability is 1-prod(seq(343,365))/(365)^23 which is approximately 50%.

  • Using your simulation code, estimate the number of students needed in the class so that the probability of a match is 95%. (You may do this by trial and error.)
  • Using your simulation code, find the approximate probability that three people have the same birthday in a class of 50 students.
  • # [Place code here]

    Place your answers to the three items below here:

  • [Ans 1]

Solutions

Expert Solution

1)

For each class of 23 students, we can simulate their birthdays in a 365 day year using the code

trial = sample(1:365, 23, replace=TRUE)

Then use

table(trial)

to find the frequencies of each date. We need to check if any of these frequencies are greater than 1. We do that with,

max(table(trial)) > 1

This will give a TRUE or FALSE answer which we can store in an array. Now for the simulation, we put everything a for-loop and store the result in an array called success.

numstudents = 23
success = c()
for (i in 1:1000) {
trial = sample(1:365, numstudents, replace=TRUE)

success[i]<- (max(table(trial))>1)
}

Then count the proportion of TRUE in the array success using

sum(success)/1000

Running that code with seed set to 123 gives the answer 0.515, which is very close to 50%.

2)

Now, to find the number of students required in a class, we run the code for different values of the variable 'numstudents' and record the results.

For

numstudents = 30
success = c()
for (i in 1:1000) {
trial = sample(1:365, numstudents, replace=TRUE)

success[i]<- (max(table(trial))>1)
}

sum(success)/1000

gives 0.693 so we need to go higher. Let's try 40.

numstudents = 40
success = c()
for (i in 1:1000) {
trial = sample(1:365, numstudents, replace=TRUE)

success[i]<- (max(table(trial))>1)
}

sum(success)/1000

And we get 0.898. So higher still.

At numstudents = 50 we get 0.97. So we need to go lower.

At numstudents = 45 we get 0.938. So a little higher.

At numstudents = 47 we get 0.954. So let's check 46.

At numstudents = 46 we get 0.943.

Thus, 47 is the smallest class size that gives the estimated probability as greater than 95%.

Note that this code is only reproducible with the right seed and you will get slightly different values otherwise.

3)

For a class size of 50 we find the trial array again, and then in table(trial) we must check if any value is at least 3 or greater than 2. So the code is:

numstudents = 50
success = c()
for (i in 1:1000) {
trial = sample(1:365, numstudents, replace=TRUE)

success[i]<- (max(table(trial))>2)
}

sum(success)/1000

And I got the output 0.128.

Code:

set.seed(123)


numstudents = 23
success = c()
for (i in 1:1000) {
trial = sample(1:365, numstudents, replace=TRUE)

success[i]<- (max(table(trial))>1)
}

sum(success)/1000


numstudents = 30
success = c()
for (i in 1:1000) {
trial = sample(1:365, numstudents, replace=TRUE)

success[i]<- (max(table(trial))>1)
}

sum(success)/1000


numstudents = 40
success = c()
for (i in 1:1000) {
trial = sample(1:365, numstudents, replace=TRUE)

success[i]<- (max(table(trial))>1)
}

sum(success)/1000


numstudents = 50
success = c()
for (i in 1:1000) {
trial = sample(1:365, numstudents, replace=TRUE)

success[i]<- (max(table(trial))>1)
}

sum(success)/1000

numstudents = 45
success = c()
for (i in 1:1000) {
trial = sample(1:365, numstudents, replace=TRUE)

success[i]<- (max(table(trial))>1)
}

sum(success)/1000

numstudents = 47
success = c()
for (i in 1:1000) {
trial = sample(1:365, numstudents, replace=TRUE)

success[i]<- (max(table(trial))>1)
}

sum(success)/1000

numstudents = 46
success = c()
for (i in 1:1000) {
trial = sample(1:365, numstudents, replace=TRUE)

success[i]<- (max(table(trial))>1)
}

sum(success)/1000

numstudents = 50
success = c()
for (i in 1:1000) {
trial = sample(1:365, numstudents, replace=TRUE)

success[i]<- (max(table(trial))>2)
}

sum(success)/1000

0.515

47

0.128


Related Solutions

Given a group of four people, find the probability that: (a) at least two have the...
Given a group of four people, find the probability that: (a) at least two have the same birth month (b) at least two have the same birthday Assume each day or month is equally likely. Ignore leap years. [Hint: First calculate the probability that they all have different birthdays. Similar to Q5 but with either 12 or 365 hotels.] Answer to a) should be 0.427 Answer to b) should be 0.00164
1. Birthday Problem. In a group of 10 students, what is the probability that a. Nobody...
1. Birthday Problem. In a group of 10 students, what is the probability that a. Nobody has birthday on the same date b. At least two have same birthday c. Exactly two have same birthday d. Exactly three have same birthday e. Two or three have same birthday f. At most three have same birthday
What's the probability that in a room of k people, exactly two share the same birthday?...
What's the probability that in a room of k people, exactly two share the same birthday? Assume 365 days (no leap year).
Two women in a group of 25 people shared the same name and the same birthday....
Two women in a group of 25 people shared the same name and the same birthday. Discuss whether this is a surprising result. Do you think it is more likely that you will find a pair of people in a room of 25 who share a first name or a pair of people who share a birthdate?
What is the probability that in a group of three people at least two will have...
What is the probability that in a group of three people at least two will have the same birth month? (Assume that all sequences of three birth months are equally likely.) (b) What is the probability that in a group of n people, n ≤ 12 , at least two will have the same birth month? (c) What is the probability that in a group of n people, n > 12 , at least two will have the same birth...
Determine the probability that in a group of 5 people, at least two share the same...
Determine the probability that in a group of 5 people, at least two share the same birth month. Assume that all 12 months are equally likely to be someone’s birth month. a) How many choices are there for the birth months of these 5 people (without any restrictions)? b) How many choices are there for the 5 people to have all different birth months? c) Report the probability that in a group of 5 people, at least two share the...
BACKGROUND: Given a group of 'n' people, the odds that at least two people have the...
BACKGROUND: Given a group of 'n' people, the odds that at least two people have the same birthday are much higher than you would think. PLEASE WRITE CODE IN C++ The program takes no input. Assumptions: 1. There is an equal chance of birthday landing on any day of the year. 2. We are not considering a leap year (only 365 days) The simulation will be run in the following manner: 1. For a group size 2, assign a random...
Prove "The Birthday Problem" in this regard, Suppose there are some number of people in a...
Prove "The Birthday Problem" in this regard, Suppose there are some number of people in a room and we need need to consider all possible pairwise combinations of those people to compare their birthdays and look for matches.Prove the probability of the matches.
In a finite cyclic group, each subgroup has size dividing the size of the group. Conversely, given a positive divisor of the size of the group, there is a subgroup of that size
Prove that in a finite cyclic group, each subgroup has size dividing the size of the group. Conversely, given a positive divisor of the size of the group, there is a subgroup of that size.
Birthday problem. Suppose that people enter a room one at a time. How people must enter...
Birthday problem. Suppose that people enter a room one at a time. How people must enter until two share a birthday? Counterintuitively, after 23 people enter the room, there is approximately a 50–50 chance that two share a birthday. This phenomenon is known as the birthday problem or birthday paradox. Write a program Birthday.java that takes two integer command-line arguments n and trials and performs the following experiment, trials times: Choose a birthday for the next person, uniformly at random...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT