Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_required_inputs = {
'z_maps': ('image', 'z'),
'sample_sizes': ('metadata', 'sample_sizes')
}
def __init__(self, two_sided=True, *args, **kwargs):
super().__init__(*args, **kwargs)
self.two_sided = two_sided
def _fit(self, dataset):
z_maps = self.inputs_['z_maps']
sample_sizes = np.array([np.mean(n) for n in self.inputs_['sample_sizes']])
return weighted_stouffers(z_maps, sample_sizes, two_sided=self.two_sided)
class RFX_GLM(IBMAEstimator):
"""
A t-test on contrast images. Requires contrast images.
Parameters
----------
null : {'theoretical', 'empirical'}, optional
Whether to use a theoretical null T distribution or an empirically-
derived null distribution determined via sign flipping.
Default is 'theoretical'.
n_iters : :obj:`int` or :obj:`None`, optional
The number of iterations to run in estimating the null distribution.
Only used if ``null = 'empirical'``.
two_sided : :obj:`bool`, optional
Whether to do a two- or one-sided test. Default is True.
"""
_required_inputs = {
-----
Sum of -log P-values (from T/Zs converted to Ps)
"""
_required_inputs = {
'z_maps': ('image', 'z')
}
def __init__(self, two_sided=True, *args, **kwargs):
super().__init__(*args, **kwargs)
self.two_sided = two_sided
def _fit(self, dataset):
return fishers(self.inputs_['z_maps'], two_sided=self.two_sided)
class Stouffers(IBMAEstimator):
"""
A t-test on z-statistic images. Requires z-statistic images.
Parameters
----------
inference : {'ffx', 'rfx'}, optional
Whether to use fixed-effects inference (default) or random-effects
inference.
null : {'theoretical', 'empirical'}, optional
Whether to use a theoretical null T distribution or an empirically-
derived null distribution determined via sign flipping. Empirical null
is only possible if ``inference = 'rfx'``.
n_iters : :obj:`int` or :obj:`None`, optional
The number of iterations to run in estimating the null distribution.
Only used if ``inference = 'rfx'`` and ``null = 'empirical'``.
two_sided : :obj:`bool`, optional
def __init__(self, inference='ffx', null='theoretical', n_iters=None,
two_sided=True, *args, **kwargs):
super().__init__(*args, **kwargs)
self.inference = inference
self.null = null
self.n_iters = n_iters
self.two_sided = two_sided
def _fit(self, dataset):
return stouffers(self.inputs_['z_maps'], inference=self.inference,
null=self.null, n_iters=self.n_iters,
two_sided=self.two_sided)
class WeightedStouffers(IBMAEstimator):
"""
An image-based meta-analytic test using z-statistic images and
sample sizes. Zs from bigger studies get bigger weights.
Parameters
----------
two_sided : :obj:`bool`, optional
Whether to do a two- or one-sided test. Default is True.
"""
_required_inputs = {
'z_maps': ('image', 'z'),
'sample_sizes': ('metadata', 'sample_sizes')
}
def __init__(self, two_sided=True, *args, **kwargs):
super().__init__(*args, **kwargs)
def __init__(self, *args, **kwargs):
mask = kwargs.get('mask')
if mask is not None:
mask = get_masker(mask)
self.masker = mask
def _preprocess_input(self, dataset):
""" Mask required input images using either the dataset's mask or the
estimator's. """
masker = self.masker or dataset.masker
for name, (type_, _) in self._required_inputs.items():
if type_ == 'image':
self.inputs_[name] = masker.transform(self.inputs_[name])
class Fishers(IBMAEstimator):
"""
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.
Parameters
----------
two_sided : :obj:`bool`, optional
Whether to do a two- or one-sided test. Default is True.
Notes
-----
Sum of -log P-values (from T/Zs converted to Ps)
"""
_required_inputs = {
'z_maps': ('image', 'z')
Working directory for FSL flameo outputs.
two_sided : :obj:`bool`, optional
Whether analysis should be two-sided (True) or one-sided (False).
Returns
-------
result : :obj:`dict`
Dictionary containing maps for test statistics, p-values, and
negative log(p) values.
"""
result = fsl_glm(con_maps, se_maps, sample_sizes, mask, inference='mfx',
cdt=cdt, q=q, work_dir=work_dir, two_sided=two_sided)
return result
class MFX_GLM(IBMAEstimator):
"""
The gold standard image-based meta-analytic test. Uses contrast and
standard error images.
Parameters
----------
cdt : :obj:`float`, optional
Cluster-defining p-value threshold.
q : :obj:`float`, optional
Alpha for multiple comparisons correction.
two_sided : :obj:`bool`, optional
Whether analysis should be two-sided (True) or one-sided (False).
"""
_required_inputs = {
'con_maps': ('image', 'con'),
'se_maps': ('image', 'se'),
Working directory for FSL flameo outputs.
two_sided : :obj:`bool`, optional
Whether analysis should be two-sided (True) or one-sided (False).
Returns
-------
result : :obj:`dict`
Dictionary containing maps for test statistics, p-values, and
negative log(p) values.
"""
result = fsl_glm(con_maps, se_maps, sample_sizes, mask, inference='ffx',
cdt=cdt, q=q, work_dir=work_dir, two_sided=two_sided)
return result
class FFX_GLM(IBMAEstimator):
"""
An image-based meta-analytic test using contrast and standard error images.
Don't estimate variance, just take from first level.
Parameters
----------
cdt : :obj:`float`, optional
Cluster-defining p-value threshold.
q : :obj:`float`, optional
Alpha for multiple comparisons correction.
two_sided : :obj:`bool`, optional
Whether analysis should be two-sided (True) or one-sided (False).
"""
_required_inputs = {
'con_maps': ('image', 'con'),
'se_maps': ('image', 'se'),