Probability and Statistics: Exercises


2. Approximating the normal distribution. A draw from the normal distribution can be approximated by summing draws from uniform distributions and then subtracting the expected value. Using the function runif(n, min, max), draw 25 observations from a uniform distribution with a minimum of 0 and a maximum of 1. Repeat this three times and then subtract the expectation, which is 1.5. Plot a histogram of your draws using hist().


# Draw observations from uniform distribution three times. draws_1 <- runif(___, 0, ___) draws_2 <- ___(___, ___, 1) draws_3 <- ___ # Sum the draws and subtract the expectation. approx_normal_draws <- ___ # Plot histogram of observations. ___ # Draw observations from uniform distribution three times. draws_1 <- runif(25, 0, 1) draws_2 <- runif(25, 0, 1) draws_3 <- runif(25, 0, 1) # Sum the draws and subtract the expectation. approx_normal_draws <- draws_1 + draws_2 + draws_3 - 1.5 # Plot histogram of observations. hist(approx_normal_draws) test_error() test_function("runif", incorrect_msg="Did you use the `runif()` function?") test_function("hist", incorrect_msg="Did you use `hist()` to plot a histogram?") success_msg("Excellent work. Does your distribution appear to approximate a normal distribution well? Try increasing the number of draws.")
Did you set the parameters of the runif() correctly?

Previous Exercise Next Exercise