<jupyter_start><jupyter_text>Example of plotting the distribution of estimates empirically Import the necessary modules:<jupyter_code>import numpy as np
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Define the number of samples and empty lists where we collect the results.<jupyter_code>mean_estimates_1 = []
mean_estimates_2 = []
numSamples = 100<jupyter_output><empty_output><jupyter_text>Iterate 1000 times and apply the two estimators each time.<jupyter_code>for iteration in range(1000):
    
    # Create a random sample of data from N(0,1)
    x = np.random.randn(numSamples)
    
    # Compute the estimate of the mean using 
    # the sample mean
    aHat_1 = x.mean() # or np.mean(x)
    
    # Compute the "first sample estimator"
    aHat_2 = x[0]
    
    # Append the computed values to our lists:
    mean_estimates_1.append(aHat_1)
    mean_estimates_2.append(aHat_2)<jupyter_output><empty_output><jupyter_text>Plot the empirical distributions. `plt.subplot` gives a collection of subplots in a list. We also set `sharex = True`, such that the two plots will have same x axis scale.<jupyter_code>fig, axes = plt.subplots(2, 1, sharex=True)

axes[0].hist(mean_estimates_1, normed = True)
axes[1].hist(mean_estimates_2, normed = True)

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08794541319181198, 'fraction_numerical': 0.02122820318423048, 'mean_word_length': 4.9192825112107625, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '278056', 'license': 'MIT', 'n_tokens_mistral': 480, 'n_tokens_neox': 443, 'n_words': 125, 'path': 'code/Two_Estimators.ipynb', 'repo_name': 'mahehu/SGN-41007', 'size': '1319'}