<jupyter_start><jupyter_text>Confidence Interval - Difference In MeansHere you will look through the example from the last video, but you will also go a couple of steps further into what might actually be going on with this data.<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

%matplotlib inline
np.random.seed(42)

full_data = pd.read_csv('coffee_dataset.csv')
sample_data = full_data.sample(200)
sample_data.head()<jupyter_output><empty_output><jupyter_text>`1.` For 10,000 iterations, bootstrap sample your sample data, compute the difference in the average heights for coffee and non-coffee drinkers.  Build a 99% confidence interval using your sampling distribution.  Use your interval to start answering the first quiz question below.<jupyter_code>diff = []
for _ in range(10000):
    boot_samp = sample_data.sample(200, replace = True)
    coff_mean = boot_samp[boot_samp['drinks_coffee'] == True]['height'].mean()
    not_coffee_mean = boot_samp[boot_samp['drinks_coffee'] == False]['height'].mean()
    diff.append(coff_mean - not_coffee_mean)
np.percentile(diff, 0.5), np.percentile(diff, 99.5)<jupyter_output><empty_output><jupyter_text>`2.` For 10,000 iterations, bootstrap sample your sample data, compute the difference in the average heights for those older than 21 and those younger than 21.  Build a 99% confidence interval using your sampling distribution.  Use your interval to finish answering the first quiz question below.<jupyter_code>diff_age = []
for _ in range(10000):
    boot_samp = sample_data.sample(200, replace = True)
    under_21 = boot_samp[boot_samp['age'] == '<21']['height'].mean()
    over_21 = boot_samp[boot_samp['age'] != '<21']['height'].mean()
    diff_age.append(over_21 - under_21)
np.percentile(diff_age, 0.5), np.percentile(diff_age, 99.5)<jupyter_output><empty_output><jupyter_text>`3.` For 10,000 iterations bootstrap your sample data, compute the **difference** in the average height for coffee drinkers and the average height for non-coffee drinkers for individuals **under** 21 years old.  Using your sampling distribution, build a 95% confidence interval.  Use your interval to start answering question 2 below.<jupyter_code>diff_coffee_under_21 = []
for _ in range(10000):
    boot_samp = sample_data.sample(200, replace = True)
    under_21_coffee = boot_samp.query("age == '<21' and drinks_coffee == True")['height'].mean()
    under_21_no_coffee = boot_samp.query("age == '<21' and drinks_coffee == False")['height'].mean()
    diff_coffee_under_21.append(under_21_no_coffee - under_21_coffee)
np.percentile(diff_coffee_under_21, 2.5), np.percentile(diff_coffee_under_21, 97.5)<jupyter_output><empty_output><jupyter_text>`4.` For 10,000 iterations bootstrap your sample data, compute the **difference** in the average height for coffee drinkers and the average height for non-coffee drinkers for individuals **over** 21 years old.  Using your sampling distribution, build a 95% confidence interval. Use your interval to finish answering the second quiz question below. As well as the following questions.<jupyter_code>diff_coffee_over_21 = []
for _ in range(10000):
    boot_samp = sample_data.sample(200, replace = True)
    over_21_coffee = boot_samp.query("age != '<21' and drinks_coffee == True")['height'].mean()
    over_21_no_coffee = boot_samp.query("age != '<21' and drinks_coffee == False")['height'].mean()
    diff_coffee_over_21.append(over_21_no_coffee - over_21_coffee)
np.percentile(diff_coffee_over_21, 2.5), np.percentile(diff_coffee_over_21, 97.5)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10662583518930957, 'fraction_numerical': 0.04175946547884187, 'mean_word_length': 5.9096153846153845, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 21, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '92756', 'license': 'Apache-2.0', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1120, 'n_words': 331, 'path': 'Practical_statistics/Confidence_intervals/Sampling Distributions - Difference in Means.ipynb', 'repo_name': 'sudoberlin/Data_Analyst_ND', 'size': '3592'}