473,395 Members | 1,595 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

chi-squared tests in python?

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...
--
Matthew Vernon MA VetMB LGSM MRCVS
Farm Animal Epidemiology and Informatics Unit
Department of Veterinary Medicine, University of Cambridge
http://www.cus.cam.ac.uk/~mcv21/
Jan 17 '06 #1
5 8768
Matthew Vernon wrote:
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
ro*********@gmail.com

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

Jan 17 '06 #2
>> 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.


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

Jan 17 '06 #3

On 17 Jan 2006, at 20:32, Rob Cowie wrote:
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.


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
Jan 18 '06 #4
Michael Anthony Maibaum wrote:
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
ro*********@gmail.com

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

Jan 18 '06 #5

On 18 Jan 2006, at 16:07, Robert Kern wrote:
Michael Anthony Maibaum wrote:
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.

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
Jan 19 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jam | last post by:
Dear All, I have a command process running xcopy in console, and now I want to execute the program Rsync After the files are copied...how could i do?? Process p10=new Process();...
1
by: c language | last post by:
Hello Everybody, I am looking for a C code that I can use it to get Alpha of a Chi-Square value. Actually I want to give the Chi Squre value and Degree of Freedom (df) and get the alpha value...
0
by: Pixie Songbook | last post by:
The following for loop (and extra from a much larger program) calculates elements of a matrix for use in newtonian minimisation of a non-lienar model. the problem is it wrongly calculates the value...
0
by: molcaleviATyahoogroupsDOTcom | last post by:
B " H _ KO mafia ! Global Democracy ARTSENU & Fusione Fredda = TRIVOLUZIONE W post OPEC ! ! ! e' SAUDITA - Bin Laden la cosi' detta '' mafia ebraica CFR globalmafia ILLUMINATI '' ....
26
by: Nospam | last post by:
I am trying to open a link in a new template window : <a onclick="windowopen('example.html','example');return false;" href="http://www.example.com" target="_blank"example link</a> such that...
0
by: molcaleviATyahoogroupsDOTcom | last post by:
KO mafia CFR ILLUMINATI ! Global Democracy TRIVOLUZIONE ARTSENU COLD FUSION W post OPEC ! B '' H _ KO mafia ! Global Democracy ARTSENU & Fusione Fredda = TRIVOLUZIONE W post OPEC ! ! !
1
by: Mohsen | last post by:
Hello everyone, I have set values and also the degree of freedom of those values in every round of my simulation. I need to know the Chi-Square probabilities of those values in every round of...
0
by: molcaleviATyahoogroupsDOTcom | last post by:
KO mafia CFR ILLUMINATI ! Global Democracy TRIVOLUZIONE ARTSENU COLD FUSION W post OPEC ! B '' H _ KO mafia ! Global Democracy ARTSENU & Fusione Fredda = TRIVOLUZIONE W post OPEC ! ! !
1
by: Tradeorganizer | last post by:
Hi i want to use an excel formula in asp , is it possible the formula chidist in excel gives the value of chi - square distribution over the degree of frequency. but when i am using the same...
18
by: Jordan Glassman | last post by:
Trying to do something fairly routine... drop output into a file to graph, but the following command at the bash command line: ising output produces a blinking cursor, an empty file named...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.