From 8fc8030b915f5efee39ed6634e8f2946cd050bef Mon Sep 17 00:00:00 2001 From: JulioAPeraza Date: Tue, 28 May 2024 14:52:27 -0700 Subject: [PATCH] Rename variables --- nimare/meta/ibma.py | 36 ++++++++++++++++++++-------------- nimare/reports/base.py | 2 +- nimare/tests/test_meta_ibma.py | 12 ++++++------ 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/nimare/meta/ibma.py b/nimare/meta/ibma.py index cba3d5824..4d19aa969 100755 --- a/nimare/meta/ibma.py +++ b/nimare/meta/ibma.py @@ -302,7 +302,8 @@ class Stouffers(IBMAEstimator): the default is now set to True (two-sided), which differs from previous versions where only one-sided tests were performed. * Add correction for multiple contrasts within a study. - * New parameter: ``use_group_size`` to use publication group sizes for weights. + * New parameter: ``normalize_contrast_weights`` to normalized the weights by the + number of contrasts in each study. .. versionchanged:: 0.2.1 @@ -320,8 +321,8 @@ class Stouffers(IBMAEstimator): Whether to use sample sizes for weights (i.e., "weighted Stouffer's") or not, as described in :footcite:t:`zaykin2011optimally`. Default is False. - use_group_size : :obj:`bool`, optional - Whether to use publication group sizes for weights or not. + normalize_contrast_weights : :obj:`bool`, optional + Whether to use number of contrast per study to normalized the weights or not. Default is False. two_sided : :obj:`bool`, optional If True, performs an unsigned t-test. Both positive and negative effects are considered; @@ -364,13 +365,19 @@ class Stouffers(IBMAEstimator): _required_inputs = {"z_maps": ("image", "z")} - def __init__(self, use_sample_size=False, use_group_size=False, two_sided=True, **kwargs): + def __init__( + self, + use_sample_size=False, + normalize_contrast_weights=False, + two_sided=True, + **kwargs, + ): super().__init__(**kwargs) self.use_sample_size = use_sample_size if self.use_sample_size: self._required_inputs["sample_sizes"] = ("metadata", "sample_sizes") - self.use_group_size = use_group_size + self.normalize_contrast_weights = normalize_contrast_weights self.two_sided = two_sided self._mode = "concordant" if self.two_sided else "directed" @@ -380,15 +387,14 @@ def _preprocess_input(self, dataset): super()._preprocess_input(dataset) study_mask = dataset.images["id"].isin(self.inputs_["id"]) - # self.inputs_["study_mask"] = np.where(study_mask)[0] - # Convert each group to a unique integer value. + # Convert each contrast name to a unique integer value. labels = dataset.images["study_id"][study_mask].to_list() label_to_int = {label: i for i, label in enumerate(set(labels))} label_counts = Counter(labels) - self.inputs_["groups"] = np.array([label_to_int[label] for label in labels]) - self.inputs_["group_counts"] = np.array([label_counts[label] for label in labels]) + self.inputs_["contrast_names"] = np.array([label_to_int[label] for label in labels]) + self.inputs_["num_contrasts"] = np.array([label_counts[label] for label in labels]) def _generate_description(self): description = ( @@ -419,15 +425,15 @@ def _fit_model(self, stat_maps, study_mask=None, corr=None): est = pymare.estimators.StoufferCombinationTest(mode=self._mode) - group_maps, sub_corr = None, None + contrast_maps, sub_corr = None, None if corr is not None: - group_maps = np.tile(self.inputs_["groups"][study_mask], (n_voxels, 1)).T + contrast_maps = np.tile(self.inputs_["contrast_names"][study_mask], (n_voxels, 1)).T sub_corr = corr[np.ix_(study_mask, study_mask)] weights = np.ones(n_studies) - if self.use_group_size: - weights *= 1 / self.inputs_["group_counts"][study_mask] + if self.normalize_contrast_weights: + weights *= 1 / self.inputs_["num_contrasts"][study_mask] if self.use_sample_size: sample_sizes = np.array( @@ -437,7 +443,7 @@ def _fit_model(self, stat_maps, study_mask=None, corr=None): weight_maps = np.tile(weights, (n_voxels, 1)).T - pymare_dset = pymare.Dataset(y=stat_maps, n=weight_maps, v=group_maps) + pymare_dset = pymare.Dataset(y=stat_maps, n=weight_maps, v=contrast_maps) est.fit_dataset(pymare_dset, corr=sub_corr) est_summary = est.summary() @@ -459,7 +465,7 @@ def _fit(self, dataset): ) corr = None - if self.inputs_["groups"].size != np.unique(self.inputs_["groups"]).size: + if self.inputs_["contrast_names"].size != np.unique(self.inputs_["contrast_names"]).size: # If all studies are not unique, we will need to correct for multiple contrasts corr = np.corrcoef(self.inputs_["z_maps"], rowvar=True) diff --git a/nimare/reports/base.py b/nimare/reports/base.py index f149266ae..a4e6fc139 100644 --- a/nimare/reports/base.py +++ b/nimare/reports/base.py @@ -66,7 +66,7 @@ "alpha": "Alpha", "prior": "Prior", "use_sample_size": "Use sample size for weights", - "use_group_size": "Use group size for weights", + "normalize_contrast_weights": "Normalize by the number of contrasts", "two_sided": "Two-sided test", "beta": "Parameter estimate", "se": "Standard error of the parameter estimate", diff --git a/nimare/tests/test_meta_ibma.py b/nimare/tests/test_meta_ibma.py index 9a4e961da..8f41d630a 100644 --- a/nimare/tests/test_meta_ibma.py +++ b/nimare/tests/test_meta_ibma.py @@ -26,7 +26,7 @@ ), pytest.param( ibma.Stouffers, - {"use_sample_size": False, "use_group_size": False}, + {"use_sample_size": False, "normalize_contrast_weights": False}, None, {}, ("z", "p", "dof"), @@ -34,7 +34,7 @@ ), pytest.param( ibma.Stouffers, - {"use_sample_size": True, "use_group_size": False}, + {"use_sample_size": True, "normalize_contrast_weights": False}, None, {}, ("z", "p", "dof"), @@ -42,19 +42,19 @@ ), pytest.param( ibma.Stouffers, - {"use_sample_size": False, "use_group_size": True}, + {"use_sample_size": False, "normalize_contrast_weights": True}, None, {}, ("z", "p", "dof"), - id="Stouffers_group_weighted", + id="Stouffers_contrast_weighted", ), pytest.param( ibma.Stouffers, - {"use_sample_size": True, "use_group_size": True}, + {"use_sample_size": True, "normalize_contrast_weights": True}, None, {}, ("z", "p", "dof"), - id="Stouffers_sample_group_weighted", + id="Stouffers_sample_contrast_weighted", ), pytest.param( ibma.WeightedLeastSquares,