Last active
March 27, 2018 03:48
-
-
Save chelseatroy/3cf86fd882a94c25d8e19a4b17ab4899 to your computer and use it in GitHub Desktop.
T-Tests for Independent Examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment