Aan de slagGa gratis aan de slag

Bootstrap replicates of other statistics

We saw in a previous exercise that the mean is Normally distributed. This does not necessarily hold for other statistics, but no worry: as hackers, we can always take bootstrap replicates! In this exercise, you'll generate bootstrap replicates for the variance of the annual rainfall at the Sheffield Weather Station and plot the histogram of the replicates.

Here, you will make use of the draw_bs_reps() function you defined a few exercises ago. It is provided below for your reference:

def draw_bs_reps(data, func, size=1):
    """Draw bootstrap replicates."""
    # Initialize array of replicates
    bs_replicates = np.empty(size)
    # Generate replicates
    for i in range(size):
        bs_replicates[i] = bootstrap_replicate_1d(data, func)
    return bs_replicates

Deze oefening maakt deel uit van de cursus

Statistical Thinking in Python (Part 2)

Cursus bekijken

Oefeninstructies

  • Draw 10000 bootstrap replicates of the variance in annual rainfall, stored in the rainfall dataset, using your draw_bs_reps() function. Hint: Pass in np.var for computing the variance.
  • Divide your variance replicates (bs_replicates) by 100 to put the variance in units of square centimeters for convenience.
  • Make a histogram of bs_replicates using the normed=True keyword argument and 50 bins.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Generate 10,000 bootstrap replicates of the variance: bs_replicates
bs_replicates = ____

# Put the variance in units of square centimeters
____

# Make a histogram of the results
_ = plt.hist(____, ____, ____)
_ = plt.xlabel('variance of annual rainfall (sq. cm)')
_ = plt.ylabel('PDF')

# Show the plot
plt.show()
Code bewerken en uitvoeren