In the first exercise you wrote a function group_iq(n) to generate a group iq (the mean of n random people’s iq).

Let’s now take a closer look at our case, where we are interested in the probability distribution of these group iq scores for groups of \(5\) people (generated by group_iq(5)). An important probability distribution characteristic is the expected value or mean. We know that the mean iq for a person is 100, but what is the mean of the group iq values for groups of \(5\) people?

Pseudocode

The mean_group_iq(x) pseudocode1 (not all real R code) below returns the simulated mean group iq based on x simulated group iq’s:

# given function, normally you do NOT need to alter/copy/move this function
group_iq <- function(n){
    mean(rnorm(n, 100, 15))
}

# function to complete...
mean_group_iq <- function(x) {
    sum <- 0
    # TODO: correct the for-loop definition so that it runs x times
    for x times {
        # TODO: generate a group iq (group of 5 people) by calling the group_iq function with n equal to 5 (group_iq(5))

        # TODO: add the generated group id to the sum
    } 
    # TODO: calculate (and return) the mean group iq (divide sum by x)
}

Exercise

Pitfall

We have written the group_iq(n) function from exercise 1 for you. You can call this function like any other R function. So there is no need to alter/copy/move this function definition. Here you can find some examples to show you how these self written functions can be used

plus_one <- function(number) {
    number + 1
}

plus_one(22)
# 23

#using this function to define another function
plus_two <- function(number) {
    plus_one(plus_one(number))
}

plus_two(22)
# 24