def test_fdr(): n = 100 x = np.linspace(.5 / n, 1. - .5 / n, n) x[:10] = .0005 x = norm.isf(x) np.random.shuffle(x) assert_almost_equal(fdr_threshold(x, .1), norm.isf(.0005)) assert_true(fdr_threshold(x, .001) == np.infty)
def test_fdr(): n = 100 x = np.linspace(.5 / n, 1. - .5 / n, n) x[:10] = .0005 x = norm.isf(x) np.random.shuffle(x) assert_almost_equal(fdr_threshold(x, .1), norm.isf(.0005)) assert fdr_threshold(x, .001) == np.infty with pytest.raises(ValueError): fdr_threshold(x, -.1) with pytest.raises(ValueError): fdr_threshold(x, 1.5)
labels, res = run_glm(texture.T, design_matrix.values[:texture.shape[1]]) ####################################################################### # contrast estimation for index, (contrast_id, contrast_val) in enumerate(contrasts.items()): print(' Contrast % 2i out of %i: %s' % (index + 1, len(contrasts), contrast_id)) if subject_idx == 0: effects[contrast_id] = [] contrast_ = compute_contrast(labels, res, contrast_val) z_map = contrast_.z_score() effect = contrast_.effect effects[contrast_id].append(effect) # Create snapshots of the contrasts threshold = fdr_threshold(z_map, alpha=.05) out_file = os.path.join( write_dir, '%s_%s_z_map.png' % (contrast_id, hemisphere)) plotting.plot_surf_stat_map(fsaverage['infl_%s' % hemisphere], z_map, hemi=hemisphere, title=contrast_id, colorbar=True, output_file=out_file, threshold=threshold, bg_map=fsaverage['sulc_%s' % hemisphere]) import pandas as pd n_subjects = len(subjects) group_design_matrix = pd.DataFrame([1] * n_subjects, columns=['intercept'])
def threshold_and_save(img, masker): data = masker.transform(img) thr = fdr_threshold(data, 0.05) data[np.abs(data) <= thr] = 0 thr_img = masker.inverse_transform(data) thr_img.to_filename(img.replace('.nii.gz', '_thr.nii.gz'))