In: Math
This is an extension of the Birthday Problem. Suppose you have 500 Facebook friends. Make the same assumptions here as in the Birthday Problem.
a) Write a program in R to estimate the probability that, on at least 1 day during the year, Facebooks tells you three (or more) of your friends shat that birthday. Based on your answer, should you be surprised by this occurrence?
b) Write a program in R to estimate the probability that, on at least 1 day during the year, Facebook tells you five (or more) of your friends share that birthday. Based on your answer, should you be surprised by the occurrence? [Hint: Generate 500 birthdays with replacement, then determine whether any birthday occurs three or more times (five or more for part (b)). The table function in R may prove useful.]
It is given in the hint that for both the part of two questions first we have to generate 500 birthdays.Then we have to see the frequency table that how many birthdays occur 3 or more times(for part a) and how many are 5 or more(for part b).
The solution can be done in three consecutive steps for both part 'a' and 'b' problem. Firstly, In the R code we first use the in build function "sample()" in R-script for SRSWR (simple random sampling with replacement) of 500 distinct birthdays from 365 days. Then we use the "table()" in r two find the required frequency number and "which()" to find the required number of counts. Finally, we calculate the probability estimate empirically (favourable no. of counts/ 365) to evaluate the required answer. The R code is given below....
R Code:
#Generate 500 birthdays with replacement from 1:365 days(in a
year) with replacement
y=sample(1:365, 500, replace = TRUE, prob = NULL)
#consider the frequency counts of the sample
z=as.numeric(table(y))
# Calculate the estimate of probability(count/Total number=365)
100*length(which(z>=3))/365 # part a probability estimate
(17% approx in my sample)
100*length(which(z>=5))/365 # part b probability estimate (0.55
% approx in my sample)