Skip to content

Commit

Permalink
Retain updated Estimator in Corrector-generated MetaResults (#633)
Browse files Browse the repository at this point in the history
* Retain updated Estimator in corrected MetaResult.

* Update test.

* Update the test again.

* Fix the problem.
  • Loading branch information
tsalo authored Feb 11, 2022
1 parent 0c67c5e commit c35ca9b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
8 changes: 7 additions & 1 deletion nimare/correct.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,14 @@ def transform(self, result):
result : :obj:`~nimare.results.MetaResult`
MetaResult with new corrected maps added.
"""
est = result.estimator
correction_method = f"correct_{self._correction_method}_{self.method}"

# Make sure we return a copy of the MetaResult
result = result.copy()

# Also operate on a copy of the estimator
est = result.estimator

# If a correction method with the same name exists in the current
# MetaEstimator, use it. Otherwise fall back on _transform.
if correction_method is not None and hasattr(est, correction_method):
Expand All @@ -136,6 +138,10 @@ def transform(self, result):
# Update corrected map names and add them to maps dict
corr_maps = {(k + self._name_suffix): v for k, v in corr_maps.items()}
result.maps.update(corr_maps)

# Update the estimator as well, in order to retain updated null distributions
result.estimator = est

return result

@abstractmethod
Expand Down
20 changes: 20 additions & 0 deletions nimare/tests/test_meta_ale.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,26 @@ def test_ALE_montecarlo_null_unit(testdata_cbma, tmp_path_factory):
np.ndarray,
)

# Check that the updated null distribution is in the corrected MetaResult's Estimator.
assert (
"values_desc-mass_level-cluster_corr-fwe_method-montecarlo"
in cres.estimator.null_distributions_.keys()
)
# The updated null distribution should *not* be in the original Estimator, nor in the
# uncorrected MetaResult's Estimator.
assert (
"values_desc-mass_level-cluster_corr-fwe_method-montecarlo"
not in meta.null_distributions_.keys()
)
assert (
"values_desc-mass_level-cluster_corr-fwe_method-montecarlo"
not in res.estimator.null_distributions_.keys()
)
assert (
"values_desc-mass_level-cluster_corr-fwe_method-montecarlo"
not in meta.results.estimator.null_distributions_.keys()
)

# Bonferroni FWE
corr = FWECorrector(method="bonferroni")
cres = corr.transform(res)
Expand Down

0 comments on commit c35ca9b

Please sign in to comment.