Esempio n. 1
0
"""
~/git/scripts/brainomics/image_clusters_analysis_nilearn.py li~1+age+sex_tstat1.nii.gz -o li~1+age+sex_tstat1 --thresh_neg_low 0 --thresh_neg_high 0 --thresh_pos_low 3 --thresh_size 10
"""
###############################################################################
## OLDIES

muols = MUOLS(Y=X,X=DesignMat)
muols.fit()
print('launching the t_test')
tvals, pvals_ttest, df1 = muols.t_test(contrasts=[1, 0, 0], pval=True)
#%time tvals, pvals_ttest, df1 = muols.t_test(contrasts=[1, 0, 0], pval=True)
print('t_test done')
print('launching maxT test')
#tvals2, pvals_maxT, df2 = muols.t_test_maxT(contrasts=np.array([1, 0, 0]), nperms=1000, two_tailed=False)
#print('maxT test done')
tvals, pvals_maxT, df3 = muols.t_test_maxT(contrasts=np.array([1, 0, 0]), nperms=1000, two_tailed=True)
#♣tvals3, minP, df3 = muols.t_test_minP(contrasts=np.array([1, 0, 0]), nperms=5, two_tailed=True)
mhist, bins, patches= plt.hist([pvals_ttest[0,:],pvals_maxT[0,:]],
                           color=['blue','red'],
                           label=['pvals_ttest','pvals_maxT'])

mycoefs=np.zeros(mask_arr.shape)
mycoefs[mask_arr]=muols.coef[0,:]

##Wilcoxon Test
# Buisness Volume time 0
bv0 = np.random.normal(loc=3, scale=.1, size=n)
# Buisness Volume time 1
bv1 = bv0 + 0.1 + np.random.normal(loc=0, scale=.1, size=n)
# create an outlier
bv1[0] -= 10
Esempio n. 2
0
                                   beta_path=os.path.join(
                                       OUTPUT, "tvals", "tvals.npz"),
                                   penalty_start=3,
                                   threshold=False)

create_texture.create_texture_file(OUTPUT=os.path.join(OUTPUT, "log10pvals"),
                                   TEMPLATE_PATH=TEMPLATE_PATH,
                                   MASK_PATH=MASK_PATH,
                                   beta_path=os.path.join(
                                       OUTPUT, "log10pvals", "log10pvals.npz"),
                                   penalty_start=3,
                                   threshold=False)

nperms = 1000
tvals_perm, pvals_perm, _ = muols.t_test_maxT(contrasts=np.array([[1, 0, 0,
                                                                   0]]),
                                              nperms=nperms,
                                              two_tailed=True)
np.savez(os.path.join(OUTPUT, "pvals_corr", "pvals_corrected_perm.npz"),
         pvals_perm[0])

create_texture.create_texture_file(OUTPUT=os.path.join(OUTPUT, "pvals_corr"),
                                   TEMPLATE_PATH=TEMPLATE_PATH,
                                   MASK_PATH=MASK_PATH,
                                   beta_path=os.path.join(
                                       OUTPUT, "pvals_corr",
                                       "pvals_corrected_perm.npz"),
                                   penalty_start=3,
                                   threshold=False)

#########################
Esempio n. 3
0
print "ok univariate analysis"
###########################################
#### Univariate Analysis with permutations
##########################################
#
##Univariate analysis with empirical pvalues corrected by permutations
## Permutation procedure to correct the pvalue: maxT
#
nperms = 100
#################################
# Correctied pvalue for the brain
muols = MUOLS(Y=X, X=DesignMat)
muols.fit(block=True)
print "ok fit permutations"
tvals, pvals_perm, _ = muols.t_test_maxT(contrasts=contrasts,
                                         nperms=nperms,
                                         two_tailed=True)
print "ok maxT test permutations"
arr = np.zeros(mask_arr.shape)
arr[mask_arr] = tvals[0]
out_im = nib.Nifti1Image(arr, affine=mask_ima.get_affine())
out_im.to_filename(os.path.join(OUTPUT_UNIVARIATE, "tstat_adrs.nii.gz"))

arr = np.zeros(mask_arr.shape)
arr[mask_arr] = pvals_perm[0]
out_im = nib.Nifti1Image(arr, affine=mask_ima.get_affine())
out_im.to_filename(os.path.join(OUTPUT_UNIVARIATE, "ptmax_adrs.nii.gz"))

log10_pvals_perm = -np.log10(pvals_perm)
arr = np.zeros(mask_arr.shape)
arr[mask_arr] = log10_pvals_perm[0]