77 upsample ,
88 winsorize ,
99 align ,
10- transform_pairwise )
10+ transform_pairwise , _calc_pvalue )
1111from nltools .simulator import Simulator
1212from nltools .mask import create_sphere
13+ # import pytest
1314
1415def test_permutation ():
1516 dat = np .random .multivariate_normal ([2 , 6 ], [[.5 , 2 ], [.5 , 3 ]], 1000 )
1617 x = dat [:, 0 ]
1718 y = dat [:, 1 ]
18- stats = two_sample_permutation (x , y )
19- assert (stats ['mean' ] < - 2 ) & (stats ['mean' ] > - 6 )
20- assert stats ['p' ] < .001
21- print (stats )
22- stats = one_sample_permutation (x - y )
23- assert (stats ['mean' ] < - 2 ) & (stats ['mean' ] > - 6 )
24- assert stats ['p' ] < .001
25- print (stats )
26- stats = correlation_permutation (x , y , metric = 'pearson' )
27- assert (stats ['correlation' ] > .4 ) & (stats ['correlation' ]< .85 )
28- assert stats ['p' ] < .001
29- stats = correlation_permutation (x , y , metric = 'spearman' )
30- assert (stats ['correlation' ] > .4 ) & (stats ['correlation' ]< .85 )
31- assert stats ['p' ] < .001
32- stats = correlation_permutation (x , y , metric = 'kendall' )
33- assert (stats ['correlation' ] > .4 ) & (stats ['correlation' ]< .85 )
34- assert stats ['p' ] < .001
19+ stats = two_sample_permutation (x , y ,tail = 1 )
20+ assert (stats ['mean' ] < - 2 ) & (stats ['mean' ] > - 6 ) & (stats ['p' ] < .001 )
21+ stats = one_sample_permutation (x - y ,tail = 1 )
22+ assert (stats ['mean' ] < - 2 ) & (stats ['mean' ] > - 6 ) & (stats ['p' ] < .001 )
23+ stats = correlation_permutation (x , y , metric = 'pearson' ,tail = 1 )
24+ assert (stats ['correlation' ] > .4 ) & (stats ['correlation' ]< .85 ) & (stats ['p' ] < .001 )
25+ stats = correlation_permutation (x , y , metric = 'spearman' ,tail = 1 )
26+ assert (stats ['correlation' ] > .4 ) & (stats ['correlation' ]< .85 ) & (stats ['p' ] < .001 )
27+ stats = correlation_permutation (x , y , metric = 'kendall' ,tail = 2 )
28+ assert (stats ['correlation' ] > .4 ) & (stats ['correlation' ]< .85 ) & (stats ['p' ] < .001 )
29+ # with pytest.raises(ValueError):
30+ # correlation_permutation(x, y, metric='kendall',tail=3)
31+ # with pytest.raises(ValueError):
32+ # correlation_permutation(x, y, metric='doesntwork',tail=3)
33+ s = np .random .normal (0 ,1 ,10000 )
34+ two_sided = _calc_pvalue (all_p = s , stat = 1.96 , tail = 2 )
35+ upper_p = _calc_pvalue (all_p = s , stat = 1.96 , tail = 1 )
36+ lower_p = _calc_pvalue (all_p = s , stat = - 1.96 , tail = 1 )
37+ sum_p = upper_p + lower_p
38+ np .testing .assert_almost_equal (two_sided , sum_p )
3539
3640def test_downsample ():
3741 dat = pd .DataFrame ()
3842 dat ['x' ] = range (0 ,100 )
3943 dat ['y' ] = np .repeat (range (1 ,11 ),10 )
4044 assert ((dat .groupby ('y' ).mean ().values .ravel () == downsample (data = dat ['x' ],sampling_freq = 10 ,target = 1 ,target_type = 'hz' ,method = 'mean' ).values ).all )
4145 assert ((dat .groupby ('y' ).median ().values .ravel () == downsample (data = dat ['x' ],sampling_freq = 10 ,target = 1 ,target_type = 'hz' ,method = 'median' ).values ).all )
46+ # with pytest.raises(ValueError):
47+ # downsample(data=list(dat['x']),sampling_freq=10,target=1,target_type='hz',method='median')
48+ # with pytest.raises(ValueError):
49+ # downsample(data=dat['x'],sampling_freq=10,target=1,target_type='hz',method='doesnotwork')
50+ # with pytest.raises(ValueError):
51+ # downsample(data=dat['x'],sampling_freq=10,target=1,target_type='doesnotwork',method='median')
4252
4353def test_upsample ():
4454 dat = pd .DataFrame ()
@@ -50,6 +60,10 @@ def test_upsample():
5060 fs = 3
5161 us = upsample (dat ,sampling_freq = 1 ,target = fs ,target_type = 'hz' )
5262 assert (dat .shape [0 ]* fs - fs == us .shape [0 ])
63+ # with pytest.raises(ValueError):
64+ # upsample(dat,sampling_freq=1,target=fs,target_type='hz',method='doesnotwork')
65+ # with pytest.raises(ValueError):
66+ # upsample(dat,sampling_freq=1,target=fs,target_type='doesnotwork',method='linear')
5367
5468def test_winsorize ():
5569 outlier_test = pd .DataFrame ([92 , 19 , 101 , 58 , 1053 , 91 , 26 , 78 , 10 , 13 ,
0 commit comments