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()
def plotBrief(x,R,y=np.nan,pref='', ylim=[[],[]]): global FII figure(size=2,aspect=1.2) for f in range(1,7): ax=subplot(3,2,f); plt.grid(axis='x') plt.ylim([-0.02,1.02]) plt.title(['CI','Cohen\'s $d$','TOST','Bayesian $t$ test','Two-group tests','Three-group tests'][f-1]) if f==1: plotCI(x,R) #if np.any(~np.isnan(y)): plt.plot(x,y,'c') plt.ylim(ylim[0]) elif f==2: plotCohendCI(x,R) plt.ylim(ylim[1]) elif f==3: plotTOST(x,R[:,:,12:16]) elif f==4: plotBFT(x,R[:,:,16:18]) elif f==5: plotNHST(x,R[:,:,8:12]) elif f==6: plotANOVA1F(x,R[:,:,18:21]) if f<5: ax.set_xticklabels([]) else: plt.xlabel(['$c_l$','$b$'][int(pref=='W')]) plt.xlim([x[0],x[-1]]) if FII>=0: fn='fig%02d.%s'%(FII,FIGFMT) FII+=1 else: fn=pref+'brief.png' plt.savefig(FIGDIR+fn,dpi=DPI,bbox_inches='tight',format=FIGFMT)
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)
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()
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)