示例#1
0
def plotXtypes(S):
    global FII
    figure(size=2,aspect=0.4)
    lbls=['No X','Ballanced','Uncrossed','Crossed','Double-crossed']
    for i in range(5):
        s=S[i+2]
        ax=subplot(1,5,i+1)
        plt.plot([0,1],s[:2],'-o')
        plt.plot([0,1],s[2:],'-o')
        ax.set_xticks([0,1])
        ax.set_xticklabels(['G1','G2'])
        plt.ylim([-4.5,0.5])
        plt.xlim([-0.25,1.25])
        if i>0: ax.set_yticklabels([])
        else: 
            #plt.legend(['F1','F2'])
            plt.ylabel('$d$')
        plt.xlabel(lbls[i])
    if FII>=0:
        fn='fig%02d.%s'%(FII,FIGFMT)
        FII+=1
    else: fn='xtypes.png'
    plt.savefig(FIGDIR+fn,bbox_inches='tight',dpi=DPI,format=FIGFMT)
    plt.clf()
    plt.close()
示例#2
0
def plotSkew(dgps):
    global FII
    cls=['$c_l$','$b$','$c_l$','$c_l$','$c_l$','$c_l$']
    figure(size=3,aspect=0.6)
    for h in range(len(dgps)):
        try:D=dgps[h].loadData(i=2,j=2)
        except FileNotFoundError: continue
        x=dgps[h].cl
        for g in range(3):
            ax=subplot(3,len(dgps),1+h+g*len(dgps))
            plt.grid(axis='x')
            if g==0: 
                plt.title(DLBLS[h])
                y=np.median(D[:,:,6],axis=1)*[1,0.1][dgps[h].suf=='BE']
            elif g==1: y=np.median(D[:,:,7],axis=1)
            elif g==2: y=np.median(D[:,:,23],axis=1)
            plt.plot(x,y,CLRS[-1],lw=LWS[1])
            if g==0: plt.ylim([0,1])
            elif g==1: plt.ylim([[0,10],[0,0.01],[0,3],[0,6],[0,0.1],[0,0.06]][h])
            elif g==2: plt.ylim([[0,3],[0,3],[0,8],[0,3],[0,3],[-3,3]][h])
            if g<2: ax.set_xticklabels([])
            else: plt.xlabel(cls[h])
            plt.xlim([x[0],x[-1]])
            ax.locator_params(axis='x', nbins=4,min_n_ticks=3)
            if not h: plt.ylabel(['Mean','Variance','Skewness'][g])
            elif g==0: ax.set_yticklabels([])
            elif g==1:
                lm=[0,-3,0,0,-2,-2][h]
                if lm!=0: ax.ticklabel_format(axis='y',style='sci',scilimits=(lm,lm))
    if FII>=0:
        fn='fig%02d.%s'%(FII,FIGFMT)
        FII+=1
    else: fn=FIGLBLS[0]+'png'            
    plt.savefig(FIGDIR+fn,bbox_inches='tight',dpi=DPI,format=FIGFMT)
    plt.clf();plt.close()
示例#3
0
def plotPDF(A,B,C,pdf,xmax=1,albls=['','','test']):
    C=np.linspace(C[0],C[-1],6)
    x=np.linspace(0,xmax,101)
    figure(size=3,aspect=1)
    def _hlp(A,i):
        if A.size>1 and xmax>0: return '%.2f'%A[i]
        else: return ''
    for i in range(A.size):
        for j in range(B.size):
            for h in range(C.size):
                ax=subplot(A.size,B.size,B.size*i+1+j)
                try:
                    if xmax>0: y=pdf(x,A[i],B[j],C[h])
                    else: y,x=pdf(A[i],B[j],C[h])
                except AssertionError: continue
                plt.plot(x,y,'k',alpha=0.2)
                plt.ylim([0,1])
                ax.set_yticks([0,1])
                if j>0: ax.set_yticklabels([])
                else: plt.ylabel(albls[0]+_hlp(A,i))
                if i+1<A.size: ax.set_xticklabels([])
                else: plt.xlabel(albls[1]+_hlp(B,j))
                plt.grid(False)
    plt.savefig(SUPDIR+albls[-1]+'prob',format=FIGFMT,     
        bbox_inches='tight',dpi=DPI)
    plt.clf();plt.close()
示例#4
0
def plotANOVA1F(x,G,showLegend=False,alpha=0.05):
    sel=np.all(~np.isnan(G[:,:,0]),axis=1)
    y=(G[sel,:,:]<alpha).mean(1)
    for ii in range(3):
        plt.plot(x[sel],y[:,ii],CLRS[ii],lw=LWS[ii]) 
    #print(np.max(np.atleast_2d(y[:,2]).T-y,axis=0))   
    if showLegend: plt.legend(['log-ANOVA','ANOVA','KW test'],loc=2)
示例#5
0
def plotTOST(x,G,showLegend=False,alpha=0.05):
    for i in range(2):
        sel=np.logical_or(np.all(~np.isnan(G[:,:,2*i+0]),axis=1),
            np.all(~np.isnan(G[:,:,2*i+1]),axis=1))    
        plt.plot(x[sel],np.logical_and(G[:,:,2*i]<alpha,
            G[:,:,2*i+1]<alpha).mean(1)[sel],CLRS[i],lw=LWS[i])
    if showLegend: plt.legend(['log TOST','TOST'],loc=2)
示例#6
0
def plotNHST(x,G,showLegend=False,alpha=0.05):
    sel=np.all(~np.isnan(G[:,:,0]),axis=1)
    y=(G[sel,:,:]<alpha).mean(1)
    for ii in range(4):
        plt.plot(x[sel],y[:,ii],CLRS[ii],lw=LWS[ii])
    #print(np.max(np.atleast_2d(y[:,2]).T-y,axis=0))
    if showLegend: plt.legend(['log welch','welch','MW test','trimmed t'],loc=2)
示例#7
0
def plotCI(x,G,ylim=[-0.5,1],alpha=0.05,K=0):
    N=G[0,0,AI-1]/2
    for ii in range(2):
        #if K and ii==0:            
        #    d,sd=_difLogitBinomProp(G[:,:,6],G[:,:,4],N)
        #    #print(np.median(G[0,:,6]))
        #    d=np.median(d,axis=1);sd=np.median(sd,axis=1)
        #else:
        d=np.median(G[:,:,2+ii*4]-G[:,:,ii*4],axis=1)
        v1=G[:,:,3+ii*4];v2=G[:,:,1+ii*4]
        sd= np.sqrt(np.median(v1+v2,axis=1))/np.sqrt(2*N)
        df=np.floor(np.square((1+np.nanmedian(v1/v2,1))/N)/
                ((1+np.square(np.nanmedian(v1/v2,1)))/(N**2*(N-1))))
        sel=~np.isnan(d)
        C2=[CLRS[-1],CLRS[1]];C=[CLRS,C2]           
        plt.plot(x[sel],d[sel],C[K>0][ii],lw=LWS[ii])
        xx=np.concatenate([x[sel],x[sel][::-1]])
        if K and ii==0:
            lb=d+sd*stats.norm.ppf(alpha/2)
            ub=d+sd*stats.norm.ppf(1-alpha/2)
        else:
            lb=d+sd*stats.t.ppf(alpha/2,df)
            ub=d+sd*stats.t.ppf(1-alpha/2,df)
        ci=np.concatenate([lb[sel],ub[sel][::-1]])
        if len(xx)==0: return
        plt.gca().add_patch(plt.Polygon(np.array([xx,ci]).T,
                alpha=0.2,fill=True,fc=C[K>0][ii],ec=C[K>0][ii]))
    plt.ylim(ylim) 
示例#8
0
def plotCohendCI(x,G,ylim=[-0.3,1.5],alpha=0.05):
    N=G[0,0,AI-1]/2
    for ii in range(2):
        v1=G[:,:,3+ii*4];v2=G[:,:,1+ii*4]
        d=np.median((G[:,:,2+ii*4]-G[:,:,ii*4])/np.sqrt((v1+v2)/2),axis=1)
        sel=~np.isnan(d)
        plt.plot(x[sel],d[sel],CLRS[ii],lw=LWS[ii])
        z=stats.norm.ppf(1-alpha/2)
        s=z*np.sqrt(2/N+np.square(d[sel])/4/N)+1e-15
        xx=np.concatenate([x[sel],x[sel][::-1]])
        ci=np.concatenate([d[sel]-s,(d[sel]+s)[::-1]])
        if len(xx)==0: return
        plt.gca().add_patch(plt.Polygon(np.array([xx,ci]).T,
                alpha=0.2,fill=True,fc=CLRS[ii],ec=CLRS[ii]))
    plt.ylim(ylim)
示例#9
0
def plot(figname='stan.png', dpi=300):
    from matusplotlib import figure, subplot, plt
    figure(size=3, aspect=0.3)
    il = [
        'dog', 'trolley', 'wallet', 'plane', 'resume', 'kitten', 'mean score',
        'median score'
    ]
    w = loadStanFit('schnall')
    S = np.load('S.npy')
    offset = np.array(w['c'][:, 0] / 2 + w['c'][:, -1] / 2, ndmin=2).T
    scale = np.array(np.abs(w['c'][:, 0] - w['c'][:, -1]) / 2, ndmin=2).T
    bp = np.linspace(-2.2, 2.2, 51)
    b = bp * np.median(scale) + np.median(offset)
    cs = np.median(w['c'], axis=0)
    d = np.median(-w['d'], axis=0)
    #xlm=[cs[0]-0.2,cs[-1]+0.2]
    xlm = b[[0, -1]]
    cls = []
    for i in range(cs.size):
        cls.append('$c_%d$' % i)
    tmp = np.median(-w['tbeta'], axis=0)

    for j in range(2):
        ax = subplot(1, 2, 1 + j)
        plt.plot(xlm, [-d[0], -d[0]])
        plt.xlim(xlm)
        ax.set_xticks(cs)
        ax.set_xticklabels(cls)
        plt.plot(tmp[0, :], -0.7 * np.ones(6), 'xg')
        plt.plot(tmp[1, :], -0.9 * np.ones(6), 'xr')
        #for k in range(tmp.shape[1]):
        #    plt.plot(tmp[0:,k],[-0.09,-0.11],'k',alpha=0.2)
        ds = np.zeros((len(S), 3)) * np.nan
        for i in range(len(S)):
            if j:
                wi = loadStanFit('schnSimBB%02d' % i)
                ds[i, :] = sap(wi['gg1'][:, 1] - wi['gg2'][:, 1],
                               [2.5, 50, 97.5])
            elif j == 0:
                wi = loadStanFit('schnSimOLR%02d' % i)
                ds[i, :] = sap(wi['d'], [2.5, 50, 97.5])
        plt.plot(b, ds[:, 1], 'k')
        temp = [list(b) + list(b)[::-1], list(ds[:, 0]) + list(ds[:, 2])[::-1]]
        ax.add_patch(
            plt.Polygon(xy=np.array(temp).T, alpha=0.2, fc='k', ec='k'))
        plt.ylim([[-2, 4], [-2, 4]][j])
        plt.ylabel('$c_u^\Delta$')
        plt.xlabel(['$c_u=-c_l$', '$c_u$'][j])
        plt.title(['OLRM', 'Beta-Binomial'][j])
        plt.grid(axis='x')
    plt.savefig(figname, bbox_inches='tight', dpi=dpi)
示例#10
0
 def makeSupplement(self):
     print(self.suf+'creating supplement')
     #plotPDF(self.np1,self.np2,self.cl,self.pdf,xmax=self.xmax,
     #    albls=['$c_l^\Delta=$','$%s=$'%self.np2lbl,self.suf])
     #tref=(self.cld[0,1]-self.cld[0,0])*np.ones(self.cl.shape)
     n1=self.np1.size;n2=self.np2.size
     for f in range(1,7):
         plt.close('all')
         figure(num=f+1,size=3,aspect=1)
         for i in range(n1):
             for j in range(n2):
                 R=self.loadData(i=i,j=j)
                 ax=subplot(n1,n2,i*n2+j+1)
                 #plt.title(getTitle(i,j))
                 plt.grid(axis='x')
                 plt.ylim([-0.05,1.05])
                 x=np.load(DPATH+'cl_'+self.suf+'.npy')
                 legon= (i==0 and j==0)
                 if f==1:
                     plotCI(x,R)
                     tref=(self.cld[0,1]-self.cld[0,0])*self.np1[i]
                     plt.plot(x,tref*np.ones(x.size),'c')
                     plt.ylim(self.cil[i])
                 elif f==2:  
                     plotCohendCI(x,R,ylim=self.cil[i+5])
                 elif f==3:plotNHST(x,R[:,:,8:12],legon)
                 elif f==4:plotANOVA1F(x,R[:,:,18:22],legon)
                 elif f==5:plotTOST(x,R[:,:,12:16],legon)
                 elif f==6:plotBFT(x,R[:,:,16:18],legon)
                 plt.xlim([x[0],x[-1]])
                 if j!=0:ax.set_yticklabels([])
                 else:plt.ylabel('$c_l^\Delta=%.2f$'%self.np1[i])
                 if i!=n1-1: ax.set_xticklabels([])
                 else:
                     temp=(self.np2lbl,self.np2[j])
                     plt.xlabel('$%s=%.2f$'%temp)
         plt.savefig(SUPDIR+self.suf+FIGLBLS[f],
             dpi=DPI,bbox_inches='tight',format=FIGFMT)
         plt.clf();plt.close()
示例#11
0
def plotFcfe():
    global FII
    figure(size=1,aspect=0.6)
    x=np.linspace(0,1,101)[1:-1]
    fl=[-np.log(x),-np.log(x/(1-x))]
    fu=[-np.log(1-x),-np.log((1-x)/x)]
    for i in range(2):
        ax=subplot(1,2,1+i)
        plt.plot(x,fl[i])
        plt.plot(x,fu[i])
        plt.xlabel('$g[\phi]$')
        #if not i:plt.ylabel('$f(\phi)$')
        plt.text(0.25,3,'$f_l(g)$',horizontalalignment='center')
        plt.text(0.65,4.1,'$f_u(1-g)$',horizontalalignment='center')
        ttl=['$-\log x$','$-\log(x/(1-x))$'][i]
        #plt.legend(['$f_l(\phi)$','$f_u(1-\phi)$'])
        plt.title(ttl,fontsize=10) 
    if FII>=0:
        fn='fig%02d.%s'%(FII,FIGFMT)
        FII+=1
    else: fn='fcfe.png'
    plt.savefig(FIGDIR+fn,bbox_inches='tight',dpi=DPI)
    plt.clf();plt.close()
示例#12
0
def plotANOVAall(dgps,showLegend=False,alpha=0.05,i=2,j=2): 
    global FII       
    cls=['$c_l$','$b$','$c_l$','$c_l$','$c_l$','$c_l$']
    lblls=['no X','no ME','uncrossed','crossed',
        'double-crossed','no X','uncrossed']
    K=len(S)-4
    figure(size=3,aspect=1)
    for h in range(len(dgps)):
        D=dgps[h].loadData(i=i,j=j)[:,:,AI:]
        x=dgps[h].cl
        for k in range(K):
            ax=subplot(K,len(dgps),1+k*len(dgps)+h)
            plt.grid(axis='x')
           
            for ii in range(3):
                s=np.all(~np.isnan(D[:,:,k*9]),axis=1)
                if not k: plt.title(DLBLS[h])
                plt.plot(x[s],(D[s,:,k*9+ii*3+2]<alpha).mean(1),
                    CLRS[ii],lw=LWS[ii],alpha=0.7)
                if k<5:
                    plt.plot(x[s],(D[s,:,k*9+ii*3+1]<alpha).mean(1),
                        CLRS[ii]+'--',alpha=0.7,lw=LWS[ii])
                    plt.plot(x[s],(D[s,:,k*9+ii*3]<alpha).mean(1),
                        CLRS[ii]+':',alpha=0.7,lw=LWS[ii])
            if not h: plt.ylabel(lblls[k])
            else:ax.set_yticklabels([])
            if k<K-1:ax.set_xticklabels([])
            else: plt.xlabel(cls[h])
            plt.ylim([-0.05,1.05])
            plt.xlim([x[0],x[-1]])
            plt.locator_params(axis='x', nbins=4)#,min_n_ticks=3)
    if FII>=0:
        fn='fig%02d.%s'%(FII,FIGFMT)
        FII+=1
    else: fn='ANOVA%d%d.png'%(i,j)
    plt.savefig(FIGDIR+fn,bbox_inches='tight',dpi=DPI,format=FIGFMT)
示例#13
0
def plotBFT(x,G,showLegend=False,alpha=0.05):
    plt.plot(x,np.median(G[:,:,0]/(1+G[:,:,0]),axis=1),CLRS[0],lw=LWS[0])
    plt.plot(x,np.median(G[:,:,1]/(1+G[:,:,1]),axis=1),CLRS[1],lw=LWS[1])
    if showLegend: plt.legend(['log Bayes t test','Bayes t test'],loc=3)