Activity: simulation
Instructions:
- Work with a neighbor to answer the following questions
- To get started, download the class activity template file
- When you are finished, render the file as an HTML and submit the HTML to Canvas (let me know if you encounter any problems)
Probability simulation: the birthday problem
Suppose we have a class of 30 students. What is the probability that there is at least one shared birthday?
- Assume there are 365 days in a year
- Assume that each day is equally likely as a birthday
- Assume there are no multiple-birth siblings (e.g. twins, triplets, etc.) in the class
Create a vector to store the days of the year (numbered 1 to 365)
Use the
samplefunction to randomly choose birthdays for the class (think about whether we want to sample with or without replacement here…)Check the number of distinct birthdays (hints:
uniquereturns the unique elements of a vector;lengthreturns the length of a vector). Are there 30 distinct birthdays?Use a for loop to repeat the experiment
nsim=10000times, making sure to store the results. What is the probability of at least one shared birthday?How many students do we need for the probability to be approximately 50%?