# implementation of $\chi^2$ test in python

I'm trying to check if a set of data has a Poisson distribution and for that I'm trying to implement a chi square test. My input data is an array that counts the amount of events registered in 1 second and I wanted to use the method:

scipy.stats.chisquare(data,expected)


As I understand from chisquare documentation(https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.chisquare.html) I have to give an array "expected" of what frecuencies I expect to get, but I'm not sure how to generate this array.

• It might be useful to revisit the theory of how you set up your chi-squared test to test that the data comes from a Poisson distribution, and that is something the terse implementational notes in the scipy.stats documentation will not supply. Given that you are trying to evaluate whether there is evidence to suggest that the data generating distribution is Poisson. I am guessing that you will need to use the Poisson distribution to generate the "expected values"? – microhaus Apr 2 at 23:16
• The full set of rules is not well-known and is frequently abused. See my post at stats.stackexchange.com/a/17148/919 for an account of this. Briefly, you must use a Maximum Likelihood estimate of the Poisson parameter, based on the counts, to determine the expected values. – whuber Apr 3 at 13:01