[SciPy-dev] Problem with F distribution, or with me?

josef.pktd@gmai... josef.pktd@gmai...
Tue Aug 12 14:43:54 CDT 2008


The problem is that the F distribution in distributions.c is missing
a multiplication by the ratio of the degrees of freedom, see the correct
rk_noncentral_f


*dfden  / dfnum


http://projects.scipy.org/scipy/numpy/browser/trunk/numpy/random/mtrand/distributions.c

226     double rk_f(rk_state *state, double dfnum, double dfden)
227     {
228         return rk_chisquare(state, dfnum) / rk_chisquare(state, dfden);
229     }
230
231     double rk_noncentral_f(rk_state *state, double dfnum, double dfden,
double nonc)
232     {
233         return ((rk_noncentral_chisquare(state, dfnum, nonc)*dfden) /
234                 (rk_chisquare(state, dfden)*dfnum));


change line 228 to
return (rk_chisquare(state, dfnum)*dfden)  / (rk_chisquare(state, dfden)
*dfnum);


correct random variables require normalization:

>>> np.sum(1/2.0*40.0*np.random.f(2, 40, 1000000)>  2.44037)
99891

>>> np.sum(1/1.0*48.0*np.random.f(1, 48, 1000000)>  7.19)
10118
>>> np.sum(1/1.0*48.0*np.random.f(1, 48, 1000000)>  7.19)
10174
>>> np.sum(1/1.0*48.0*np.random.f(1, 48, 1000000)>  7.19)
10043

Josef
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-dev/attachments/20080812/4298cde4/attachment.html 


More information about the Scipy-dev mailing list