Now that you can define functions, use if statements and for-loops. It’s time to actually simulate the chance a random group of 5 people has an avarage iq greater than or equal to 110.

Pseudocode

The simulate_chance(n) pseudocode1 (not real R code) below returns the simulated chance that a group of 5 people are having a group iq (group_iq(5)) greater than or equal to 110 based on n generated groups:

group_iq <- function(n){
    mean(rnorm(n, 100, 15))
}

simulate_chance <- function(n) {
    counter <- 0
    # TODO: correct the for-loop definition so that it runs n times
    for n times {
        # TODO: generate a group iq for a group of 5 people (use group_iq function)

        # TODO: correct the if condition
        if the iq value is greater than or equal to 110 {
            # TODO: add one to the counter variable
        }
    }
    # TODO: calculate (and return) the frequency that the mean group iq is greater than or equal to 110
}

Exercise