Question: a) Write a for loop to call the flips() function 1000 times and store the 1000 resulting values in the vector called 'flips_vec'. Then, as

 a) Write a for loop to call the flips() function 1000

a) Write a for loop to call the flips() function 1000 times and store the 1000 resulting values in the vector called 'flips_vec'. Then, as you did in Assignment 1 , Problem 4 , count the frequencies of the number of flips in flips_vec and generate a bar plot of flips frequencies, with x-axis label "Number of coin flips" and y-axis label "Occurrences". Note: Do not add to or change the flips() function code. The for loop that you write merely needs to call the already existing flips() function 1000 times and store each return value from flips() in the flips_vec vector. What is the most frequent number of coin flips required to get 3 heads in a row? b) In R, the apply family of functions often makes it unnecessary to write loops. The replicate() function is a simplified version of sapply() that allows you to repeat an expression or function a set number of times. see ?replicate in the R console and this link. Repeat part a) using the replicate() function instead of the for loop. c) Based on the results of a) or b), what is your approximation of the probability of getting 3 heads in a row in just 3 coin tosses

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!