Skip to content

Commit

Permalink
New multiTest_two_sample_independence function for performing multipl…
Browse files Browse the repository at this point in the history
…e tests on two-sample independence
  • Loading branch information
RichieHakim committed May 19, 2024
1 parent 640c028 commit 04c6766
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion bnpm/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,53 @@ def zscore_to_pvalue(z, two_tailed=True):
if two_tailed:
return 2 * scipy.stats.norm.sf(np.abs(z))
else:
return scipy.stats.norm.sf(np.abs(z))
return scipy.stats.norm.sf(np.abs(z))


def multiTest_two_sample_independence(
a,
b,
) -> dict:
"""
Perform multiple tests for two-sample independence.
This function performs the following tests: \n
* Two-sample t-test
* equal variance, unequal variance
* two-tailed, greater, less
* Mann-Whitney U test
* two-tailed, greater, less
Args:
a (np.ndarray or torch.Tensor):
The first samples.
b (np.ndarray or torch.Tensor):
The second samples.
Returns:
dict:
A dictionary containing the results of the tests.
"""
# Perform two-sample t-test
ttest_ind = scipy.stats.ttest_ind(a, b, equal_var=True)
ttest_ind_unequal = scipy.stats.ttest_ind(a, b, equal_var=False)
ttest_ind_greater = scipy.stats.ttest_ind(a, b, alternative="greater")
ttest_ind_unequal_greater = scipy.stats.ttest_ind(a, b, equal_var=False, alternative="greater")
ttest_ind_less = scipy.stats.ttest_ind(a, b, alternative="less")
ttest_ind_unequal_less = scipy.stats.ttest_ind(a, b, equal_var=False, alternative="less")

# Perform Mann-Whitney U test
mannwhitneyu = scipy.stats.mannwhitneyu(a, b, alternative="two-sided")
mannwhitneyu_greater = scipy.stats.mannwhitneyu(a, b, alternative="greater")
mannwhitneyu_less = scipy.stats.mannwhitneyu(a, b, alternative="less")

return {
"ttest_ind": ttest_ind,
"ttest_ind_unequal": ttest_ind_unequal,
"ttest_ind_greater": ttest_ind_greater,
"ttest_ind_unequal_greater": ttest_ind_unequal_greater,
"ttest_ind_less": ttest_ind_less,
"ttest_ind_unequal_less": ttest_ind_unequal_less,
"mannwhitneyu": mannwhitneyu,
"mannwhitneyu_greater": mannwhitneyu_greater,
"mannwhitneyu_less": mannwhitneyu_less,
}

0 comments on commit 04c6766

Please sign in to comment.