コード例 #1
0
def two_sample_permu(X0, X1, SigLevel, nSim):
    import numpy as np
    from permustat import perm_t
    XTobs = perm_t.get_T(X0, X1)
    XTm = perm_t.get_Ts(X0, X1, nSim)

    PvalST = np.zeros((XTm.shape[0], XTm.shape[1]))
    for ii in range(XTm.shape[0]):
        for tt in range(XTm.shape[1]):
            a, b = np.histogram(XTm[ii, tt,:], bins=20)
            a = np.cumsum(a)/float(nSim) 
            if XTobs[ii, tt] < 0: 
                cutID = np.where(b < XTobs[ii, tt])[0]
                if len(cutID)>0 :    
                    PvalST[ii, tt] = a[cutID[-1]]
                else:
                    PvalST[ii, tt] = 0.0    
            else :  
                cutID = np.where(b >= XTobs[ii, tt])[0]
                if len(cutID)>0 and (cutID[0]<len(a)):     
                    PvalST[ii, tt] = 1.0 - a[cutID[0]]
                else:
                    PvalST[ii, tt] = 0.0

    SigST = 1.0 * (PvalST < (SigLevel/2))
    nSigS  = np.sum(SigST, axis=0)  
    nSigT  = np.sum(SigST, axis=1)  
    statOut = {'Obs':XTobs,'Pval':PvalST,'Sig':SigST,'nSigS':nSigS,'nSigT':nSigT} #,'XTm':XTm}
    
    return statOut #[XTobs, PvalST, SigST, XTm, nSig, nSigT]


#    from scipy.stats import norm
#    Xstd = np.std(X, axis=2)
##        XT = Xmean / Xstd  
#    XT = np.sqrt(nX) * Xmean / Xstd  
##        ut = t.isf(SigLevel/2, nX-1, 0, 1)   
#    ut = norm.isf(SigLevel/2, 0, 1)   
#    
#    Tvector = XT.reshape((nSpaces*nSamples,1))
#    mu = np.mean(Tvector)
#    sig = np.std(Tvector)
#    vu = mu + ut * sig
#    vl = mu - ut * sig
#     
#    uu = (Tvector > vu ) 
#    ll = (Tvector < vl ) 
#    eee = uu + ll 
#    eee = eee.reshape((nSpaces, nSamples))
#    SigST = 1. * eee
    

    
コード例 #2
0
def two_sample_t(X0, X1, SigLevel):
    from scipy.stats import t 
    import numpy as np
    from permustat import perm_t
    
    XT = perm_t.get_T(X0, X1)
    PvalST = np.zeros(XT.shape)
    for ii in range(XT.shape[0]): 
        for jj in range(XT.shape[1]):
            temp = 1-t.cdf(XT[ii,jj], X0.shape[2] + X1.shape[2]-2)
            if temp > 0.5 : 
                PvalST[ii, jj] = 1 - temp
            else: 
                PvalST[ii, jj] = temp
                
    SigST = 1.0 * (PvalST < SigLevel/2)
    nSigS  = np.sum(SigST, axis=0) 
    nSigT  = np.sum(SigST, axis=1) 
    statOut = {'T':XT,'Pval':PvalST,'Sig':SigST,'nSigS':nSigS,'nSigT':nSigT} 

    return statOut #[XT, PvalST, SigST, nSig, nSigT]