<jupyter_start><jupyter_text>HYPOTHESIS TESTING WITH SCIPYFamiliar: A Study In Data AnalysisWelcome to Familiar, a startup in the new market of blood transfusion! You’ve joined the team because you appreciate the flexible hours and extremely intelligent team, but the overeager doorman welcoming you into the office is a nice way to start your workday (well, work-evening).Familiar has fallen into some tough times lately, so you’re hoping to help them make some insights about their product and help move the needle (so to speak).<jupyter_code>import familiar
from scipy.stats import ttest_1samp
from scipy.stats import ttest_ind
from scipy.stats import chi2_contingency<jupyter_output><empty_output><jupyter_text>now the first thing we want to show is that our most basic package, the Vein Pack, actually has a significant impact on the subscribers. It would be a marketing goldmine if we can show that subscribers to the Vein Pack live longer than other people.Lifespans of Vein Pack users are returned by the function lifespans(package='vein'), which is part of the familiar module. Call that function and save the data into a variable called vein_pack_lifespans.<jupyter_code>vein_pack_lifespans = familiar.lifespans(package='vein')<jupyter_output><empty_output><jupyter_text>We’d like to find out if the average lifespan of a Vein Pack subscriber is significantly different from the average life expectancy of 71 years.<jupyter_code>vein_pack_test = ttest_1samp(vein_pack_lifespans, 71)
print(vein_pack_test.pvalue)<jupyter_output>2.7463117986584107e-10<jupyter_text>Let’s check if the results are significant! Check the pvalue of vein_pack_test. If it’s less than 0.05, we’ve got significance! Let’s print some information out! If the test’s p-value is less than 0.05, print “The Vein Pack Is Proven To Make You Live Longer!”. Otherwise print “The Vein Pack Is Probably Good For You Somehow!”<jupyter_code>if vein_pack_test.pvalue < 0.05:
  print('The Vein Pack Is Proven To Make You Live Longer!')
else:
  print('The Vein Pack Is Probably Good For You Somehow!')<jupyter_output>The Vein Pack Is Proven To Make You Live Longer!<jupyter_text>Upselling Familiar: Pumping Life Into The Company In order to differentiate Familiar’s different product lines, we’d like to compare this lifespan data between our different packages. Our next step up from the Vein Pack is the Artery Pack. Let’s get the lifespans of Artery Pack subscribers using the same method, called with package='artery' instead. Save the value into a variable called artery_pack_lifespans.<jupyter_code>artery_pack_lifespans = familiar.lifespans(package='artery')<jupyter_output><empty_output><jupyter_text>Now we want to show that the subscribers to the Artery Pack experience a significant improvement even beyond what a Vein Pack subscriber’s benefits. Import the 2-Sample T-Test and we’ll use that to see if there is a significant difference between the two subscriptions.<jupyter_code>package_comparison_results=ttest_ind(vein_pack_lifespans,artery_pack_lifespans)

print(package_comparison_results.pvalue)<jupyter_output>0.05588883079070819<jupyter_text>Let’s see the results! If the p-value from our experiment is less than 0.05, the results are significant and we should print out “the Artery Package guarantees even stronger results!”. Otherwise we should print out “the Artery Package is also a great product!”<jupyter_code>if package_comparison_results.pvalue < 0.05:
  print('the Artery Package guarantees even stronger results!')
else:
  print('the Artery Package is also a great product!')<jupyter_output>the Artery Package is also a great product!<jupyter_text>Well, shame that it’s not significantly better, but maybe there’s a way to demonstrate the benefits of the Artery Package yet. Benefitting Everyone: A Familiar Problem If your lifespan isn’t significantly increased by signing up for the Artery Package, maybe we can make some other claim about the benefits of the package. To that end, we’ve sent out a survey collecting the iron counts for our subscribers, and filtered that data into “low”, “normal”, and “high”.We received 200 responses from our Vein Package subscribers. 70% of them had low iron counts, 20% had normal, and 10% of them have high iron counts.We were only able to get 145 responses from our Artery Package subscribers, but only 20% of them had low iron counts. 60% had normal, and 20% have high iron counts. The data from the survey has been collected and formatted into a contingency table. You can access that data from the function familiar.iron_counts_for_package(). Save the survey results into a variable called iron_contingency_table.<jupyter_code>iron_contingency_table =familiar.iron_counts_for_package()<jupyter_output><empty_output><jupyter_text>We want to be able to tell if what seems like a higher number of our Artery Package subscribers is a significant difference from what was reported by Vein Package subscribers. Import the Chi-Squared test so that we can find out. Run the Chi-Squared test on the iron_contingency_table and save the p-value in a variable called iron_pvalue. Remember that this test returns four things: the test statistic, the p-value, the number of degrees of freedom, and the expected frequencies.<jupyter_code>_, iron_pvalue, _, _ = chi2_contingency(iron_contingency_table)
print(iron_pvalue)<jupyter_output>2.9227133549883315e-19<jupyter_text>Here’s the big moment: if the iron_pvalue is less than 0.05, print out “The Artery Package Is Proven To Make You Healthier!” otherwise we’ll have to use our other marketing copy: “While We Can’t Say The Artery Package Will Help You, I Bet It’s Nice!”<jupyter_code>if iron_pvalue < 0.05 :
  print(' The Artery Package Is Proven To Make You Healthier! ')
else:
  print(' While We Can’t Say The Artery     Package Will Help You, I Bet It’s Nice!')<jupyter_output>The Artery Package Is Proven To Make You Healthier!
{'fraction_non_alphanumeric': 0.05361975642760487, 'fraction_numerical': 0.017591339648173207, 'mean_word_length': 5.81221198156682, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 35, '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': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '601650', 'license': 'MIT', 'n_tokens_mistral': 1762, 'n_tokens_neox': 1641, 'n_words': 778, 'path': 'Familiar A Study In Data Analysis/Script.ipynb', 'repo_name': 'bibekuchiha/Hypothesis-Testing', 'size': '5912'}