You can apply the same concept to simulate the chance every groupsmember of random group of 5 people has an iq greater than or equal to 110.
The simulate_chance_2(n)
pseudocode1 (not real R code) below returns the simulated chance that a group of 5 people are ALL having an iq greater than or equal to 110 based on n
generated groups:
simulate_chance_2 <- function(n) {
counter <- 0
# TODO: correct the for-loop definition so that it runs n times
for n times {
# TODO: generate 5 normally distributed iq values with the rnorm() function (mean = 100, standard deviation = 15)
# TODO: correct the if condition
if ALL of these 5 iq values are greater than or equal to 110 {
# TODO: add one to the counter variable
}
}
# TODO: calculate (and return) the frequency that 5 normally distributed iq values are ALL greater than or equal to 110
}
Edit the code from previous exercise or start from the given pseudocode to write a function simulate_chance_2(n)
that simulates the chance ALL groupsmembers of a random group of 5 people have an IQ greater than or equal to 110 based on n
randomly generated groups.
Expected chance
We have calculated the chance, the exact chance is equal to \(0.001026225\)
Hint
- Note that in this case it’s simpler to write all of your code inside the
simulate_chance_2(n)
function definition instead of using a helper function like thegroup_iq(n)
function from previous exercises.- The
any
/all
function(s) will be useful.