Blog of Andrés Aravena
CMB2:

# Homework 7

25 May 2021. Deadline: Monday, 31 May, 9:00.

# Montecarlo method

This week we will do a little practice of creating complex random systems by combining simpler cases. These programs may take several minutes to finish, so be patient. You may want to run them in the console first and, once they give you a good result, copy the code to a Rmarkdown document for your answer.

## 1. You throw two dice.

Let’s assume that we have two normal dice with six sides. Please write a function to simulate the experiment “throwing two dice and counting the total number of spots in the upper face”.

1. Replicate the simulation at least 1000 times. Use the result to estimate the probability that the sum of both dice is 7.
2. Using the same code (or the same results of the simulation), estimate the probability that the sum of both dice is more than or equal to 10.
3. (optional) Can you give a confidence interval for these estimation of probabilities?
4. What are the probabilities (and confidence intervals) if you throw three dice?

## 2. Three plants

To test a new fertilizer, three plants were planted in a new environment. After one month, one died and the others survived. We want to know what is the range of survival probability that is compatible with this outcome

1. Write a function that takes one input 𝑝, corresponding to the survival probability of a single plant, simulates the survival of three plants, and returns the relative frequency of cases where only two plants survived. These relative frequencies must count positive cases over a total cases, with at least 1000 cases.
2. Use the previous function to test what happens if 𝑝 is 0.1, 0.15, 0.2, …, 0.9, 0.95. Make a plot of “probability of two plants” versus 𝑝.

Something to pay attention here: there are two probabilities in this question. One is 𝑝, the probability of survival for each plant (you can model it with a coin). The other probability is for “two of three plants survived”, a value that you should estimate based on these simulations.

You can simulate each plant independently, or use the R function for “toss 𝑛 coins and count the number of heads”.