Skip to content

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

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

2 participants

@josef-pkt
SciPy member

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
SciPy member

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

@rgommers
SciPy member

Other issue now also fixed in gh-3008.

@rgommers rgommers added a commit that closed this issue Nov 10, 2013
@rgommers rgommers 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.
32051ab
@rgommers rgommers closed this in 32051ab Nov 10, 2013
@andrenarchy andrenarchy added a commit to andrenarchy/scipy that referenced this issue Dec 4, 2013
@rgommers rgommers 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.
21ca1ac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.