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 _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
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
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
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
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
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 = _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