chi-squared tests in python?

M

Matthew Vernon

Hi,

I'd like to be able to use the chi-squared test in my code. Currently,
I can output "look up [this value] in a chi-squared table with [x]
degrees of freedom", but that's obviously a little sub-optimal. I
notice that numarray has a chi_square function, but that just gives
you random numbers from a chi-squared distribution with a set number
of degrees of freedom - not really what I want.

Does there exist python code to do this? preferably something vaguely
standard?

Thanks,

Matthew
ps: given the "batteries included" philosphy, there's a remarkable dearth
of stats in python...
 
R

Robert Kern

Matthew said:
Hi,

I'd like to be able to use the chi-squared test in my code. Currently,
I can output "look up [this value] in a chi-squared table with [x]
degrees of freedom", but that's obviously a little sub-optimal. I
notice that numarray has a chi_square function, but that just gives
you random numbers from a chi-squared distribution with a set number
of degrees of freedom - not really what I want.

Does there exist python code to do this? preferably something vaguely
standard?

Yes, in Scipy.

from scipy.stats import chi2

# one-sided Chi^2 test
pval = 1 - chi2.cdf(value, dof)

http://new.scipy.org/Wiki
[This URL will be http://www.scipy.org in a week or so, I hope.]
Matthew
ps: given the "batteries included" philosphy, there's a remarkable dearth
of stats in python...

I think Chi^2 tests fall distinctly in the "third-party library" category, myself.

--
Robert Kern
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 
R

Rob Cowie

Matthew
I think Chi^2 tests fall distinctly in the "third-party library" category, >myself.

I don't know... I've often thought the Standard Library should include
a stats package.
 
M

Michael Anthony Maibaum

I don't know... I've often thought the Standard Library should include
a stats package.

Coming from the scientific community I agree. A relatively shallow
selection of standard statistical methods would be very useful to
avoid requiring people to install a relatively large external package
(e.g. scipy) for a few simple stats methods.

cheers,
Michael
 
R

Robert Kern

Michael said:
Coming from the scientific community I agree. A relatively shallow
selection of standard statistical methods would be very useful to
avoid requiring people to install a relatively large external package
(e.g. scipy) for a few simple stats methods.

Gary Strangman's stats.py has existed for many years. Of course, it's utility
went up quite a bit when it got integrated into scipy so that it could use
efficient arrays instead of lists and had access to our library of special
functions.

--
Robert Kern
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 
M

Michael Anthony Maibaum

Gary Strangman's stats.py has existed for many years. Of course,
it's utility
went up quite a bit when it got integrated into scipy so that it
could use
efficient arrays instead of lists and had access to our library of
special
functions.


Sure and that is actually what I've used when I've needed a
lightweight solution. I wouldn't begin to argue that something like
scipy isn't a better general solution, but something like stats.py
might well be a useful addition to the core library.

Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top