And to check it worked I tried rep.b and think I typed the wrong code for Part B
ID: 3324225 • Letter: A
Question
And to check it worked I tried rep.b and think I typed the wrong code for Part B) because when I tried to approximate for Part C) I also got a weird number. What is the replicate properly for Part B) then approximate the result for Part C) in R Studio program. O 200% . iaucies. 11.3 (Birthday problem). Suppose you have a class of n students ano you're interested in the probability that at least two student share the same birthday. If one assumes that each birthday is equally likely from the set (1, 2, ., 365), then collecting birthdays can be viewed as a a. Write a function with argument n that samples n birthdays and computes b. Using the replicate function, repeat this simulation 1000 times for the c. From the output, approximate the probability that there is at least one sample of size n chosen with replacement from the set. the number of unique birthdays observed. special case of n = 30 students. matching birthday among the 30 birthdaysExplanation / Answer
> #function which sample n birthdays > replicate = function(n){ + bdays = sample.int(365, n, replace = TRUE) + uniqBdays = length(unique(bdays)) + return(uniqBdays) + } > > allUnique = 0 > #simulation that samples birthdays 1000 times > #stores 1 if all birthdays are found to be unique in list 'allUnique' > for (i in 1:1000){ + uniq_bdays = replicate(30) + if (uniq_bdays == 30){ + allUnique[i] = 1 + } + else{ + allUnique[i] = 0 + } + } > > #computation of probabilities > prob_no_similar_bday = length(allUnique[allUnique==1])/1000 > prob_atleast_one_similar = 1 - prob_no_similar_bday > prob_no_similar_bday [1] 0.278 > prob_atleast_one_similar [1] 0.722