6
6
7
7
import warnings
8
8
import numpy as np
9
- import scipy .stats as stats
9
+ from scipy .stats import percentileofscore
10
10
from . import helpers
11
11
from . import core
12
12
from . import mstats
@@ -129,7 +129,8 @@ def permutation_corr(Y, *,
129
129
with_replacement ,
130
130
stat_func = corr_func ,
131
131
var_func = np .max ,
132
- side = side )
132
+ side = side ,
133
+ )
133
134
134
135
# compute the real R statistics
135
136
Rstats = Rstats_ = corr_func (np .c_ [x , Y ])
@@ -138,8 +139,9 @@ def permutation_corr(Y, *,
138
139
# compare them to the Rmax distribution with a right-sided test,
139
140
# because significance is obtained for high R stats
140
141
pvals = np .array ([
141
- (100 - stats .percentileofscore (Rmax , R , kind = 'strict' )) / 100
142
- for R in Rstats_ ])
142
+ (100 - percentileofscore (Rmax , R , kind = 'strict' )) / 100
143
+ for R in Rstats_
144
+ ])
143
145
144
146
if return_dist :
145
147
return Rstats , pvals , Rmax
@@ -223,7 +225,8 @@ def permutation_ttest_rel(X, Y, *,
223
225
with_replacement = with_replacement ,
224
226
stat_func = mstats .studentt_rel ,
225
227
var_func = np .max ,
226
- side = side )
228
+ side = side ,
229
+ )
227
230
228
231
# compute the real t statistics
229
232
tstats = tstats_ = mstats .studentt_rel (X - Y )
@@ -232,8 +235,9 @@ def permutation_ttest_rel(X, Y, *,
232
235
# compare them to the tmax distribution with a right-sided test,
233
236
# because significance is obtained for high t stats
234
237
pvals = np .array ([
235
- (100 - stats .percentileofscore (tmax , t , kind = 'strict' )) / 100
236
- for t in tstats_ ])
238
+ (100 - percentileofscore (tmax , t , kind = 'strict' )) / 100
239
+ for t in tstats_
240
+ ])
237
241
238
242
if return_dist :
239
243
return tstats , pvals , tmax
@@ -320,18 +324,22 @@ def permutation_ttest_ind(X, Y, *,
320
324
with_replacement = with_replacement ,
321
325
stat_func = stat_func ,
322
326
var_func = np .max ,
323
- side = side )
327
+ side = side ,
328
+ )
324
329
325
330
# compute the real t statistics
326
- tstats = tstats_ = stat_func (np .concatenate ((X , Y ), axis = 0 ),
327
- [X .shape [0 ], Y .shape [0 ]])
331
+ tstats = tstats_ = stat_func (
332
+ np .concatenate ((X , Y ), axis = 0 ),
333
+ [X .shape [0 ], Y .shape [0 ]],
334
+ )
328
335
if side == 'two' :
329
336
tstats_ = np .abs (tstats_ )
330
337
# compare it to the tmax distribution with a right-sided test,
331
338
# because significance is obtained for high t stats
332
339
pvals = np .array ([
333
- (100 - stats .percentileofscore (tmax , t , kind = 'strict' )) / 100
334
- for t in tstats_ ])
340
+ (100 - percentileofscore (tmax , t , kind = 'strict' )) / 100
341
+ for t in tstats_
342
+ ])
335
343
336
344
if return_dist :
337
345
return tstats , pvals , tmax
@@ -407,14 +415,16 @@ def permutation_wilcoxon(X, Y, *,
407
415
stat_func = mstats .wilcoxon ,
408
416
var_func = np .min ,
409
417
side = 'one' ,
410
- zero_method = zero_method )
418
+ zero_method = zero_method ,
419
+ )
411
420
412
421
# compute the real T statistics
413
422
Tstats = mstats .wilcoxon (X - Y , zero_method )
414
423
# compare it to the Tmin distribution with a left-sided test,
415
424
# because significance is obtained for low T stats
416
425
pvals = np .array ([
417
- stats .percentileofscore (Tmin , T , kind = 'weak' ) / 100 for T in Tstats ])
426
+ percentileofscore (Tmin , T , kind = 'weak' ) / 100 for T in Tstats
427
+ ])
418
428
419
429
if return_dist :
420
430
return Tstats , pvals , Tmin
@@ -482,15 +492,19 @@ def permutation_mannwhitneyu(X, Y, *,
482
492
with_replacement = with_replacement ,
483
493
stat_func = mstats .mannwhitneyu ,
484
494
var_func = np .min ,
485
- side = 'one' )
495
+ side = 'one' ,
496
+ )
486
497
487
498
# compute the real U statistics
488
- Ustats = mstats .mannwhitneyu (np .concatenate ((X , Y ), axis = 0 ),
489
- [X .shape [0 ], Y .shape [0 ]])
499
+ Ustats = mstats .mannwhitneyu (
500
+ np .concatenate ((X , Y ), axis = 0 ),
501
+ [X .shape [0 ], Y .shape [0 ]],
502
+ )
490
503
# compare it to the Umin distribution with a left-sided test,
491
504
# because significance is obtained for low U stats
492
505
pvals = np .array ([
493
- stats .percentileofscore (Umin , U , kind = 'weak' ) / 100 for U in Ustats ])
506
+ percentileofscore (Umin , U , kind = 'weak' ) / 100 for U in Ustats
507
+ ])
494
508
495
509
if return_dist :
496
510
return Ustats , pvals , Umin
@@ -550,7 +564,8 @@ def permutation_f_oneway(*args, n=10000, return_dist=False):
550
564
with_replacement = True ,
551
565
stat_func = mstats .f_oneway ,
552
566
var_func = np .max ,
553
- side = 'one' )
567
+ side = 'one' ,
568
+ )
554
569
555
570
# number of measurements for each sample / group
556
571
list_meas = np .asarray (list (map (len , args )))
@@ -559,8 +574,8 @@ def permutation_f_oneway(*args, n=10000, return_dist=False):
559
574
# compare it to the Fmax distribution with a right-sided test,
560
575
# because significance is obtained for high F stats
561
576
pvals = np .array ([
562
- (100 - stats . percentileofscore (Fmax , F , kind = 'strict' )) / 100
563
- for F in Fstats ])
577
+ (100 - percentileofscore (Fmax , F , kind = 'strict' )) / 100 for F in Fstats
578
+ ])
564
579
565
580
if return_dist :
566
581
return Fstats , pvals , Fmax
@@ -621,16 +636,17 @@ def permutation_kruskal(*args, n=10000, return_dist=False):
621
636
with_replacement = True ,
622
637
stat_func = mstats .kruskal ,
623
638
var_func = np .max ,
624
- side = 'one' )
639
+ side = 'one' ,
640
+ )
625
641
626
642
list_meas = np .asarray (list (map (len , args )))
627
643
# compute the real H statistics
628
644
Hstats = mstats .kruskal (np .concatenate (args , axis = 0 ), list_meas )
629
645
# compare it to the Hmax distribution with a right-sided test,
630
646
# because significance is obtained for high H stats
631
647
pvals = np .array ([
632
- (100 - stats . percentileofscore (Hmax , H , kind = 'strict' )) / 100
633
- for H in Hstats ])
648
+ (100 - percentileofscore (Hmax , H , kind = 'strict' )) / 100 for H in Hstats
649
+ ])
634
650
635
651
if return_dist :
636
652
return Hstats , pvals , Hmax
@@ -714,8 +730,9 @@ def permutation_friedmanchisquare(*args, n=10000, return_dist=False):
714
730
# compare it to the chimax distribution with a right-sided test,
715
731
# because significance is obtained for high chi2 stats
716
732
pvals = np .array ([
717
- (100 - stats .percentileofscore (chi2max , chi2 , kind = 'strict' )) / 100
718
- for chi2 in chi2stats ])
733
+ (100 - percentileofscore (chi2max , chi2 , kind = 'strict' )) / 100
734
+ for chi2 in chi2stats
735
+ ])
719
736
720
737
if return_dist :
721
738
return chi2stats , pvals , chi2max
0 commit comments