-3

I have some t-values and degrees of freedom and want to find the p-values from them (it's two-tailed). In the real world I would use a t-test table in the back of a Statistics textbook; however, I am using stdtr or stats.t.sf function in python. Both of them work fine for small degrees of freedom but give me nan for large degrees of freedom :

pf = 2*stdtr(dof, -np.abs(tf))
pval = 2*stats.t.sf(np.abs(tf), dof-1)

tf = -11.374250, dof=-2176568.362223 gives pf and pval= nan.

Can you please help me understand what is happening here internally. Besides, how can read the code for these internal functions of python.

novieq
  • 88
  • 1
  • 2
  • 14
  • These are not "internal functions of python"; they are from SciPy. Specifically, they are `scipy.special.stdtr()` and `scipy.stats.t.sf()`. The second one's source code is readily available in iPython via `scipy.stats.t.sf??` -- putting two question marks after a function will often bring-up the code. – chrisaycock Jun 06 '15 at 20:42

1 Answers1

2

Re what happens here internally. Well, the Student t distribution is defined for dof > 0, at least in scipy.stats: http://docs.scipy.org/doc/scipy-dev/reference/generated/scipy.stats.t.html. Hence a nan:

In [11]: stats.t.sf(-11, df=10)
Out[11]: 0.99999967038443183

In [12]: stats.t.sf(-11, df=-10)
Out[12]: nan
ev-br
  • 24,968
  • 9
  • 65
  • 78