Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

P-value from Chi sq test statistic in Python

I have computed a test statistic that is distributed as a chi square with 1 degree of freedom, and want to find out what P-value this corresponds to using python.

I'm a python and maths/stats newbie so I think what I want here is the probability denisty function for the chi2 distribution from SciPy. However, when I use this like so:

from scipy import stats stats.chi2.pdf(3.84 , 1) 0.029846 

However some googling and talking to some colleagues who know maths but not python have said it should be 0.05.

Any ideas? Cheers, Davy

like image 796
Davy Kavanagh Avatar asked Jul 30 '12 15:07

Davy Kavanagh


People also ask

Does Chi-square test give p-value?

Chi Square P-Values.A chi square test will give you a p-value. The p-value will tell you if your test results are significant or not. In order to perform a chi square test and get the p-value, you need two pieces of information: Degrees of freedom.

How do you interpret chi square results in Python?

We make use of p-value to interpret the Chi-square test. If the p-value is less than the assumed significance value (0.05), then we fail to accept that there is no association between the variables. That is, we reject the NULL hypothesis and accept the alternate hypothesis claim.


1 Answers

Quick refresher here:

Probability Density Function: think of it as a point value; how dense is the probability at a given point?

Cumulative Distribution Function: this is the mass of probability of the function up to a given point; what percentage of the distribution lies on one side of this point?

In your case, you took the PDF, for which you got the correct answer. If you try 1 - CDF:

>>> 1 - stats.chi2.cdf(3.84, 1) 0.050043521248705147 

PDF CDF

like image 97
2 revs, 2 users 82% Avatar answered Sep 18 '22 15:09

2 revs, 2 users 82%