Blog of Andrés Aravena
CMB2:

Homework 9

07 June 2021. Deadline: Friday, 11 June, 9:00.

Please use this template for your answers.

Wedding Planner

You got a new job as “Wedding Planner”. Your clients want to organize a big party, but they are not sure how many people will attend. Talking to your clients, you find that they have:

Each one of the good friends will attend with probability 90%. The regular friends will attend with probability 50%. The acquittances will attend with probability 20%.

1. Simulate one party

The function party receives the number of good, regular and bad friends, and returns the total number of people attending to the simulated party.

party <- function(n_good, n_regular, n_bad) {
# write your code here 
}

If all is right, you should get something like this:

party(10, 50, 40)
[1] 48

2. Simulate ten thousand parties

Store the result in a vector called parties, and make a bar plot

# write your code here
barplot(table(parties))

plot of chunk unnamed-chunk-4

3. Mean value and standard deviation

Find the average and the standard deviation of the number of people attending the party

# write your code here
[1] 42.0306

[1] 4.415225

4. Find an interval containing 95% of all parties

This will allow you to have a reasonable idea of what will happen in real life.

You should get something like this

[1] 33.20015 50.86105
# write your code here

5. Find population mean using a small sample

In a previous question we found the mean value of parties, assuming that we know all of them.

Now we will assume that the vector parties is a population, and we have only access to a small sample of 3 cases.

sample_of_3 <- sample(parties, size=3)

Please find an interval containing the population mean with 95% confidence

[1] 33.74417 48.92250

Attention: this question is different from the previous one. Here we ask for an interval for the population mean, not for the individual cases.

6. Find population mean using a larger sample

Repeat the same procedure as before, assuming that you have a sample of 20 cases.

sample_of_20 <- sample(parties, size=20)

Please find an interval containing the population mean with 95% confidence

[1] 39.13881 43.52786

Deadline: Friday, 11 June, 9:00.

Originally published at https://anaraven.bitbucket.io/blog/2021/cmb2/homework-9.html