fix bug in mann whitney u test

This commit is contained in:
Han Fei 2024-08-19 17:06:24 +02:00
parent 008d02880b
commit 2c8fade3d7
2 changed files with 22 additions and 2 deletions

View File

@ -114,7 +114,7 @@ private:
{
if (ind < first.size())
return first[ind];
return second[ind % first.size()];
return second[ind - first.size()];
}
size_t size() const

View File

@ -17,9 +17,20 @@ def test_and_check(name, a, b, t_stat, p_value):
client.query(
"CREATE TABLE mann_whitney (left Float64, right UInt8) ENGINE = Memory;"
)
#client.query(
# "INSERT INTO mann_whitney VALUES {};".format(
# ", ".join(["({},{}), ({},{})".format(i, 0, j, 1) for i, j in zip(a, b)])
# )
#)
client.query(
"INSERT INTO mann_whitney VALUES {};".format(
", ".join(["({},{}), ({},{})".format(i, 0, j, 1) for i, j in zip(a, b)])
", ".join(["({},{})".format(i, 0) for i in a])
)
)
client.query(
"INSERT INTO mann_whitney VALUES {};".format(
", ".join(["({},{})".format(i, 1) for i in b])
)
)
@ -59,6 +70,15 @@ def test_mann_whitney():
test_and_check("mannWhitneyUTest('greater')", rvs1, rvs2, s, p)
def test_mann_whitney_skew():
rvs1 = [1]
rvs2 = [0,2,4]
s, p = stats.mannwhitneyu(rvs1, rvs2, alternative="two-sided")
test_and_check("mannWhitneyUTest", rvs1, rvs2, s, p)
test_and_check("mannWhitneyUTest('two-sided')", rvs1, rvs2, s, p)
if __name__ == "__main__":
test_mann_whitney()
test_mann_whitney_skew()
print("Ok.")