[SciPy-user] scipy.stats.ttest_ind broken?

Zachary Pincus zpincus at stanford.edu
Wed Mar 1 14:03:32 CST 2006


Can anyone please verify this? The basic T-test should not be broken  
for 1D arrays.

import scipy.stats
scipy.stats.ttest_ind([1,2,3], [2,3,4])
    TypeError: len() of unsized object

For 1d arrays, all the values that the ttest computes are scalars,  
but it assumes that it would be an array.

A patch (though I think there could be a better patch that doesn't  
need a try block):

stats.py, change lines 1463-1464 to:
try:
   if len(probs) == 1:
     probs = probs[0]
except TypeError:
   pass


Zach



On Mar 1, 2006, at 1:54 AM, Zachary Pincus wrote:

> Hi folks,
>
> I'm using scipy 0.4.6 with numpy 0.9.5, and I have noticed that the t-
> test in the stats library is broken.
>
>
> scipy.stats.ttest_ind([1,2,3], [4,5,6])
> ---------------------------------------------------------------------- 
> --
> ---
> exceptions.TypeError                      Traceback (most recent call
> last)
>
> /Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-
> packages/scipy/stats/stats.py in ttest_ind(a, b, axis, printit,
> name1, name2, writemode)
>     1461     if type(t) == ArrayType:
>     1462         probs = reshape(probs,t.shape)
> -> 1463     if len(probs) == 1:
>     1464         probs = probs[0]
>     1465
>
> TypeError: len() of unsized object
>
> What's happening is that betai is returning a scalar value, which has
> no length. This causes the len(probs) call to fail.
>
> Zach Pincus
>
> Program in Biomedical Informatics and Department of Biochemistry
> Stanford University School of Medicine
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-user



More information about the SciPy-user mailing list