Session Ready
Exercise

A simple embarrassingly parallel application

As a simple example of an embarrassingly parallel statistical application, we will repeatedly compute the mean of a set of normally distributed random numbers. For now, you will process it sequentially using a for loop, and the sapply() function.

In general, we recommend to implement any task that will be repeatedly applied to data as a function. Here, the function will be called mean_of_rnorm(). It generates random numbers with rnorm(), then computes their mean.

The objects n_numbers_per_replicate (set to 10000) and n_replicates (set to 50) have been created for you and determine the length of the random numbers vector and how many times the task is repeated, respectively.

Instructions 1/3
undefined XP
  • 1
  • 2
  • 3
  • Complete the definition of a function, mean_of_rnorm, to calculate normally distributed random numbers.
    • The function should take one argument: n .
    • Draw random numbers by calling rnorm(), passing it the mean_of_rnorm argument n and assigning the result to random_numbers.
    • Calculate the mean of the random numbers.
  • Try the function by calling it, setting n to 100.