/
ibma.py
executable file
·698 lines (554 loc) · 24.5 KB
/
ibma.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
"""Image-based meta-analysis estimators."""
from __future__ import division
import logging
import numpy as np
import pymare
from nilearn.input_data import NiftiMasker
from nilearn.mass_univariate import permuted_ols
from ..base import MetaEstimator
from ..transforms import p_to_z, t_to_z
from ..utils import _boolean_unmask
LGR = logging.getLogger(__name__)
class Fishers(MetaEstimator):
"""An image-based meta-analytic test using t- or z-statistic images.
Requires z-statistic images, but will be extended to work with t-statistic images as well.
Notes
-----
Requires ``z`` images.
Warnings
--------
Masking approaches which average across voxels (e.g., NiftiLabelsMaskers)
will result in invalid results. It cannot be used with these types of maskers.
All image-based meta-analysis estimators adopt an aggressive masking
strategy, in which any voxels with a value of zero in any of the input maps
will be removed from the analysis.
References
----------
* Fisher, R. A. (1934). Statistical methods for research workers.
Statistical methods for research workers., (5th Ed).
https://www.cabdirect.org/cabdirect/abstract/19351601205
See Also
--------
:class:`pymare.estimators.FisherCombinationTest`:
The PyMARE estimator called by this class.
"""
_required_inputs = {"z_maps": ("image", "z")}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def _fit(self, dataset):
self.dataset = dataset
self.masker = self.masker or dataset.masker
if not isinstance(self.masker, NiftiMasker):
raise ValueError(
f"A {type(self.masker)} mask has been detected. "
"Only NiftiMaskers are allowed for this Estimator. "
"This is because aggregation, such as averaging values across ROIs, "
"will produce invalid results."
)
pymare_dset = pymare.Dataset(y=self.inputs_["z_maps"])
est = pymare.estimators.FisherCombinationTest()
est.fit_dataset(pymare_dset)
est_summary = est.summary()
results = {
"z": _boolean_unmask(est_summary.z.squeeze(), self.inputs_["aggressive_mask"]),
"p": _boolean_unmask(est_summary.p.squeeze(), self.inputs_["aggressive_mask"]),
}
return results
class Stouffers(MetaEstimator):
"""A t-test on z-statistic images.
Requires z-statistic images.
Parameters
----------
use_sample_size : :obj:`bool`, optional
Whether to use sample sizes for weights (i.e., "weighted Stouffer's") or not.
Default is False.
Notes
-----
Requires ``z`` images and optionally the sample size metadata field.
Warnings
--------
Masking approaches which average across voxels (e.g., NiftiLabelsMaskers)
will result in invalid results. It cannot be used with these types of maskers.
All image-based meta-analysis estimators adopt an aggressive masking
strategy, in which any voxels with a value of zero in any of the input maps
will be removed from the analysis.
References
----------
* Stouffer, S. A., Suchman, E. A., DeVinney, L. C., Star, S. A., &
Williams Jr, R. M. (1949). The American Soldier: Adjustment during
army life. Studies in social psychology in World War II, vol. 1.
https://psycnet.apa.org/record/1950-00790-000
* Zaykin, D. V. (2011). Optimally weighted Z-test is a powerful method for
combining probabilities in meta-analysis. Journal of evolutionary
biology, 24(8), 1836-1841.
https://doi.org/10.1111/j.1420-9101.2011.02297.x
See Also
--------
:class:`pymare.estimators.StoufferCombinationTest`:
The PyMARE estimator called by this class.
"""
_required_inputs = {"z_maps": ("image", "z")}
def __init__(self, use_sample_size=False, *args, **kwargs):
super().__init__(*args, **kwargs)
self.use_sample_size = use_sample_size
if self.use_sample_size:
self._required_inputs["sample_sizes"] = ("metadata", "sample_sizes")
def _fit(self, dataset):
self.dataset = dataset
self.masker = self.masker or dataset.masker
if not isinstance(self.masker, NiftiMasker):
raise ValueError(
f"A {type(self.masker)} mask has been detected. "
"Only NiftiMaskers are allowed for this Estimator. "
"This is because aggregation, such as averaging values across ROIs, "
"will produce invalid results."
)
est = pymare.estimators.StoufferCombinationTest()
if self.use_sample_size:
sample_sizes = np.array([np.mean(n) for n in self.inputs_["sample_sizes"]])
weights = np.sqrt(sample_sizes)
weight_maps = np.tile(weights, (self.inputs_["z_maps"].shape[1], 1)).T
pymare_dset = pymare.Dataset(y=self.inputs_["z_maps"], v=weight_maps)
else:
pymare_dset = pymare.Dataset(y=self.inputs_["z_maps"])
est.fit_dataset(pymare_dset)
est_summary = est.summary()
results = {
"z": _boolean_unmask(est_summary.z.squeeze(), self.inputs_["aggressive_mask"]),
"p": _boolean_unmask(est_summary.p.squeeze(), self.inputs_["aggressive_mask"]),
}
return results
class WeightedLeastSquares(MetaEstimator):
"""Weighted least-squares meta-regression.
.. versionchanged:: 0.0.8
* [FIX] Remove single-dimensional entries of each array of returns (:obj:`dict`).
.. versionadded:: 0.0.4
Provides the weighted least-squares estimate of the fixed effects given
known/assumed between-study variance tau^2.
When tau^2 = 0 (default), the model is the standard inverse-weighted
fixed-effects meta-regression.
Parameters
----------
tau2 : :obj:`float` or 1D :class:`numpy.ndarray`, optional
Assumed/known value of tau^2. Must be >= 0. Default is 0.
Notes
-----
Requires ``beta`` and ``varcope`` images.
Warnings
--------
Masking approaches which average across voxels (e.g., NiftiLabelsMaskers)
will likely result in biased results. The extent of this bias is currently
unknown.
All image-based meta-analysis estimators adopt an aggressive masking
strategy, in which any voxels with a value of zero in any of the input maps
will be removed from the analysis.
References
----------
* Brockwell, S. E., & Gordon, I. R. (2001). A comparison of statistical
methods for meta-analysis. Statistics in Medicine, 20(6), 825–840.
https://doi.org/10.1002/sim.650
See Also
--------
:class:`pymare.estimators.WeightedLeastSquares`:
The PyMARE estimator called by this class.
"""
_required_inputs = {"beta_maps": ("image", "beta"), "varcope_maps": ("image", "varcope")}
def __init__(self, tau2=0, *args, **kwargs):
super().__init__(*args, **kwargs)
self.tau2 = tau2
def _fit(self, dataset):
self.dataset = dataset
self.masker = self.masker or dataset.masker
if not isinstance(self.masker, NiftiMasker):
LGR.warning(
f"A {type(self.masker)} mask has been detected. "
"Masks which average across voxels will likely produce biased results when used "
"with this Estimator."
)
pymare_dset = pymare.Dataset(y=self.inputs_["beta_maps"], v=self.inputs_["varcope_maps"])
est = pymare.estimators.WeightedLeastSquares(tau2=self.tau2)
est.fit_dataset(pymare_dset)
est_summary = est.summary()
# tau2 is an float, not a map, so it can't go in the results dictionary
results = {
"z": _boolean_unmask(
est_summary.get_fe_stats()["z"].squeeze(), self.inputs_["aggressive_mask"]
),
"p": _boolean_unmask(
est_summary.get_fe_stats()["p"].squeeze(), self.inputs_["aggressive_mask"]
),
"est": _boolean_unmask(
est_summary.get_fe_stats()["est"].squeeze(), self.inputs_["aggressive_mask"]
),
}
return results
class DerSimonianLaird(MetaEstimator):
"""DerSimonian-Laird meta-regression estimator.
.. versionchanged:: 0.0.8
* [FIX] Remove single-dimensional entries of each array of returns (:obj:`dict`).
.. versionadded:: 0.0.4
Estimates the between-subject variance tau^2 using the DerSimonian-Laird
(1986) method-of-moments approach.
Notes
-----
Requires ``beta`` and ``varcope`` images.
Warnings
--------
Masking approaches which average across voxels (e.g., NiftiLabelsMaskers)
will likely result in biased results. The extent of this bias is currently
unknown.
All image-based meta-analysis estimators adopt an aggressive masking
strategy, in which any voxels with a value of zero in any of the input maps
will be removed from the analysis.
References
----------
* DerSimonian, R., & Laird, N. (1986). Meta-analysis in clinical trials.
Controlled clinical trials, 7(3), 177-188.
* Kosmidis, I., Guolo, A., & Varin, C. (2017). Improving the accuracy of
likelihood-based inference in meta-analysis and meta-regression.
Biometrika, 104(2), 489–496. https://doi.org/10.1093/biomet/asx001
See Also
--------
:class:`pymare.estimators.DerSimonianLaird`:
The PyMARE estimator called by this class.
"""
_required_inputs = {"beta_maps": ("image", "beta"), "varcope_maps": ("image", "varcope")}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def _fit(self, dataset):
self.dataset = dataset
self.masker = self.masker or dataset.masker
if not isinstance(self.masker, NiftiMasker):
LGR.warning(
f"A {type(self.masker)} mask has been detected. "
"Masks which average across voxels will likely produce biased results when used "
"with this Estimator."
)
est = pymare.estimators.DerSimonianLaird()
pymare_dset = pymare.Dataset(y=self.inputs_["beta_maps"], v=self.inputs_["varcope_maps"])
est.fit_dataset(pymare_dset)
est_summary = est.summary()
results = {
"tau2": _boolean_unmask(est_summary.tau2.squeeze(), self.inputs_["aggressive_mask"]),
"z": _boolean_unmask(
est_summary.get_fe_stats()["z"].squeeze(), self.inputs_["aggressive_mask"]
),
"p": _boolean_unmask(
est_summary.get_fe_stats()["p"].squeeze(), self.inputs_["aggressive_mask"]
),
"est": _boolean_unmask(
est_summary.get_fe_stats()["est"].squeeze(), self.inputs_["aggressive_mask"]
),
}
return results
class Hedges(MetaEstimator):
"""Hedges meta-regression estimator.
.. versionchanged:: 0.0.8
* [FIX] Remove single-dimensional entries of each array of returns (:obj:`dict`).
.. versionadded:: 0.0.4
Estimates the between-subject variance tau^2 using the Hedges & Olkin (1985)
approach.
Notes
-----
Requires ``beta`` and ``varcope`` images.
Warnings
--------
Masking approaches which average across voxels (e.g., NiftiLabelsMaskers)
will likely result in biased results. The extent of this bias is currently
unknown.
All image-based meta-analysis estimators adopt an aggressive masking
strategy, in which any voxels with a value of zero in any of the input maps
will be removed from the analysis.
References
----------
* Hedges LV, Olkin I. 1985. Statistical Methods for Meta-Analysis.
See Also
--------
:class:`pymare.estimators.Hedges`:
The PyMARE estimator called by this class.
"""
_required_inputs = {"beta_maps": ("image", "beta"), "varcope_maps": ("image", "varcope")}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def _fit(self, dataset):
self.dataset = dataset
self.masker = self.masker or dataset.masker
if not isinstance(self.masker, NiftiMasker):
LGR.warning(
f"A {type(self.masker)} mask has been detected. "
"Masks which average across voxels will likely produce biased results when used "
"with this Estimator."
)
est = pymare.estimators.Hedges()
pymare_dset = pymare.Dataset(y=self.inputs_["beta_maps"], v=self.inputs_["varcope_maps"])
est.fit_dataset(pymare_dset)
est_summary = est.summary()
results = {
"tau2": _boolean_unmask(est_summary.tau2.squeeze(), self.inputs_["aggressive_mask"]),
"z": _boolean_unmask(
est_summary.get_fe_stats()["z"].squeeze(), self.inputs_["aggressive_mask"]
),
"p": _boolean_unmask(
est_summary.get_fe_stats()["p"].squeeze(), self.inputs_["aggressive_mask"]
),
"est": _boolean_unmask(
est_summary.get_fe_stats()["est"].squeeze(), self.inputs_["aggressive_mask"]
),
}
return results
class SampleSizeBasedLikelihood(MetaEstimator):
"""Method estimates with known sample sizes but unknown sampling variances.
.. versionchanged:: 0.0.8
* [FIX] Remove single-dimensional entries of each array of returns (:obj:`dict`).
.. versionadded:: 0.0.4
Iteratively estimates the between-subject variance tau^2 and fixed effect
betas using the specified likelihood-based estimator (ML or REML).
Parameters
----------
method : {'ml', 'reml'}, optional
The estimation method to use. The available options are
============== =============================
"ml" (default) Maximum likelihood
"reml" Restricted maximum likelihood
============== =============================
Notes
-----
Requires ``beta`` images and sample size from metadata.
Homogeneity of sigma^2 across studies is assumed.
The ML and REML solutions are obtained via SciPy’s scalar function
minimizer (:func:`scipy.optimize.minimize`).
Parameters to ``minimize()`` can be passed in as keyword arguments.
Warnings
--------
Likelihood-based estimators are not parallelized across voxels, so this
method should not be used on full brains, unless you can submit your code
to a job scheduler.
All image-based meta-analysis estimators adopt an aggressive masking
strategy, in which any voxels with a value of zero in any of the input maps
will be removed from the analysis.
See Also
--------
:class:`pymare.estimators.SampleSizeBasedLikelihoodEstimator`:
The PyMARE estimator called by this class.
"""
_required_inputs = {
"beta_maps": ("image", "beta"),
"sample_sizes": ("metadata", "sample_sizes"),
}
def __init__(self, method="ml", *args, **kwargs):
super().__init__(*args, **kwargs)
self.method = method
def _fit(self, dataset):
self.dataset = dataset
self.masker = self.masker or dataset.masker
sample_sizes = np.array([np.mean(n) for n in self.inputs_["sample_sizes"]])
n_maps = np.tile(sample_sizes, (self.inputs_["beta_maps"].shape[1], 1)).T
pymare_dset = pymare.Dataset(y=self.inputs_["beta_maps"], n=n_maps)
est = pymare.estimators.SampleSizeBasedLikelihoodEstimator(method=self.method)
est.fit_dataset(pymare_dset)
est_summary = est.summary()
results = {
"tau2": _boolean_unmask(est_summary.tau2.squeeze(), self.inputs_["aggressive_mask"]),
"z": _boolean_unmask(
est_summary.get_fe_stats()["z"].squeeze(), self.inputs_["aggressive_mask"]
),
"p": _boolean_unmask(
est_summary.get_fe_stats()["p"].squeeze(), self.inputs_["aggressive_mask"]
),
"est": _boolean_unmask(
est_summary.get_fe_stats()["est"].squeeze(), self.inputs_["aggressive_mask"]
),
}
return results
class VarianceBasedLikelihood(MetaEstimator):
"""A likelihood-based meta-analysis method for estimates with known variances.
.. versionchanged:: 0.0.8
* [FIX] Remove single-dimensional entries of each array of returns (:obj:`dict`).
.. versionadded:: 0.0.4
Iteratively estimates the between-subject variance tau^2 and fixed effect
coefficients using the specified likelihood-based estimator (ML or REML).
Parameters
----------
method : {'ml', 'reml'}, optional
The estimation method to use. The available options are
============== =============================
"ml" (default) Maximum likelihood
"reml" Restricted maximum likelihood
============== =============================
Notes
-----
Requires ``beta`` and ``varcope`` images.
The ML and REML solutions are obtained via SciPy's scalar function
minimizer (:func:`scipy.optimize.minimize`).
Parameters to ``minimize()`` can be passed in as keyword arguments.
Warnings
--------
Likelihood-based estimators are not parallelized across voxels, so this
method should not be used on full brains, unless you can submit your code
to a job scheduler.
Masking approaches which average across voxels (e.g., NiftiLabelsMaskers)
will likely result in biased results. The extent of this bias is currently
unknown.
All image-based meta-analysis estimators adopt an aggressive masking
strategy, in which any voxels with a value of zero in any of the input maps
will be removed from the analysis.
References
----------
* DerSimonian, R., & Laird, N. (1986). Meta-analysis in clinical trials.
Controlled clinical trials, 7(3), 177-188.
* Kosmidis, I., Guolo, A., & Varin, C. (2017). Improving the accuracy of
likelihood-based inference in meta-analysis and meta-regression.
Biometrika, 104(2), 489–496. https://doi.org/10.1093/biomet/asx001
See Also
--------
:class:`pymare.estimators.VarianceBasedLikelihoodEstimator`:
The PyMARE estimator called by this class.
"""
_required_inputs = {"beta_maps": ("image", "beta"), "varcope_maps": ("image", "varcope")}
def __init__(self, method="ml", *args, **kwargs):
super().__init__(*args, **kwargs)
self.method = method
def _fit(self, dataset):
self.dataset = dataset
self.masker = self.masker or dataset.masker
if not isinstance(self.masker, NiftiMasker):
LGR.warning(
f"A {type(self.masker)} mask has been detected. "
"Masks which average across voxels will likely produce biased results when used "
"with this Estimator."
)
est = pymare.estimators.VarianceBasedLikelihoodEstimator(method=self.method)
pymare_dset = pymare.Dataset(y=self.inputs_["beta_maps"], v=self.inputs_["varcope_maps"])
est.fit_dataset(pymare_dset)
est_summary = est.summary()
results = {
"tau2": _boolean_unmask(est_summary.tau2.squeeze(), self.inputs_["aggressive_mask"]),
"z": _boolean_unmask(
est_summary.get_fe_stats()["z"].squeeze(), self.inputs_["aggressive_mask"]
),
"p": _boolean_unmask(
est_summary.get_fe_stats()["p"].squeeze(), self.inputs_["aggressive_mask"]
),
"est": _boolean_unmask(
est_summary.get_fe_stats()["est"].squeeze(), self.inputs_["aggressive_mask"]
),
}
return results
class PermutedOLS(MetaEstimator):
r"""An analysis with permuted ordinary least squares (OLS), using nilearn.
.. versionchanged:: 0.0.8
* [FIX] Remove single-dimensional entries of each array of returns (:obj:`dict`).
.. versionadded:: 0.0.4
Parameters
----------
two_sided : :obj:`bool`, optional
If True, performs an unsigned t-test. Both positive and negative effects are considered;
the null hypothesis is that the effect is zero. If False, only positive effects are
considered as relevant. The null hypothesis is that the effect is zero or negative.
Default is True.
Notes
-----
Requires ``z`` images.
Available correction methods: :func:`PermutedOLS.correct_fwe_montecarlo`
Warnings
--------
All image-based meta-analysis estimators adopt an aggressive masking
strategy, in which any voxels with a value of zero in any of the input maps
will be removed from the analysis.
References
----------
* Freedman, D., & Lane, D. (1983). A nonstochastic interpretation of reported significance
levels. Journal of Business & Economic Statistics, 1(4), 292-298.
See Also
--------
nilearn.mass_univariate.permuted_ols : The function used for this IBMA.
"""
_required_inputs = {"z_maps": ("image", "z")}
def __init__(self, two_sided=True, *args, **kwargs):
super().__init__(*args, **kwargs)
self.two_sided = two_sided
self.parameters_ = {}
def _fit(self, dataset):
self.dataset = dataset
# Use intercept as explanatory variable
self.parameters_["tested_vars"] = np.ones((self.inputs_["z_maps"].shape[0], 1))
self.parameters_["confounding_vars"] = None
_, t_map, _ = permuted_ols(
self.parameters_["tested_vars"],
self.inputs_["z_maps"],
confounding_vars=self.parameters_["confounding_vars"],
model_intercept=False, # modeled by tested_vars
n_perm=0,
two_sided_test=self.two_sided,
random_state=42,
n_jobs=1,
verbose=0,
)
# Convert t to z, preserving signs
dof = self.parameters_["tested_vars"].shape[0] - self.parameters_["tested_vars"].shape[1]
z_map = t_to_z(t_map, dof)
images = {
"t": _boolean_unmask(t_map.squeeze(), self.inputs_["aggressive_mask"]),
"z": _boolean_unmask(z_map.squeeze(), self.inputs_["aggressive_mask"]),
}
return images
def correct_fwe_montecarlo(self, result, n_iters=10000, n_cores=1):
"""Perform FWE correction using the max-value permutation method.
.. versionchanged:: 0.0.8
* [FIX] Remove single-dimensional entries of each array of returns (:obj:`dict`).
.. versionadded:: 0.0.4
Only call this method from within a Corrector.
Parameters
----------
result : :obj:`~nimare.results.MetaResult`
Result object from an ALE meta-analysis.
n_iters : :obj:`int`, optional
The number of iterations to run in estimating the null distribution.
Default is 10000.
n_cores : :obj:`int`, optional
Number of cores to use for parallelization.
If <=0, defaults to using all available cores. Default is 1.
Returns
-------
images : :obj:`dict`
Dictionary of 1D arrays corresponding to masked images generated by
the correction procedure. The following arrays are generated by
this method: 'z_vthresh', 'p_level-voxel', 'z_level-voxel', and
'logp_level-cluster'.
See Also
--------
nimare.correct.FWECorrector : The Corrector from which to call this method.
nilearn.mass_univariate.permuted_ols : The function used for this IBMA.
Examples
--------
>>> meta = PermutedOLS()
>>> result = meta.fit(dset)
>>> corrector = FWECorrector(method='montecarlo',
n_iters=5, n_cores=1)
>>> cresult = corrector.transform(result)
"""
n_cores = self._check_ncores(n_cores)
log_p_map, t_map, _ = permuted_ols(
self.parameters_["tested_vars"],
self.inputs_["z_maps"],
confounding_vars=self.parameters_["confounding_vars"],
model_intercept=False, # modeled by tested_vars
n_perm=n_iters,
two_sided_test=self.two_sided,
random_state=42,
n_jobs=n_cores,
verbose=0,
)
# Fill complete maps
p_map = np.power(10.0, -log_p_map)
# Convert p to z, preserving signs
sign = np.sign(t_map)
sign[sign == 0] = 1
z_map = p_to_z(p_map, tail="two") * sign
images = {
"logp_level-voxel": _boolean_unmask(
log_p_map.squeeze(), self.inputs_["aggressive_mask"]
),
"z_level-voxel": _boolean_unmask(z_map.squeeze(), self.inputs_["aggressive_mask"]),
}
return images