# [SciPy-User] stats.chisquare issues

Gökhan Sever gokhansever@gmail....
Sun Sep 26 14:02:41 CDT 2010

```Hello,

Consider these examples:

I[35]: np.histogram(ydata, bins=6)
O[35]:
(array([4, 1, 3, 0, 0, 1]),
array([   2.8       ,  146.33333333,  289.86666667,  433.4       ,
576.93333333,  720.46666667,  864.        ]))

I[36]: np.histogram(ypred, bins=6)
O[36]:
(array([4, 2, 2, 0, 0, 1]),
array([  22.08895   ,  166.34439167,  310.59983333,  454.855275  ,
599.11071667,  743.36615833,  887.6216    ]))

I[45]: stats.chisquare([4, 1, 3, 0, 0, 1], [4, 2, 2, 0, 0,
1])---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

/home/gsever/Desktop/<ipython console> in <module>()

/usr/lib/python2.6/site-packages/scipy/stats/stats.pyc in chisquare(f_obs,
f_exp, ddof)
2516     if f_exp is None:
2517         f_exp = array([np.sum(f_obs,axis=0)/float(k)] *
len(f_obs),float)
-> 2518     f_exp = f_exp.astype(float)
2519     chisq = np.add.reduce((f_obs-f_exp)**2 / f_exp)
2520     return chisq, chisqprob(chisq, k-1-ddof)

AttributeError: 'list' object has no attribute 'astype'

Here, I expect any scipy function including chisquare should be able to
handle lists???

############################################

This one throws:

I[46]: stats.chisquare(np.array([4, 1, 3, 0, 0, 1]), np.array([4, 2, 2, 0,
0, 1]))
O[46]: (nan, nan)

again I should be aware since the division has 0 in it.

Further,

I[49]: stats.chisquare(a1, a2)
O[49]: (1.0, 0.96256577324729631)

I[50]: stats.mstats.chisquare(a1, a2)
O[50]: (1.0, 0.80125195690120077)

p-values differ, is this expected?

Thanks.

--
Gökhan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20100926/73742541/attachment.html
```