In [1]:
    
%matplotlib inline
main_path = '../../../Dropbox/McGill-publication/Papers/Multisite/'
path_out = main_path + 'figures/'
    
In [2]:
    
from matplotlib.pylab import *
import matplotlib.pyplot as plt
import numpy as np
import scipy.io
from mpl_toolkits.axes_grid1 import ImageGrid
import matplotlib.gridspec as gridspec
def errorfill(x, y, yerr, color=None, alpha_fill=0.3, ax=None, label=''):
    ax = ax if ax is not None else plt.gca()
    if color is None:
        color = ax._get_lines.color_cycle.next()
    if np.isscalar(yerr) or len(yerr) == len(y):
        ymin = y - yerr
        ymax = y + yerr
    elif len(yerr) == 2:
        ymin, ymax = yerr
    ax.plot(x, y, color=color, label=label, lw=2)
    ax.fill_between(x, ymax, ymin, color=color, alpha=alpha_fill)
    
def load_file(path):
    mat = scipy.io.loadmat(path)
    return mat
def gen_fig(path_in, file_in,path_out, file_out, conn = 0, pvalidx=0):
    labels_box = ['H0 multi','H0 Dummy', 'H0 METAL']
    lw = 2
    mat = load_file(path_in + file_in)
    pvals = mat.get('list_p')[0]
    fig = plt.figure(figsize=(8, 4))
    sns.set_context('paper',font_scale=1.7)
    plt.subplot(1, 2, 1)
    #ax.set_xticks(np.arange(0,1,0.1))
    #ax.set_yticks(np.arange(0,1.,0.1))
    plt.xlim(0,1.5)
    effect_size = np.arange(0.0, 1.501, 0.01)
    plt.ylabel('Detection power')
    plt.xlabel('Effect size (Cohen\'s ' + r'$d$)')
    plt.plot(effect_size, mat.get('sens_monosite')[pvalidx,:,conn],label="Monosite", lw=lw, c='r')
    #plt.plot(effect_size, mat.get('sens_multisite_nocorr')[pvalidx,:,conn],label="Multisite no correction",lw=lw, c='k')
    plt.plot(effect_size, mat.get('sens_multisite_dummyvar')[pvalidx,:,conn],label="Multisite (7 sites)",lw=lw, c='b')
    #plt.plot(effect_size, mat.get('sens_multisite_metal')[pvalidx,:,conn],label="Multisite METAL",lw=lw, c='m')
    plt.grid(True)
    plt.title('p-value ' +  str(pvals[pvalidx]))
    
    # fully use the given bounding box.
    #plt.legend(bbox_to_anchor=(1.05, 1), loc=4, mode="expand", borderaxespad=0.)
    plt.legend( bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0., frameon=False)
    # do the box plot
    plt.subplot(2, 2, 4)
    ax = fig.gca()
    #xtickNames = plt.setp(ax, xticklabels=np.repeat(labels_box, 1))
    #plt.setp(xtickNames, rotation=45, fontsize=12)
    plt.xlabel(r'Effect size (Cohen\'s $d$)')
    #h0_metal =  mat.get('sens_multisite_h0_metal')[pvalidx,:,conn]
    #h0_multi  = mat.get('sens_multisite_h0')[pvalidx,:,conn]
    h0_dummy  = np.mean(mat.get('sens_multisite_h0_dummy')[pvalidx,:,conn],axis=0)
    #boxplot((h0_multi,h0_dummy,h0_metal))
    boxplot((h0_dummy))
    ax.set_xticklabels(labels_box, rotation=0, ha='center')
    ax.set_yscale('log')
    ax.set_ylim((10**(-3),10**(0)))
    plt.ylabel('Detection power (log)')
    plt.title('H0 hypotheses')
    plt.tight_layout()
    #plt.savefig(path_out + file_out)
    #plt.show()
def gen_fig_allconn(path_in, file_in, path_out, file_out, conn=0, pvalidx=0, efflim=1.5,nsites=7):
    labels_box = ['H0 multi','H0 Dummy', 'H0 METAL']
    lw = 2
    mat = load_file(path_in + file_in)
    pvals = mat.get('list_p')[0]
    
    fig = plt.figure(figsize=(5,5))
    sns.set_context('paper',font_scale=1.7)
    plt.subplot2grid((5,2), (1,0),colspan=2,rowspan=4)
    ax = fig.gca()
    #ax.set_xticks(np.arange(0,1,0.1))
    #ax.set_yticks(np.arange(0,1.,0.1))
    if efflim==2:
        plt.xlim(0,2)
        effect_size = np.arange(0.0, 2.001, 0.01)
    else:
        plt.xlim(0,1.5)
        effect_size = np.arange(0.0, 1.501, 0.01)
    
    plt.ylabel('Detection power')
    plt.xlabel('Effect size (Cohen\'s ' + r'$d$)')
    ax.set_ylim((0,1))
    tmpdata = mat.get('sens_monosite')[pvalidx,:,:]
    errorfill(effect_size, tmpdata.mean(axis=1)[:len(effect_size)],tmpdata.std(axis=1)[:len(effect_size)],label="Monosite", color='r')
    #tmpdata = mat.get('sens_multisite_nocorr')[pvalidx,:,:]
    #errorfill(effect_size, tmpdata.mean(axis=1),tmpdata.std(axis=1),label="Multisite no correction", color='k')
    tmpdata = mat.get('sens_multisite_dummyvar')[pvalidx,:,:]
    errorfill(effect_size, tmpdata.mean(axis=1)[:len(effect_size)],tmpdata.std(axis=1)[:len(effect_size)],label="Multisite ("+str(nsites)+" sites)", color='b')
    #tmpdata = mat.get('sens_multisite_metal')[pvalidx,:,:]
    #errorfill(effect_size, tmpdata.mean(axis=1),tmpdata.std(axis=1),label="Multisite METAL", color='m')
    
    plt.grid(True)
    plt.title(r'False-positive rate $\alpha=$' +  str(pvals[pvalidx]))
    
    # fully use the given bounding box.
    plt.legend(bbox_to_anchor=(0., 1.10, 1., .102), loc=3, ncol=2, mode="expand", borderaxespad=0.,frameon=False)
    #plt.legend( bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0., frameon=False)
    # do the box plot
    #plt.subplot2grid((7,2), (5,0),colspan=2,rowspan=2)
    #ax = fig.gca()
    ##xtickNames = plt.setp(ax, xticklabels=np.repeat(labels_box, 1))
    ##plt.setp(xtickNames, rotation=45, fontsize=12)
    #plt.xlabel('Effect size (cohen\'s d)')
    #h0_metal =  np.ndarray.flatten(np.mean(mat.get('sens_multisite_h0_metal')[pvalidx,:,:],axis=0))
    #h0_multi  = np.ndarray.flatten(np.mean(mat.get('sens_multisite_h0')[pvalidx,:,:],axis=0))
    #h0_dummy  = np.ndarray.flatten(np.mean(mat.get('sens_multisite_h0_dummy')[pvalidx,:,:],axis=0))
    ##boxplot((h0_multi,h0_dummy,h0_metal))
    #boxplot((h0_dummy))
    #ax.set_xticklabels(labels_box, rotation=0, ha='center')
    #ax.set_yscale('log')
    #ax.set_ylim((10**(-5),10**(0)))
    #plt.ylabel('Detection power (log)')
    #plt.title('H0 hypotheses')
    #plt.grid(True)
    print('monosite h0: ',np.mean(mat.get('sens_monosite_h0')[pvalidx,:,:]))
    plt.tight_layout()
    plt.savefig(path_out + file_out,dpi=150)
    
def gen_fig_full_sim(path_in, file_in,path_out, file_out):
    labels_box = ['H0 multi','H0 Dummy', 'H0 METAL']
    lw = 2
    mat = load_file(path_in + file_in)
    pvals = 0.001
    #fig = plt.figure(figsize=(5.5,7))
    fig = plt.figure(figsize=(5,5))
    sns.set_context('paper',font_scale=1.7)
    plt.subplot2grid((5,2), (1,0),colspan=2,rowspan=4)
    ax = fig.gca()
    plt.xlim(0,1.5)
    effect_size = np.arange(0.0, 1.501, 0.01)
    ax.set_ylim((0,1))
    plt.ylabel('Detection power')
    plt.xlabel('Effect size (Cohen\'s ' + r'$d$)')
    plt.plot(effect_size, mat.get('sens_mono'),label="Monosite",lw=lw, color='r')
    #plt.plot(effect_size, mat.get('sens_multi'),label="Multisite no correction",lw=lw, c='k')
    plt.plot(effect_size, mat.get('sens_multi_dummy'),label="Multisite (7 sites)",lw=lw, c='b')
    #plt.plot(effect_size, mat.get('sens_multi_metal'),label="Multisite METAL",lw=lw, c='m')
    plt.grid(True)
    plt.title(r'False-positive rate $\alpha=$' +  str(pvals))
    
    # fully use the given bounding box.
    plt.legend(bbox_to_anchor=(0., 1.10, 1., .102), loc=3, ncol=2, mode="expand", borderaxespad=0.,frameon=False)
    ##plt.legend( bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0., frameon=False)
    ## do the box plot
    #plt.subplot2grid((7,2), (5,0),colspan=2,rowspan=2)
    #ax = plt.gca()
    ##ax = fig.gca()
    ##xtickNames = plt.setp(ax, xticklabels=np.repeat(labels_box, 1))
    ##plt.setp(xtickNames, rotation=45, fontsize=12)
    #plt.xlabel('Effect size (cohen\'s d)')
    ##h0_metal =  np.mean(mat.get('sens_multi_h0_metal'),axis=0)
    ##h0_multi  = np.mean(mat.get('sens_multi_h0'),axis=0)
    ##h0_dummy  = np.mean(mat.get('sens_multi_h0_dummy'),axis=0)
    ##boxplot((h0_multi,h0_dummy,h0_metal))
    #boxplot((h0_dummy))
    #ax.set_xticklabels(labels_box, rotation=0, ha='center')
    #ax.set_yscale('log')
    #ax.set_ylim((10**(-5),10**(0)))
    #plt.ylabel('Detection power (log)')
    #plt.title('H0 hypotheses')
    #plt.grid(True)
    print('monosite h0: ',np.mean(mat.get('sens_monosite_h0'),axis=0))
    plt.tight_layout()
    plt.savefig(path_out + file_out,dpi=150)
    ##plt.show()
    
def geteffectsize(path_in, file_in,mono=True,pidx=0):
    point_list = []
    mat = load_file(path_in + file_in)
    pvals = mat.get('list_p')[0]
    #print pvals
    if mono:
        pow_mask = mat.get('sens_monosite')[pidx]>=0.8 
    else:
        pow_mask = mat.get('sens_multisite_dummyvar')[pidx]>=0.8 
    
    for i in range(pow_mask.shape[1]):
        #print np.where(pow_mask[:,i])[0][0]
        point_list.append(mat.get('list_effect_size')[0][np.where(pow_mask[:,i])[0][0]])
    
    return np.mean(point_list),np.std(point_list)
#sens_monosite 
#sens_multisite_dummyvar
    
In [3]:
    
from scipy.interpolate import interp1d
import statsmodels.stats.power as pow
import pandas as pan
import math as math
plt.figure()
x = np.linspace(0, 2 * np.pi)
y_sin = np.sin(x)
y_cos = np.cos(x)
print(x.shape,y_cos.shape)
errorfill(x, y_sin, 0.5,'y')
errorfill(x, y_cos, 0.2,'c')
a = np.array([[1,2], [3,4]])
print a
print np.ndarray.flatten(a)
    
    
    
In [5]:
    
import seaborn; seaborn.set()
import seaborn as sns
sns.set_style("whitegrid")
sns.set_color_codes("muted")
 
path_tmp = main_path + 'figures/default_sim/samps_s40_50pct/'
m1,s1 = geteffectsize(path_tmp,'results_simu_power.mat',True)
path_tmp = main_path + 'figures/default_sim/samps_s80_50pct/'
m2,s2 = geteffectsize(path_tmp,'results_simu_power.mat',True) 
path_tmp = main_path + 'figures/default_sim/samps_s120_50pct/'
m3,s3 = geteffectsize(path_tmp,'results_simu_power.mat',True) 
path_tmp = main_path + 'figures/default_sim/samps_s40_50pct/'
mm1,sm1 = geteffectsize(path_tmp,'results_simu_power.mat',False) 
path_tmp = main_path + 'figures/default_sim/samps_s80_50pct/'
mm2,sm2 = geteffectsize(path_tmp,'results_simu_power.mat',False) 
path_tmp = main_path + 'figures/default_sim/samps_s120_50pct/'
mm3,sm3 = geteffectsize(path_tmp,'results_simu_power.mat',False)
yref=[]
x = np.linspace(40, 120, 3)
y = np.array([m1,m2,m3])
y2 = np.array([mm1,mm2,mm3])
f1 = interp1d(x, y, kind='linear')
f2 = interp1d(x, y2, kind='linear')
xnew = np.linspace(40, 120, 40)
for i in xnew:
    yref.append((pow.TTestIndPower().solve_power(nobs1=i/2, power=0.8, ratio=1, alpha=0.001)))
yref  = np.array(yref)
plt.figure(figsize=(6,6))
sns.set_context('paper',font_scale=1.8)
plt.plot(xnew,yref,'k--',lw=2)
#plt.scatter(x,y,c="r",s=50)
#plt.scatter(x[1:],y2,c="b",s=50)
plt.errorbar(x, y, yerr=[s1,s2,s3], fmt='rD')
plt.errorbar(x, y2, yerr=[sm1,sm2,sm3], fmt='bD')
plt.legend(['parametric','monosite','multisite (7 sites)'],bbox_to_anchor=(0., 1.05, 1., .002),handletextpad=0.01, loc=3, ncol=3, mode="expand",borderaxespad=0.,frameon=False)
plt.xlabel('Total # subjects')
plt.ylabel('Effect size (Cohen\'s ' + r'$d$)')
plt.grid(True)
axes = plt.gca()
axes.set_xlim([20,140])
axes.set_ylim([0,1.8])
plt.title(r'False-positive rate $\alpha=0.001$')
plt.savefig(path_out + 'samplesize_effectsize_pow80_alpha001.png',dpi=150)
    
    
In [4]:
    
import seaborn; seaborn.set()
import seaborn as sns
sns.set_style("whitegrid")
sns.set_color_codes("muted")
 
mat = load_file(main_path + 'figures/default_sim/samps_s120_15pct/results_simu_power.mat')
    
    
In [86]:
    
ls ../../../Dropbox/McGill-publication/Papers/Multisite/figures/default_sim/
    
    
In [81]:
    
print mat['sens_multisite_h0_dummy'][2,:,:]
mat.keys()
    
    
    Out[81]:
In [90]:
    
def plot_boxplot_h0(mat,path_out,N,W,alpha_idx=0):
    alpha = [0.001,0.01,0.05]
    #fig, ax  = plt.figure(figsize=(4,4))
    fig, ax = plt.subplots(figsize=(4, 4))
    plt.plot(alpha[alpha_idx]*np.ones((8,1)),'k--')
    width_=1
    data = [mat['sens_monosite_h0'][alpha_idx,:,:].mean(),mat['sens_multisite_h0_dummy'][alpha_idx,:,:].mean(),mat['sens_multisite_h0'][alpha_idx,:,:].mean()]
    #plt.boxplot([mat['sens_monosite_h0'][alpha_idx,:,:],mat['sens_multisite_h0_dummy'][alpha_idx,:,:],mat['sens_multisite_h0'][alpha_idx,:,:]],notch=1,labels=('Monosite','Multisite\ncorrection','Multisite\nno correction'))
    plt.bar([1,3,5],data,width_)
    ax.set_xticks((1.5,3.5,5.5))
    ax.set_xticklabels(('Monosite','Multisite\ncorrection','Multisite\nno correction'))
    ax.set_ylabel('Detection power')
    ax.set_xlabel('N='+str(N)+', W='+str(W)+'%')
    n = mat['sens_monosite_h0'][alpha_idx,:,:].reshape(-1,1).shape[0]
    ci1 =(0.95/2)*(np.std(mat['sens_monosite_h0'][alpha_idx,:,:])/np.sqrt(n))
    ci2 =(0.95/2)*(np.std(mat['sens_multisite_h0_dummy'][alpha_idx,:,:])/np.sqrt(n))
    ci3 =(0.95/2)*(np.std(mat['sens_multisite_h0'][alpha_idx,:,:])/np.sqrt(n))
    print ci1,ci2,ci3
    plt.legend(['Expected'],bbox_to_anchor=(0., 1.05, 1., .002),handletextpad=0.01, loc=3, ncol=3, mode="expand",borderaxespad=0.,frameon=False)
    ax.yaxis.grid(True, linestyle='-', which='major', color='lightgrey',
               alpha=0.5)
    ax.xaxis.grid(False)
    plt.title('H0')
    if alpha_idx==0:
        plt.ylim(0,0.01)
    if alpha_idx==1:
        plt.ylim(0,0.1)
    if alpha_idx==2:
        plt.ylim(0,0.5)
        
    plt.tight_layout()
    plt.savefig(path_out,dpi=150)
    #plt.plot(-ci+0.05*np.ones((6,1)),'k:')
    #plt.plot(ci+0.05*np.ones((6,1)),'k:')
    
In [93]:
    
mat['sens_multisite_dummyvar'].shape
    
    Out[93]:
In [97]:
    
0.05/np.square(201*11)
    
    Out[97]:
In [79]:
    
mat = load_file(main_path + 'figures/default_sim/samps_s120_15pct/results_simu_power.mat')
out_name = path_out + 'h0_s120_15pct_alpha001.png'
plot_boxplot_h0(mat,out_name,120,15)
    
    
    
In [80]:
    
mat = load_file(main_path + 'figures/default_sim/samps_s40_50pct/results_simu_power.mat')
out_name = path_out + 'h0_s40_50pct_alpha001.png'
plot_boxplot_h0(mat,out_name,40,50)
    
    
    
In [81]:
    
mat = load_file(main_path + 'figures/default_sim/samps_s80_50pct/results_simu_power.mat')
out_name = path_out + 'h0_s80_50pct_alpha001.png'
plot_boxplot_h0(mat,out_name,80,50)
    
    
    
In [82]:
    
mat = load_file(main_path + 'figures/default_sim/samps_s120_50pct/results_simu_power.mat')
out_name = path_out + 'h0_s120_50pct_alpha001.png'
plot_boxplot_h0(mat,out_name,120,50)
    
    
    
In [83]:
    
mat = load_file(main_path + 'figures/default_sim/samps_s120_30pct/results_simu_power.mat')
out_name = path_out + 'h0_s120_30pct_alpha001.png'
plot_boxplot_h0(mat,out_name,120,30)
    
    
    
In [84]:
    
mat = load_file(main_path + 'figures/default_sim/samps_s120_15pct/results_simu_power.mat')
out_name = path_out + 'h0_s120_15pct_alpha001.png'
plot_boxplot_h0(mat,out_name,120,15)
    
    
    
In [92]:
    
mat = load_file(main_path + 'figures/default_sim/samps_s120_50pct/results_simu_power.mat')
out_name = path_out + 'h0_s120_50pct_alpha05.png'
plot_boxplot_h0(mat,out_name,120,50,2)
    
    
    
In [91]:
    
mat = load_file(main_path + 'figures/default_sim/samps_s120_50pct/results_simu_power.mat')
out_name = path_out + 'h0_s120_50pct_alpha01.png'
plot_boxplot_h0(mat,out_name,120,50,1)
    
    
    
In [132]:
    
main_path
    
    Out[132]:
In [66]:
    
plt.figure(figsize=(4,4))
plt.boxplot([mat['sens_monosite_h0'][2,:,:],mat['sens_multisite_h0_dummy'][2,:,:],mat['sens_multisite_h0'][2,:,:]],notch=1,labels=('Monosite','Multisite dummy','Multisite'))
n = mat['sens_monosite_h0'][2,:,:].reshape(-1,1).shape[0]
ci =(0.95/2)*(np.std(mat['sens_monosite_h0'][2,:,:])/np.sqrt(n))
plt.plot(0.05*np.ones((6,1)),'k--')
#plt.plot(-ci+0.05*np.ones((6,1)),'k:')
#plt.plot(ci+0.05*np.ones((6,1)),'k:')
    
    Out[66]:
    
In [ ]:
    
np.sqrt
    
In [34]:
    
mat['sens_monosite_h0'][2,:,:].reshape(-1,1).shape
    
    Out[34]:
In [27]:
    
path_tmp = main_path + 'figures/default_sim/samps_s40_50pct/'
m1,s1 = geteffectsize(path_tmp,'results_simu_power.mat',True,1)
path_tmp = main_path + 'figures/default_sim/samps_s80_50pct/'
m2,s2 = geteffectsize(path_tmp,'results_simu_power.mat',True,1) 
path_tmp = main_path + 'figures/default_sim/samps_s120_50pct/'
m3,s3 = geteffectsize(path_tmp,'results_simu_power.mat',True,1) 
path_tmp = main_path + 'figures/default_sim/samps_s40_50pct/'
mm1,sm1 = geteffectsize(path_tmp,'results_simu_power.mat',False,1) 
path_tmp = main_path + 'figures/default_sim/samps_s80_50pct/'
mm2,sm2 = geteffectsize(path_tmp,'results_simu_power.mat',False,1) 
path_tmp = main_path + 'figures/default_sim/samps_s120_50pct/'
mm3,sm3 = geteffectsize(path_tmp,'results_simu_power.mat',False,1)
yref=[]
x = np.linspace(40, 120, 3)
y = np.array([m1,m2,m3])
y2 = np.array([mm1,mm2,mm3])
f1 = interp1d(x, y, kind='linear')
f2 = interp1d(x, y2, kind='linear')
xnew = np.linspace(40, 120, 40)
for i in xnew:
    yref.append((pow.TTestIndPower().solve_power(nobs1=i/2, power=0.8, ratio=1, alpha=0.01)))
yref  = np.array(yref)
plt.figure(figsize=(6,6))
sns.set_context('paper',font_scale=1.8)
plt.plot(xnew,yref,'k--',lw=2)
#plt.scatter(x,y,c="r",s=50)
#plt.scatter(x,y2,c="b",s=50)
plt.errorbar(x, y, yerr=[s1,s2,s3], fmt='rD')
plt.errorbar(x, y2, yerr=[sm1,sm2,sm3], fmt='bD')
plt.legend(['parametric','monosite','multisite (7 sites)'],bbox_to_anchor=(0., 1.05, 1., .002),handletextpad=0.1, loc=3, ncol=3, mode="expand",borderaxespad=0.,frameon=False)
plt.xlabel('Total # subjects')
plt.ylabel('Effect size (Cohen\'s ' + r'$d$)')
plt.grid(True)
axes = plt.gca()
axes.set_xlim([20,140])
axes.set_ylim([0,1.8])
plt.title(r'False-positive rate $\alpha=0.01$')
plt.savefig(path_out + 'samplesize_effectsize_pow80_alpha01.png',dpi=150)
    
    
In [28]:
    
path_tmp = main_path + 'figures/default_sim/samps_s40_50pct/'
m1,s1 = geteffectsize(path_tmp,'results_simu_power.mat',True,2)
path_tmp = main_path + 'figures/default_sim/samps_s80_50pct/'
m2,s2 = geteffectsize(path_tmp,'results_simu_power.mat',True,2) 
path_tmp = main_path + 'figures/default_sim/samps_s120_50pct/'
m3,s3 = geteffectsize(path_tmp,'results_simu_power.mat',True,2) 
path_tmp = main_path + 'figures/default_sim/samps_s40_50pct/'
mm1,sm1 = geteffectsize(path_tmp,'results_simu_power.mat',False,2) 
path_tmp = main_path + 'figures/default_sim/samps_s80_50pct/'
mm2,sm2 = geteffectsize(path_tmp,'results_simu_power.mat',False,2) 
path_tmp = main_path + 'figures/default_sim/samps_s120_50pct/'
mm3,sm3 = geteffectsize(path_tmp,'results_simu_power.mat',False,2)
yref=[]
x = np.linspace(40, 120, 3)
y = np.array([m1,m2,m3])
y2 = np.array([mm1,mm2,mm3])
f1 = interp1d(x, y, kind='linear')
f2 = interp1d(x, y2, kind='linear')
xnew = np.linspace(40, 120, 40)
for i in xnew:
    yref.append((pow.TTestIndPower().solve_power(nobs1=i/2, power=0.8, ratio=1, alpha=0.05)))
yref  = np.array(yref)
plt.figure(figsize=(6,6))
sns.set_context('paper',font_scale=1.8)
plt.plot(xnew,yref,'k--',lw=2)
#plt.scatter(x,y,c="r",s=50)
#plt.scatter(x,y2,c="b",s=50)
plt.errorbar(x, y, yerr=[s1,s2,s3], fmt='rD')
plt.errorbar(x, y2, yerr=[sm1,sm2,sm3], fmt='bD')
plt.legend(['parametric','monosite','multisite (7 sites)'],bbox_to_anchor=(0., 1.05, 1., .002),handletextpad=0.1, loc=3, ncol=3, mode="expand",borderaxespad=0.,frameon=False)
plt.xlabel('Total # subjects')
plt.ylabel('Effect size (Cohen\'s ' + r'$d$)')
plt.grid(True)
axes = plt.gca()
axes.set_xlim([20,140])
axes.set_ylim([0,1.8])
plt.title(r'False-positive rate $\alpha=0.05$')
plt.savefig(path_out + 'samplesize_effectsize_pow80_alpha05.png',dpi=150)
    
    
In [408]:
    
np.linspace(0, 120, 4)
    
    Out[408]:
conn = 0 path_tmp = main_path + 'figures/samps_s40_50pct/' for conn in range(9, 10): gen_fig(path_tmp,'results_simu_power.mat',path_tmp, 'detection_power.pdf',conn)
path_tmp = main_path + 'figures/samps_s80_50pct/' for conn in range(9, 10): gen_fig(path_tmp,'results_simu_power.mat',path_tmp, 'detection_power.pdf',conn)
path_tmp = main_path + 'figures/samps_s120_50pct/' for conn in range(9, 10): gen_fig(path_tmp,'results_simu_power.mat',path_tmp, 'detection_power.pdf',conn)
In [6]:
    
sns.set_color_codes('muted')
path_tmp = main_path + 'figures/default_sim/samps_s40_50pct/'
gen_fig_allconn(path_tmp,'results_simu_power.mat',path_out, 'realdata_detect_pow_s40_50pct.png',efflim=2)
path_tmp = main_path + 'figures/default_sim/samps_s80_50pct/'
gen_fig_allconn(path_tmp,'results_simu_power.mat',path_out, 'realdata_detect_pow_s80_50pct.png',efflim=2)
path_tmp = main_path + 'figures/default_sim/samps_s120_50pct/'
gen_fig_allconn(path_tmp,'results_simu_power.mat',path_out, 'realdata_detect_pow_s120_50pct.png',efflim=2)
current_palette = sns.color_palette()
sns.palplot(current_palette)
current_palette = sns.color_palette('pastel')
sns.palplot(current_palette)
current_palette = sns.color_palette('muted')
sns.palplot(current_palette)
    
    
    
    
    
    
    
    
In [12]:
    
'''
path_tmp = main_path + 'figures/default_sim/samps_s80_15pct/'
gen_fig_allconn(path_tmp,'results_simu_power.mat',path_out, 'realdata_detect_pow_s80_15pct.png')
    
path_tmp = main_path + 'figures/default_sim/samps_s80_30pct/'
gen_fig_allconn(path_tmp,'results_simu_power.mat',path_out, 'realdata_detect_pow_s80_30pct.png')
    
path_tmp = main_path + 'figures/default_sim/samps_s80_50pct/'
gen_fig_allconn(path_tmp,'results_simu_power.mat',path_out, 'realdata_detect_pow_s80_50pct.png')
'''
path_tmp = main_path + 'figures/default_sim/samps_s120_15pct/'
gen_fig_allconn(path_tmp,'results_simu_power.mat',path_out, 'realdata_detect_pow_s120_15pct_14.png',efflim=2)
    
path_tmp = main_path + 'figures/default_sim/samps_s120_30pct/'
gen_fig_allconn(path_tmp,'results_simu_power.mat',path_out, 'realdata_detect_pow_s120_30pct_14.png',efflim=2)
    
path_tmp = main_path + 'figures/default_sim/samps_s120_50pct/'
gen_fig_allconn(path_tmp,'results_simu_power.mat',path_out, 'realdata_detect_pow_s120_50pct_14.png',efflim=2)
    
    
    
    
    
In [19]:
    
path_tmp = main_path + 'figures/sim_site_patho/samps_s80_15pct/'
gen_fig_allconn(path_tmp,'results_simu_power.mat',path_out, 'realdata_detect_pow_sitepatho_s80_15pct.png',efflim=2)
path_tmp = main_path + 'figures/sim_site_patho/samps_s80_30pct/'
gen_fig_allconn(path_tmp,'results_simu_power.mat',path_out, 'realdata_detect_pow_sitepatho_s80_30pct.png',efflim=2)
path_tmp = main_path + 'figures/sim_site_patho/samps_s80_50pct/'
gen_fig_allconn(path_tmp,'results_simu_power.mat',path_out, 'realdata_detect_pow_sitepatho_s80_50pct.png',efflim=2)
path_tmp = main_path + 'figures/sim_site_patho/samps_s120_15pct/'
gen_fig_allconn(path_tmp,'results_simu_power.mat',path_out, 'realdata_detect_pow_sitepatho_s120_15pct.png',efflim=2)
path_tmp = main_path + 'figures/sim_site_patho/samps_s120_30pct/'
gen_fig_allconn(path_tmp,'results_simu_power.mat',path_out, 'realdata_detect_pow_sitepatho_s120_30pct.png',efflim=2)
path_tmp = main_path + 'figures/sim_site_patho/samps_s120_50pct/'
gen_fig_allconn(path_tmp,'results_simu_power.mat',path_out, 'realdata_detect_pow_sitepatho_s120_50pct.png',efflim=2)
    
    
    
    
    
    
    
    
path_tmp = main_path + 'figures/2sites_realdata/samps_s33_70_30_2site/' gen_fig_allconn(path_tmp,'results_simu_power.mat',path_out, 'realdata_detect_pow_sitepatho2site_s33_70pct.pdf') path_tmp = main_path + 'figures/2sites_realdata/samps_s33_30_70_2site/' gen_fig_allconn(path_tmp,'results_simu_power.mat',path_out, 'realdata_detect_pow_sitepatho2site_s33_30pct.pdf')
In [18]:
    
path_tmp = main_path + 'figures/2sites_realdata/samps_s100_30_70_2site/'
gen_fig_allconn(path_tmp,'results_simu_power.mat',path_out, 'realdata_detect_pow_sitepatho2site_s100_30pct.png',efflim=2,nsites=2)
path_tmp = main_path + 'figures/2sites_realdata/samps_s100_70_30_2site/'
gen_fig_allconn(path_tmp,'results_simu_power.mat',path_out, 'realdata_detect_pow_sitepatho2site_s100_70pct.png',efflim=2,nsites=2)
    
    
    
    
In [413]:
    
path_tmp = main_path + 'figures/'
gen_fig_full_sim(path_tmp,'simu_bal5050_var0_site0.mat',path_tmp, 'detect_pow_bal5050_var0_site0.png')
gen_fig_full_sim(path_tmp,'simu_bal5050_var0_site05.mat',path_tmp, 'detect_pow_bal5050_var0_site05.png')
gen_fig_full_sim(path_tmp,'simu_bal5050_var2_site0.mat',path_tmp, 'detect_pow_bal5050_var2_site0.png')
gen_fig_full_sim(path_tmp,'simu_bal5050_var2_site05.mat',path_tmp, 'detect_pow_bal5050_var2_site05.png')
    
    
    
    
    
    
In [414]:
    
path_tmp = main_path + 'figures/'
gen_fig_full_sim(path_tmp,'simu_bal7030_var0_site0.mat',path_tmp, 'detect_pow_bal7030_var0_site0.png')
gen_fig_full_sim(path_tmp,'simu_bal7030_var0_site05.mat',path_tmp, 'detect_pow_bal7030_var0_site05.png')
gen_fig_full_sim(path_tmp,'simu_bal7030_var2_site0.mat',path_tmp, 'detect_pow_bal7030_var2_site0.png')
gen_fig_full_sim(path_tmp,'simu_bal7030_var2_site05.mat',path_tmp, 'detect_pow_bal7030_var2_site05.png')
    
    
    
    
    
    
In [415]:
    
path_tmp = main_path + 'figures/'
gen_fig_full_sim(path_tmp,'simu_2080bal5050_var0_site0.mat',path_tmp, 'detect_pow_2080bal5050_var0_site0.png')
gen_fig_full_sim(path_tmp,'simu_2080bal5050_var0_site05.mat',path_tmp, 'detect_pow_2080bal5050_var0_site05.png')
gen_fig_full_sim(path_tmp,'simu_2080bal5050_var2_site0.mat',path_tmp, 'detect_pow_2080bal5050_var2_site0.png')
gen_fig_full_sim(path_tmp,'simu_2080bal5050_var2_site05.mat',path_tmp, 'detect_pow_2080bal5050_var2_site05.png')
    
    
    
    
    
    
In [416]:
    
path_tmp = main_path + 'figures/'
gen_fig_full_sim(path_tmp,'simu_2080bal7030_var0_site0.mat',path_tmp, 'detect_pow_2080bal7030_var0_site0.png')
gen_fig_full_sim(path_tmp,'simu_2080bal7030_var0_site05.mat',path_tmp, 'detect_pow_2080bal7030_var0_site05.png')
gen_fig_full_sim(path_tmp,'simu_2080bal7030_var2_site0.mat',path_tmp, 'detect_pow_2080bal7030_var2_site0.png')
gen_fig_full_sim(path_tmp,'simu_2080bal7030_var2_site05.mat',path_tmp, 'detect_pow_2080bal7030_var2_site05.png')
gen_fig_full_sim(path_tmp,'simu_8020bal7030_var0_site0.mat',path_tmp, 'detect_pow_8020bal7030_var0_site0.png')
gen_fig_full_sim(path_tmp,'simu_8020bal7030_var0_site05.mat',path_tmp, 'detect_pow_8020bal7030_var0_site05.png')
gen_fig_full_sim(path_tmp,'simu_8020bal7030_var2_site0.mat',path_tmp, 'detect_pow_8020bal7030_var2_site0.png')
gen_fig_full_sim(path_tmp,'simu_8020bal7030_var2_site05.mat',path_tmp, 'detect_pow_8020bal7030_var2_site05.png')
    
    
    
    
    
    
    
    
    
    
In [417]:
    
path_tmp = main_path + 'figures/'
gen_fig_full_sim(path_tmp,'simu_10subj_20sites_rndbal1090_var0_site05.mat',path_tmp, 'detect_pow_10subj_20sites_rndbal1090_var0_site05.png')
gen_fig_full_sim(path_tmp,'simu_10subj_50sites_rndbal1090_var0_site05.mat',path_tmp, 'detect_pow_10subj_50sites_rndbal1090_var0_site05.png')
gen_fig_full_sim(path_tmp,'simu_rndsubj0520_50sites_rndbal1090_var0_site05.mat',path_tmp, 'detect_pow_rndsubj0520_50sites_rndbal1090_var0_site05.png')
gen_fig_full_sim(path_tmp,'simu_rndsubj0215_50sites_rndbal1090_var0_siternd0005.mat',path_tmp, 'detect_pow_rndsubj0215_50sites_rndbal1090_var0_siternd0005.png')
gen_fig_full_sim(path_tmp,'simu_rndsubj0215_50sites_rndbal1090_varrnd02_siternd0005.mat',path_tmp, 'detect_pow_rndsubj0215_50sites_rndbal1090_varrnd02_siternd0005.png')
    
    
    
    
    
    
    
In [418]:
    
aa = load_file(path_tmp + 'simu_10subj_20sites_rndbal1090_var0_site05.mat')
    
In [419]:
    
aa.keys()
aa.get('sens_mono')
    
    Out[419]:
In [420]:
    
#color palette "#9b59b6", "#3498db", "#95a5a6", "#e74c3c", "#34495e", "#2ecc71"
def plotpropbar(patho,ctrl):
    plt.figure(figsize=(2, 2))
    plt.subplot2grid((5,5), (1,1),colspan=4, rowspan=4)
    N = 2
    ind = np.arange(N)/4.    # the x locations for the groups
    width = 0.20       # the width of the bars: can also be len(x) sequence
    p1 = plt.bar(ind, patho,width, color='#3498db')
    p2 = plt.bar(ind, ctrl, width, color='#95a5a6',bottom=patho)
    plt.ylabel('# subjects')
    #plt.title('Scores by group and gender')
    plt.xticks(ind+width/2., ('Site1', 'Site2') )
    plt.yticks(np.arange(0,101,20))
    #plt.legend( (p1[0], p2[0]), ('Patho', 'CTRL') )
    plt.legend((p1[0], p2[0]), ('Patho', 'Control'),bbox_to_anchor=(0., 1.0, 1., .102), loc=3, ncol=1, borderaxespad=0.,frameon=False)
path_tmp = main_path + 'figures/'
# simulation data repartition
patho   = (35, 15)
ctrl = (15, 35)
plotpropbar(patho,ctrl)
plt.savefig(path_tmp + 'prop_5050subj_7030.png')
patho   = (25, 25)
ctrl = (25, 25)
plotpropbar(patho,ctrl)
plt.savefig(path_tmp + 'prop_5050subj_5050.png')
patho   = (40, 10)
ctrl = (40, 10)
plotpropbar(patho,ctrl)
plt.savefig(path_tmp + 'prop_8020subj_5050.png')
patho   = (56, 6)
ctrl    = (24, 14)
plotpropbar(patho,ctrl)
plt.savefig(path_tmp + 'prop_8020subj_7030.png')
patho   = (10, 40)
ctrl = (10, 40)
plotpropbar(patho,ctrl)
plt.savefig(path_tmp + 'prop_2080subj_5050.png')
patho   = (6, 56)
ctrl    = (14, 24)
plotpropbar(patho,ctrl)
plt.savefig(path_tmp + 'prop_2080subj_7030.png')
# real data repartition
patho   = (30, 30)
ctrl    = (30, 30)
plotpropbar(patho,ctrl)
plt.savefig(path_tmp + 'prop_real120subj_5050.png')
patho   = (42, 18)
ctrl    = (18, 42)
plotpropbar(patho,ctrl)
plt.savefig(path_tmp + 'prop_real120subj_7030.png')
patho   = (18, 42)
ctrl    = (42, 18)
plotpropbar(patho,ctrl)
plt.savefig(path_tmp + 'prop_real120subj_3070.png')
    
    
    
    
    
    
    
    
    
    
In [35]:
    
4990*0.001
    
    Out[35]:
In [15]:
    
def errorfill_pred(x, y, yerr, color=None, alpha_fill=0.3, ax=None, label=''):
    ax = ax if ax is not None else plt.gca()
    if color is None:
        color = ax._get_lines.color_cycle.next()
    if np.isscalar(yerr) or len(yerr) == len(y):
        ymin = y - yerr
        ymax = y + yerr
    elif len(yerr) == 2:
        ymin, ymax = yerr
    ax.plot(x, y, color=color, label=label, lw=3)
    #ax.fill_between(x, ymax, ymin, color=color, alpha=alpha_fill)
    
def gen_fig_prediction(path_in, file_in, path_out, file_out, conn=0, pvalidx=0, efflim=1.5,nsites=7):
    labels_pct_regions = ['0.1%','1%','5%']
    labels_box = ['H0 multi','H0 Dummy', 'H0 METAL']
    lw = 2
    mat = load_file(path_in + file_in)
    pvals = mat.get('list_p')[0]
    
    fig = plt.figure(figsize=(5,5),dpi=300)
    sns.set_context('paper',font_scale=1.7)
    plt.subplot2grid((5,2), (1,0),colspan=2,rowspan=4)
    ax = fig.gca()
    #ax.set_xticks(np.arange(0,1,0.1))
    #ax.set_yticks(np.arange(0,1.,0.1))
    if efflim==2:
        plt.xlim(0,2)
        effect_size = np.arange(0.0, 2.001, 0.01)
    else:
        plt.xlim(0,1.5)
        effect_size = np.arange(0.0, 1.501, 0.01)
    
    plt.ylabel('Accuracy')
    plt.xlabel('Effect size (Cohen\'s ' + r'$d$)')
    ax.set_ylim((0,1))
    tmpdata = mat.get('sens_monosite')[pvalidx,:,:]
    errorfill_pred(effect_size, tmpdata.mean(axis=1)[:len(effect_size)],tmpdata.std(axis=1)[:len(effect_size)],label="Monosite", color='r')
    tmpdata = mat.get('sens_multisite_nocorr')[pvalidx,:,:]
    errorfill_pred(effect_size, tmpdata.mean(axis=1),tmpdata.std(axis=1),label="Multisite no correction", color='k')
    tmpdata = mat.get('sens_multisite_dummyvar')[pvalidx,:,:]
    errorfill_pred(effect_size, tmpdata.mean(axis=1)[:len(effect_size)],tmpdata.std(axis=1)[:len(effect_size)],label="Multisite ("+str(nsites)+" sites)", color='b')
    #tmpdata = mat.get('sens_multisite_metal')[pvalidx,:,:]
    #errorfill(effect_size, tmpdata.mean(axis=1),tmpdata.std(axis=1),label="Multisite METAL", color='m')
    
    plt.grid(True)
    plt.title(r'Connections affected $\pi_1=$' +  labels_pct_regions[pvalidx])
    
    # fully use the given bounding box.
    plt.legend(bbox_to_anchor=(0., 1.10, 1., .102), loc=3, ncol=2, mode="expand", borderaxespad=0.,frameon=False)
    
    print('monosite h0: ',np.mean(mat.get('sens_monosite_h0')[pvalidx,:,:]))
    print('multisite no corr h0: ',np.mean(mat.get('sens_multisite_h0')[pvalidx,:,:]))
    print('multisite corr h0: ',np.mean(mat.get('sens_multisite_h0_dummy')[pvalidx,:,:]))
    plt.tight_layout()
    plt.savefig(path_out + file_out,dpi=150)
    
In [7]:
    
path_tmp = main_path + 'figures/simulation_prediction/results_simu_power.mat'
mat = load_file(path_tmp)
    
    
In [44]:
    
mat.keys()
    
    Out[44]:
In [67]:
    
np.std(mat['sens_monosite'][2,:,:],axis=1)
    
    Out[67]:
In [61]:
    
main_path
    
    Out[61]:
In [16]:
    
path_tmp = main_path + 'figures/simulation_prediction/samps_s120_50pct/'
gen_fig_prediction(path_tmp,'results_simu_power.mat',path_tmp, 'prediction_120_01pct.png',pvalidx=0,efflim=2)
path_tmp = main_path + 'figures/simulation_prediction/samps_s80_50pct/'
gen_fig_prediction(path_tmp,'results_simu_power.mat',path_tmp, 'prediction_80_01pct.png',pvalidx=0,efflim=2)
    
    
    
    
In [17]:
    
path_tmp = main_path + 'figures/simulation_prediction/samps_s120_50pct/'
gen_fig_prediction(path_tmp,'results_simu_power.mat',path_tmp, 'prediction_120_10pct.png',pvalidx=1,efflim=2)
path_tmp = main_path + 'figures/simulation_prediction/samps_s80_50pct/'
gen_fig_prediction(path_tmp,'results_simu_power.mat',path_tmp, 'prediction_80_10pct.png',pvalidx=1,efflim=2)
    
    
    
    
In [18]:
    
path_tmp = main_path + 'figures/simulation_prediction/samps_s120_50pct/'
gen_fig_prediction(path_tmp,'results_simu_power.mat',path_tmp, 'prediction_120_50pct.png',pvalidx=2,efflim=2)
path_tmp = main_path + 'figures/simulation_prediction/samps_s80_50pct/'
gen_fig_prediction(path_tmp,'results_simu_power.mat',path_tmp, 'prediction_80_50pct.png',pvalidx=2,efflim=2)
    
    
    
    
In [ ]: