rottweiler_tl = fetchmaker.get_tail_length("rottweiler") rottweiler_tl_mean = np.mean(rottweiler_tl) rottweiler_tl_std = np.std(rottweiler_tl) print (rottweiler_tl_mean) print (rottweiler_tl_std) whippet_rescue = fetchmaker.get_is_rescue("whippet") num_whippet_rescues = np.count_nonzero(whippet_rescue) print (num_whippet_rescues) num_whippets = np.size(whippet_rescue) print (num_whippets) pval = binom_test(num_whippet_rescues,num_whippets,0.08) print (pval) a = fetchmaker.get_weight("whippet") b = fetchmaker.get_weight("terrier") c = fetchmaker.get_weight("pitbull") fstat,pval = f_oneway(a,b,c) print (pval) v = np.concatenate([a,b,c]) labels = ['whippet']*len(a) + ['terrier']*len(b) + ['pitbull']*len(c) tukey_results = pairwise_tukeyhsd(v,labels,0.05) print (tukey_results) poodle_colors = fetchmaker.get_color("poodle") shihtzu_colors = fetchmaker.get_color("shihtzu") x11 = np.count_nonzero(poodle_colors == 'black') x12 = np.count_nonzero(shihtzu_colors == 'black')
print(np.std(rottweiler_tl)) """ Over the years, we have seen that we expect 8% of dogs in the FetchMaker system to be rescues. We want to know if whippets are significantly more or less likely to be a rescue. """ whippet_rescue = fetchmaker.get_is_rescue("whippet") num_whippet_rescues = np.count_nonzero(whippet_rescue) print(num_whippet_rescues) num_whippets = np.size(whippet_rescue) print(num_whippets) pval = binom_test(num_whippet_rescues, n=num_whippets, p=0.08) print(pval) """ Three of our most popular mid-sized dog breeds are whippets, terriers, and pitbulls. Is there a significant difference in the average weights of these three dog breeds? Perform a comparative numerical test to determine if there is a significant difference. """ whippet_weight = fetchmaker.get_weight("whippet") terrier_weight = fetchmaker.get_weight("terrier") pitbull_weight = fetchmaker.get_weight("pitbull") print(np.size(whippet_weight)) print(np.size(terrier_weight)) print(np.size(pitbull_weight)) tstat, pval = f_oneway(whippet_weight, terrier_weight, pitbull_weight) print(pval) v = np.concatenate([whippet_weight, terrier_weight, pitbull_weight]) labels = ['whippet_weight'] * len(whippet_weight) + ['terrier_weight'] * len( terrier_weight) + ['pitbull_weight'] * len(pitbull_weight) tukey_results = pairwise_tukeyhsd(v, labels, 0.05) print(tukey_results) """
from scipy.stats import f_oneway from statsmodels.stats.multicomp import pairwise_tukeyhsd from scipy.stats import chi2_contingency rottweiler_tl = fetchmaker.get_tail_length('rottweiler') print(np.mean(rottweiler_tl)) print(np.std(rottweiler_tl)) whippet_rescue = fetchmaker.get_is_rescue('whippet') num_whippet_rescues = np.count_nonzero(whippet_rescue) num_whippets = np.size(whippet_rescue) print(binom_test(num_whippet_rescues, num_whippets, .08)) w = fetchmaker.get_weight('whippet') t = fetchmaker.get_weight('terrier') p = fetchmaker.get_weight('pitbull') print(f_oneway(w, t, p).pvalue) values = np.concatenate([w, t, p]) labels = ['whippet'] * len(w) + ['terrier'] * len(t) + ['pitbull'] * len(p) print(pairwise_tukeyhsd(values, labels, .05)) poodle_colors = fetchmaker.get_color('poodle') shihtzu_colors = fetchmaker.get_color('shihtzu') color_table = [[ np.count_nonzero(poodle_colors == 'black'), np.count_nonzero(shihtzu_colors == 'black')
num_whippet_rescue = np.count_nonzero(whippet_rescue) print(num_whippet_rescue) num_whippets = np.size(whippet_rescue) print(num_whippets) from scipy.stats import binom_test whippet_binom_test = binom_test(num_whippet_rescue, num_whippets, 0.08) if whippet_binom_test < 0.05: print('Significant Difference!') else: print('No Difference.') from scipy.stats import f_oneway whippet_avg_weight = fetchmaker.get_weight('whippet') terrier_avg_weight = fetchmaker.get_weight('terrier') pitbull_avg_weight = fetchmaker.get_weight('pitbull') weight_t, weight_pval = f_oneway(whippet_avg_weight, terrier_avg_weight, pitbull_avg_weight) if weight_pval < 0.05: print('There is a difference between these breeds!') else: print('There is no difference between these breeds.') from statsmodels.stats.multicomp import pairwise_tukeyhsd weight_pw = np.concatenate( [whippet_avg_weight, terrier_avg_weight, pitbull_avg_weight]) weight_labels = ['whippet'] * len(whippet_avg_weight) + ['terrier'] * len(
import numpy as np import fetchmaker from scipy.stats import binom_test from scipy.stats import f_oneway from statsmodels.stats.multicomp import pairwise_tukeyhsd from scipy.stats import chi2_contingency rottweiler_tl = fetchmaker.get_weight("rottweiler") print print np.mean(rottweiler_tl) print np.std(rottweiler_tl) whippet_rescue = fetchmaker.get_is_rescue("whippet") num_whippet_rescues = np.count_nonzero(whippet_rescue==1) num_whippets = np.size(whippet_rescue) pval = binom_test(num_whippets, n=10000, p=0.08) print pval whippets = fetchmaker.get_weight("whippet") terriers = fetchmaker.get_weight("terrier") pitbulls = fetchmaker.get_weight("pitbull") fstat, pval = f_oneway(whippets, terriers, pitbulls) print pval v = np.concatenate([whippets, terriers, pitbulls]) labels = ['Whippets'] * len(whippets) + ['Terriers'] * len(terriers) + ['Pitbulls'] * len(pitbulls)
from scipy.stats import chi2_contingency rottweiler_tl = fm.get_tail_length("rottweiler") print(np.mean(rottweiler_tl)) print(np.std(rottweiler_tl)) whippet_rescue = fm.get_is_rescue("whippet") num_whippet_rescues = np.count_nonzero(whippet_rescue) num_whippets = np.size(whippet_rescue) pval = binom_test(num_whippet_rescues, num_whippets, p=0.08) print(pval) # pval > 0.05 : Not significant whippet_wg = fm.get_weight("whippet") terrier_wg = fm.get_weight("terrier") pitbull_wg = fm.get_weight("pitbull") pval2 = f_oneway(whippet_wg, terrier_wg, pitbull_wg).pvalue print(pval2) # pval > 0.05 : Not significant weights = np.concatenate([whippet_wg, terrier_wg, pitbull_wg]) labels = ["Whippet"] * len(whippet_wg) + ["Terrier"] * len(terrier_wg) + ["Pitbull"] * len(pitbull_wg) tukey_results = pairwise_tukeyhsd(weights, labels, 0.05) print(tukey_results)
# on average, 8% of dogs in the FetchMaker system is expected to be rescues # find out if the number of whippet rescues is statistically equal to the expected percentage of 8% whippet_rescue = fetchmaker.get_is_rescue('whippet') num_whippet_rescues = np.count_nonzero(whippet_rescue) print(num_whippet_rescues) # number of whippets that is a rescue is 6 num_whippet = np.size(whippet_rescue) print(num_whippet) # total number of whippets is 100 pval = binom_test(6, 100, 0.08) print(format(pval, '0.10f')) # the difference in percentage is not significant (p = .58), the number of whippet rescues doesn't differ from the expected average of 8% # perform a test to determine if there is a significant difference in average weights of three of the most popular dog breeds; whippets, terriers and pitbulls weight_pitbull = fetchmaker.get_weight('pitbull') weight_whippet = fetchmaker.get_weight('whippet') weight_terrier = fetchmaker.get_weight('terrier') weight_compare_test = f_oneway(weight_pitbull, weight_whippet, weight_terrier) print(format(weight_compare_test.pvalue, '0.10f')) # p < .01 # now perform another test to determine which of the pairs of these dog breeds differ from each other values = np.concatenate([weight_pitbull, weight_whippet, weight_terrier]) labels = ['pitbull'] * len(weight_pitbull) + ['whippet'] * len( weight_whippet) + ['terrier'] * len(weight_terrier) tukey_results = pairwise_tukeyhsd(values, labels, 0.05) print(tukey_results) # in the result table we can see that pitbulls and whippets are similar in weight, pitbulls and terriers differ in weight and terriers and whippets differ in weight as well
import numpy as np import fetchmaker from scipy.stats import binom_test from scipy.stats import f_oneway from statsmodels.stats.multicomp import pairwise_tukeyhsd from scipy.stats import chi2_contingency rottweiler_tl = fetchmaker.get_tail_length('rottweiler') print rottweiler_tl print np.std(rottweiler_tl) print np.mean(rottweiler_tl) whippet_rescue = fetchmaker.get_is_rescue('whippet') num_whippet_rescues = np.count_nonzero(whippet_rescue) num_whippets = np.size(whippet_rescue) pval = binom_test(num_whippet_rescues, num_whippets, 0.08) print pval whippets_weight = fetchmaker.get_weight('whippet') terriers_weight = fetchmaker.get_weight('terrier') pitbulls_weight = fetchmaker.get_weight('pitbull') tstat, pval_wt = f_oneway(whippets_weight, terriers_weight, pitbulls_weight) print pval_wt v = np.concatenate([whippets_weight, terriers_weight, pitbulls_weight]) labels = ['whippet'] * len(whippets_weight) + ['terrier'] * len( terriers_weight) + ['pitbull'] * len(pitbulls_weight) tukey_results = pairwise_tukeyhsd(v, labels, 0.05) print tukey_results poodle_colors = fetchmaker.get_color('poodle') shihtzu_colors = fetchmaker.get_color('shihtzu') color_table = [[ np.count_nonzero(poodle_colors == 'black'), np.count_nonzero(shihtzu_colors == 'black') ],
# Get number of whippet rescues and total whippets num_whippet_rescues = np.count_nonzero(whippet_rescue) assert np.sum(whippet_rescue) == num_whippet_rescues num_whippets = whippet_rescue.size print(binom_test(num_whippet_rescues, n=num_whippets, p=0.08)) print( 'Unable to reject hypothesis that whippets have avg likelihood of being a rescue.\n' ) # Determine if there is a sig. diff. between # the weights of whippets, terriers and pitbulls weights = [] for breed in ['whippet', 'terrier', 'pitbull']: weights.append(fetchmaker.get_weight(breed)) print(f_oneway(*weights).pvalue) print( 'Reject the null hypothesis that whippets, terriers and pitbulls have the same average weight.' ) # Determine which breed is different labels = ['whippet']*len(weights[0]) + \ ['terrier']*len(weights[1]) + \ ['pitbull']*len(weights[2]) tukey_range = pairwise_tukeyhsd(np.concatenate(weights), labels, 0.05) count = 0 for i in range(len(tukey_range.groupsunique) - 1): for j in range(i + 1, len(tukey_range.groupsunique)): print('Reject {}-{}? {}'.format(tukey_range.groupsunique[i],