mstats.ttest_rel axis=None, requires masked array #3047

Closed
josef-pkt opened this Issue Nov 8, 2013 · 2 comments

Comments

Projects
None yet
2 participants
@josef-pkt
Member

josef-pkt commented Nov 8, 2013

mstats.ttest_rel has wrong axis default axis=None instead of axis=0
requires masked array if axis=None

ma.ravel does not convert to masked arrays, at least not with numpy 1.6.1

def _chk2_asarray(a, b, axis):
    if axis is None:
        a = ma.ravel(a)
        b = ma.ravel(b)
>>> outcome = np.random.randn(20, 4) + [0, 0, 1, 2]
>>> stats.mstats.ttest_rel(outcome[:, 0], outcome[:, 1:])
Traceback (most recent call last):
  File "<pyshell#30>", line 1, in <module>
    stats.mstats.ttest_rel(outcome[:, 0], outcome[:, 1:])
  File "C:\Programs\Python27\lib\site-packages\scipy\stats\mstats_basic.py", line 782, in ttest_rel
    raise ValueError('unequal length arrays')
ValueError: unequal length arrays

>>> [stats.mstats.ttest_rel(outcome[:, 0], outcome[:, k]) for k in range(1, 4)]
Traceback (most recent call last):
  File "<pyshell#31>", line 1, in <module>
    [stats.mstats.ttest_rel(outcome[:, 0], outcome[:, k]) for k in range(1, 4)]
  File "C:\Programs\Python27\lib\site-packages\scipy\stats\mstats_basic.py", line 785, in ttest_rel
    n = a.count(axis)
AttributeError: 'numpy.ndarray' object has no attribute 'count'
@rgommers

This comment has been minimized.

Show comment
Hide comment
@rgommers

rgommers Nov 10, 2013

Member

The issue with _chk2_asarray I had already fixed in gh-3008.

Member

rgommers commented Nov 10, 2013

The issue with _chk2_asarray I had already fixed in gh-3008.

@rgommers

This comment has been minimized.

Show comment
Hide comment
@rgommers

rgommers Nov 10, 2013

Member

Other issue now also fixed in gh-3008.

Member

rgommers commented Nov 10, 2013

Other issue now also fixed in gh-3008.

@rgommers rgommers closed this in 32051ab Nov 10, 2013

andrenarchy added a commit to andrenarchy/scipy that referenced this issue Dec 4, 2013

BUG: fix errors in mstats.ttest_rel and mstats.ttest_ind.
Change default of axis kw to 0 in ttest_rel.  This is OK without warning
because the function didn't work before anyway.

Also provide basic test coverage (comparison against nonmasked version).
Testing with various masked array inputs to be done.

Closes gh-3047.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment