Skip to content
{{ message }}

Instantly share code, notes, and snippets.

# chelseatroy/distance.py

Last active Mar 27, 2018
T-Tests for Independent Examples
 def t_test_for(num_samples_1, standard_deviation_1, mean_1, num_samples_2, standard_deviation_2, mean_2, confidence=0.95): alpha = 1 - confidence total_degrees_freedom = num_samples_1 + num_samples_2 - 2 t_distribution_number = -1 * t.ppf(alpha, total_degrees_freedom) degrees_freedom_1 = num_samples_1 - 1 degrees_freedom_2 = num_samples_2 - 1 sum_of_squares_1 = (standard_deviation_1 ** 2) * degrees_freedom_1 sum_of_squares_2 = (standard_deviation_2 ** 2) * degrees_freedom_2 combined_variance = (sum_of_squares_1 + sum_of_squares_2) / (degrees_freedom_1 + degrees_freedom_2) first_dividend_addend = combined_variance/float(num_samples_1) second_dividend_addend = combined_variance/float(num_samples_2) denominator = math.sqrt(first_dividend_addend + second_dividend_addend) numerator = mean_1 - mean_2 t_value = float(numerator)/float(denominator) accept_null_hypothesis = abs(t_value) < abs(t_distribution_number) #results are not significant return accept_null_hypothesis, t_value
to join this conversation on GitHub. Already have an account? Sign in to comment