def test_z_score(): p = np.random.rand(10) assert_array_almost_equal(norm.sf(z_score(p)), p) # check the numerical precision for p in [1.e-250, 1 - 1.e-16]: assert_array_almost_equal(z_score(p), norm.isf(p)) assert_array_almost_equal(z_score(np.float32(1.e-100)), norm.isf(1.e-300))
def print_images1(files, masker, mask_array, curr_work_folder, coords): """Convert NIfTI files to images""" for file in files: pdata = nib.load(os.path.join(curr_work_folder, file)).get_data() pvals = pdata[mask_array > 0] z_map = masker.inverse_transform(z_score(np.power(10, -np.abs(pvals)))) threshold1 = fdr_threshold(np.power(10, -np.abs(pvals)), 0.05) thresholded_map2, threshold2 = map_threshold(z_map, threshold=.05, height_control='fdr') print(file, threshold1, threshold2) # According to internet plotting.plot_stat_map(thresholded_map2, threshold=threshold2, cut_coords=coords, title='Thresholded z map, expected fdr = .05', output_file=os.path.join( curr_work_folder, os.path.splitext(file)[0] + '_01')) # Flop plotting.plot_stat_map(os.path.join(working_folder, file), threshold=threshold1, cut_coords=coords, title='Thresholded z map, expected fdr = .05', output_file=os.path.join( curr_work_folder, os.path.splitext(file)[0] + '_02')) # Does this make sense plotting.plot_stat_map(thresholded_map2, threshold=threshold1, cut_coords=coords, title='Thresholded z map, expected fdr = .05', output_file=os.path.join( curr_work_folder, os.path.splitext(file)[0] + '_03')) # plotting.plot_stat_map(os.path.join(working_folder, file), threshold=threshold2, cut_coords=coords, title='Thresholded z map, expected fdr = .05', output_file=os.path.join( curr_work_folder, os.path.splitext(file)[0] + '_04'))
memory='nilearn_cache', memory_level=1) # cache options cmap_filenames = localizer_dataset.cmaps fmri_masked = nifti_masker.fit_transform(cmap_filenames) ######################################################################### # Perform the second level analysis # ---------------------------------- # perform a one-sample test on these values from scipy.stats import ttest_1samp _, p_values = ttest_1samp(fmri_masked, 0) ######################################################################### # z-transform of p-values from nistats.utils import z_score z_map = nifti_masker.inverse_transform(z_score(p_values)) ######################################################################### # Threshold the resulting map: # false positive rate < .001, cluster size > 10 voxels from nistats.thresholding import map_threshold thresholded_map1, threshold1 = map_threshold(z_map, threshold=.001, height_control='fpr', cluster_threshold=10) ######################################################################### # Now use FDR <.05, no cluster-level threshold thresholded_map2, threshold2 = map_threshold(z_map, threshold=.05, height_control='fdr')
n_subjects=n_samples) # mask data nifti_masker = NiftiMasker( smoothing_fwhm=5, memory='nilearn_cache', memory_level=1) # cache options cmap_filenames = localizer_dataset.cmaps fmri_masked = nifti_masker.fit_transform(cmap_filenames) # perform a one-sample test on these values from scipy.stats import ttest_1samp _, p_values = ttest_1samp(fmri_masked, 0) # z-transform of p-values from nistats.utils import z_score z_map = nifti_masker.inverse_transform(z_score(p_values)) # Threshold the resulting map: # false positive rate < .001, cluster size > 10 voxels from nistats.thresholding import map_threshold thresholded_map1, threshold1 = map_threshold( z_map, threshold=.001, height_control='fpr', cluster_threshold=10) # Now use FDR <.05, no cluster-level threshold thresholded_map2, threshold2 = map_threshold( z_map, threshold=.05, height_control='fdr') # Visualization from nilearn import plotting display = plotting.plot_stat_map(z_map, title='Raw z map') plotting.plot_stat_map(