예제 #1
0
def PlotTTest2(XStart, XStop, Samp1, Samp2, Cov, PThr):
    FileName1=os.path.split(Samp1)[1]
    FileName1=os.path.splitext(FileName1)[0]
    FileName2=os.path.split(Samp2)[1]
    FileName2=os.path.splitext(FileName2)[0]
    
    Samp1=Read(Samp1)
    Samp2=Read(Samp2)

    if Cov is not None:
        Cov=Read(Cov)
        if len(Cov.shape)==1:
            Cov=Cov[:,np.newaxis]

    Mean1=Samp1.mean(axis=0)
    Mean2=Samp2.mean(axis=0)

    delta=(XStop-XStart)/(Mean1.shape[0]-1)
    if delta!=0:
        X=np.arange(XStart, XStop+0.5*delta, delta)
    else:
        delta=1
        XStart=1
        XStop=Mean1.shape[0]
        X=np.arange(Mean1.shape[0])

    Ymax=np.max([Mean1, Mean2])
    Ymin=np.min([Mean1, Mean2])
    Ylimit=Ymax-Ymin
    plt.ylim(Ymin-0.1*Ylimit, Ymax+0.5*Ylimit)
    plt.xlim(XStart-delta, XStop+delta)

    if PThr==0:
        Leg1, Leg2=plt.plot(X, Mean1, 'kx-', 
                X, Mean2, 'kx--')
        plt.legend((Leg1,Leg2),
            (FileName1, FileName2))
    else:
        P=np.zeros_like(Mean1, dtype="bool")
        for i in range(len(P)):
            P[i]=ttest2(Samp1[i,:], Samp2[i,:], Cov)<PThr
        if any(P==0):
            Leg1, Leg2=plt.plot(X, Mean1, 'kx-', 
                    X, Mean2, 'kx--')
            plt.legend((Leg1,Leg2),
                (FileName1, FileName2))
        else:
            YStar=np.max([Mean1, Mean2], axis=0)
            XStar=X
            YStar=YStar[P]
            XStar=XStar[P]

            Leg1, Leg2, Leg3=plt.plot(X, Mean1, 'kx-', 
                    X, Mean2, 'kx--',
                    XStar, YStar, 'ks')
            plt.legend((Leg1,Leg2,Leg3),
                (FileName1, FileName2, 'p < %s' % str(PThr)))

    plt.show()
예제 #2
0
def PlotCorr(Samp1, Samp2, Cov, PThr): 
    FileName1=os.path.split(Samp1)[1]
    FileName1=os.path.splitext(FileName1)[0]
    FileName2=os.path.split(Samp2)[1]
    FileName2=os.path.splitext(FileName2)[0]
    
    Samp1=Read(Samp1)
    Samp2=Read(Samp2)

    if Cov is not None:
        Cov=Read(Cov)
        if len(Cov.shape)==1:
            Cov=Cov[:,np.newaxis]
        Cov=np.concatenate(
                (Cov, np.ones_like(Samp1)), axis=1)
        b, Samp1, SSE=regress(Samp1, Cov)
        b, Samp2, SSE=regress(Samp2, Cov)

    b, intercept=np.polyfit(Samp1, Samp2, 1)
    r=np.corrcoef(Samp1, Samp2)[0,1]

    Line=b*Samp1+intercept

    Xmax=Samp1.max()
    Xmin=Samp1.min()
    Ymax=np.max([Samp2, Line])
    Ymin=np.min([Samp2, Line])
    Xlimit=Xmax-Xmin
    Ylimit=Ymax-Ymin

    plt.plot(Samp1, Samp2, 'kx', 
        Samp1, Line, 'k-')
    func="y=%.2fx+%.2f, r=%.2f" % (b, intercept, r)
    plt.text(Xmax-0.2*Xlimit, Ymax+0.05*Ylimit,
            '$%s$' % func)

    plt.xlim(Xmin-0.1*Xlimit, Xmax+0.3*Xlimit)
    plt.ylim(Ymin-0.1*Ylimit, Ymax+0.3*Ylimit)
    plt.xlabel("X (Sample 1)")
    plt.ylabel("Y (Sample 2)")

    plt.show()