Samples from a rolled die
Let's work through generating a simulation using the numpy
package. You'll work with the same scenario from the slides, simulating rolls from a standard die numbered 1 through 6, using the randint()
function. Take a look at the documentation for this function if you haven't encountered it before.
Starting with a small sample and working your way up to a larger sample, examine the outcome means and come to a conclusion about the underlying theorem.
This exercise is part of the course
Practicing Statistics Interview Questions in Python
Exercise instructions
- Generate a sample of 10 die rolls using the
randint()
function; assign it to oursmall
variable. - Assign the mean of the sample to
small_mean
and print the results; notice how close it is to the true mean. - Similarly, create a larger sample of 1000 die rolls and assign the list to our
large
variable. - Assign the mean of the larger sample to
large_mean
and print the mean; which theorem is at work here?
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
from numpy.random import randint
# Create a sample of 10 die rolls
small = randint(____, ____, ____)
# Calculate and print the mean of the sample
small_mean = ____
print(____)
# Create a sample of 1000 die rolls
large = randint(____, ____, ____)
# Calculate and print the mean of the large sample
large_mean = ____
print(____)