Skip to content

Commit

Permalink
BUG: make stats.f_oneway work with integer array input.
Browse files Browse the repository at this point in the history
Closes gh-3376.
  • Loading branch information
ankit-maverick authored and rgommers committed Mar 16, 2014
1 parent 89654ae commit 01e88d8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions scipy/stats/stats.py
Expand Up @@ -2379,14 +2379,15 @@ def f_oneway(*args):
.. [2] Heiman, G.W. Research Methods in Statistics. 2002.
"""
args = list(map(np.asarray, args)) # convert to an numpy array
na = len(args) # ANOVA on 'na' groups, each in it's own array
args = [np.asarray(arg, dtype=float) for arg in args]
na = len(args) # ANOVA on 'na' groups, each in it's own array
alldata = np.concatenate(args)
bign = len(alldata)
sstot = ss(alldata) - (square_of_sums(alldata) / float(bign))
ssbn = 0
for a in args:
ssbn += square_of_sums(a) / float(len(a))

ssbn -= (square_of_sums(alldata) / float(bign))
sswn = sstot - ssbn
dfbn = na - 1
Expand Down
11 changes: 7 additions & 4 deletions scipy/stats/tests/test_stats.py
Expand Up @@ -2668,22 +2668,25 @@ def test_sigmaclip3(self):


class TestFOneWay(TestCase):

def test_trivial(self):
# A trivial test of stats.f_oneway, with F=0.
F, p = stats.f_oneway([0,2], [0,2])
assert_equal(F, 0.0)

def test_basic(self):
# A test of stats.f_oneway, with F=2.
F, p = stats.f_oneway([0,2], [2,4])
# Despite being a floating point calculation, this data should
# result in F being exactly 2.0.
F, p = stats.f_oneway([0,2], [2,4])
assert_equal(F, 2.0)

def test_large_integer_array(self):
a = np.array([655, 788], dtype=np.uint16)
b = np.array([789, 772], dtype=np.uint16)
F, p = stats.f_oneway(a, b)
assert_almost_equal(F, 0.77450216931805538)

class TestKruskal(TestCase):

class TestKruskal(TestCase):
def test_simple(self):
x = [1]
y = [2]
Expand Down

0 comments on commit 01e88d8

Please sign in to comment.