2
2
3
3
import numpy as np
4
4
import pytest
5
- import scipy .stats as ss
6
5
7
6
from pymare import Dataset
8
7
from pymare .estimators import FisherCombinationTest , StoufferCombinationTest
16
15
(StoufferCombinationTest , _z1 , "concordant" , [4.55204117 ]),
17
16
(StoufferCombinationTest , _z2 , "directed" , [4.69574275 , - 4.16803071 ]),
18
17
(StoufferCombinationTest , _z2 , "undirected" , [4.87462819 , 4.16803071 ]),
19
- (StoufferCombinationTest , _z2 , "concordant" , [4.55204117 , 4.00717817 ]),
18
+ (StoufferCombinationTest , _z2 , "concordant" , [4.55204117 , - 4.00717817 ]),
20
19
(FisherCombinationTest , _z1 , "directed" , [5.22413541 ]),
21
20
(FisherCombinationTest , _z1 , "undirected" , [5.27449962 ]),
22
21
(FisherCombinationTest , _z1 , "concordant" , [5.09434911 ]),
23
22
(FisherCombinationTest , _z2 , "directed" , [5.22413541 , - 3.30626405 ]),
24
23
(FisherCombinationTest , _z2 , "undirected" , [5.27449962 , 4.27572965 ]),
25
- (FisherCombinationTest , _z2 , "concordant" , [5.09434911 , 4.11869468 ]),
24
+ (FisherCombinationTest , _z2 , "concordant" , [5.09434911 , - 4.11869468 ]),
26
25
]
27
26
28
27
29
28
@pytest .mark .parametrize ("Cls,data,mode,expected" , _params )
30
29
def test_combination_test (Cls , data , mode , expected ):
31
30
"""Test CombinationTest Estimators with numpy data."""
32
31
results = Cls (mode ).fit (data ).params_
33
- z = ss .norm .isf (results ["p" ])
34
- assert np .allclose (z , expected , atol = 1e-5 )
32
+ assert np .allclose (results ["z" ], expected , atol = 1e-5 )
35
33
36
34
37
35
@pytest .mark .parametrize ("Cls,data,mode,expected" , _params )
@@ -40,8 +38,7 @@ def test_combination_test_from_dataset(Cls, data, mode, expected):
40
38
dset = Dataset (y = data )
41
39
est = Cls (mode ).fit_dataset (dset )
42
40
results = est .summary ()
43
- z = ss .norm .isf (results .p )
44
- assert np .allclose (z , expected , atol = 1e-5 )
41
+ assert np .allclose (results .z , expected , atol = 1e-5 )
45
42
46
43
47
44
def test_stouffer_adjusted ():
@@ -61,10 +58,9 @@ def test_stouffer_adjusted():
61
58
groups = np .tile (np .array ([0 , 0 , 1 , 2 , 2 , 2 ]), (data .shape [1 ], 1 )).T
62
59
63
60
results = StoufferCombinationTest ("directed" ).fit (z = data , w = weights , g = groups ).params_
64
- z = ss .norm .isf (results ["p" ])
65
61
66
62
z_expected = np .array ([5.00088912 , 3.70356943 , 4.05465924 , 5.4633001 , 5.18927878 ])
67
- assert np .allclose (z , z_expected , atol = 1e-5 )
63
+ assert np .allclose (results [ "z" ] , z_expected , atol = 1e-5 )
68
64
69
65
# Test with weights and no groups. Limiting cases.
70
66
# Limiting case 1: all correlations are one.
@@ -74,22 +70,20 @@ def test_stouffer_adjusted():
74
70
groups_l1 = np .tile (np .array ([0 , 0 , 0 , 0 , 0 ]), (data_l1 .shape [1 ], 1 )).T
75
71
76
72
results_l1 = StoufferCombinationTest ("directed" ).fit (z = data_l1 , g = groups_l1 ).params_
77
- z_l1 = ss .norm .isf (results_l1 ["p" ])
78
73
79
74
sigma_l1 = n_maps_l1 * (n_maps_l1 - 1 ) # Expected inflation term
80
75
z_expected_l1 = n_maps_l1 * common_sample / np .sqrt (n_maps_l1 + sigma_l1 )
81
- assert np .allclose (z_l1 , z_expected_l1 , atol = 1e-5 )
76
+ assert np .allclose (results_l1 [ "z" ] , z_expected_l1 , atol = 1e-5 )
82
77
83
78
# Test with correlation matrix and groups.
84
79
data_corr = data - data .mean (0 )
85
80
corr = np .corrcoef (data_corr , rowvar = True )
86
81
results_corr = (
87
82
StoufferCombinationTest ("directed" ).fit (z = data , w = weights , g = groups , corr = corr ).params_
88
83
)
89
- z_corr = ss .norm .isf (results_corr ["p" ])
90
84
91
85
z_corr_expected = np .array ([5.00088912 , 3.70356943 , 4.05465924 , 5.4633001 , 5.18927878 ])
92
- assert np .allclose (z_corr , z_corr_expected , atol = 1e-5 )
86
+ assert np .allclose (results_corr [ "z" ] , z_corr_expected , atol = 1e-5 )
93
87
94
88
# Test with no correlation matrix and groups, but only one feature.
95
89
with pytest .raises (ValueError ):
@@ -101,6 +95,5 @@ def test_stouffer_adjusted():
101
95
102
96
# Test with correlation matrix and no groups.
103
97
results1 = StoufferCombinationTest ("directed" ).fit (z = _z1 , corr = corr ).params_
104
- z1 = ss .norm .isf (results1 ["p" ])
105
98
106
- assert np .allclose (z1 , [4.69574 ], atol = 1e-5 )
99
+ assert np .allclose (results1 [ "z" ] , [4.69574 ], atol = 1e-5 )
0 commit comments