コード例 #1
0
for j in range(nCategory):
    for i in range(nTrials):
        if (trialsName[i] == categoryName[j]):
            whichCat[i,j] = 1
whichCat = np.array(whichCat, dtype='i')
 
 
catName1 = categoryName[0]; catName2 = categoryName[1] ;
print('Two sample T-test: %s vs %s' %(catName1, catName2)) 
X1 = s[:,:, (whichCat[:,0]>0)]; X2 = s[:,:, (whichCat[:,1]>0)];        

nX1 = X1.shape[2]
SigLevel = 0.05     

XMean1 = np.mean(X1, axis=2); XSigma1 = np.std(X1, axis=2);
statOut1 = permustat_fun.one_sample_t(X1, SigLevel/2) 

Gfp1 = np.std(XMean1,axis=0) 
fig = plt.figure()
plt.plot(msSamples, Gfp1)
plt.axvline(43, color='black', lw=2)

fig = plt.figure()
plt.imshow(statOut1['Sig']) 

tsid = np.where(msSamples == 43)[0]
statOut1['Sig'][:, tsid]

up = XMean1[:, tsid] + 3* XSigma1[:, tsid] / np.sqrt(nX1)
bt = XMean1[:, tsid] - 3* XSigma1[:, tsid] / np.sqrt(nX1)
コード例 #2
0
ファイル: PermuStat.py プロジェクト: jesong1126/PermuStat
    def pbRunStat_Callback(self):
        import numpy as np
        import config
        from permustat import permustat_fun, perm_plot

        msSamples = config.msSamples
        s = config.s
        sden = config.sden
        categoryName = config.categoryName
        whichCat = config.whichCat
        nCategory = config.nCategory

        #---------------------------------------------------------------------
        SigLevel = self.editSigLevel.text()
        SigLevel = float(SigLevel)
        print("Significant level is %3.2f" % SigLevel)

        NumSim = self.editNumSim.text()
        NumSim = int(NumSim)

        if self.rbPara.isChecked():
            config.ParaVal = 0
            print("Parametric is selected")
        else:
            config.ParaVal = 1
            print("Non-Parametric is selected and Num Sim is %d" % NumSim)

        ##---------------------------------------------------------------------
        if self.rbOneT.isChecked():
            catName = categoryName[config.OneTCatVal]
            print("One sample T-test:%s" % catName)
            if self.rbScalp.isChecked():
                X = s[:, :, (whichCat[:, config.OneTCatVal] > 0)]
            else:
                X = sden[:, :, (whichCat[:, config.OneTCatVal] > 0)]
            XMean = np.mean(X, axis=2)
            XSigma = np.std(X, axis=2)
            statOut = permustat_fun.one_sample_t(X, SigLevel)
            perm_plot.oneT(XMean, XSigma, statOut['T'], statOut['nSigS'],
                           catName, msSamples)
            config.Stat = statOut['T']

        elif self.rbTwoT.isChecked():
            catName1 = categoryName[config.TwoTCatVal1]
            catName2 = categoryName[config.TwoTCatVal2]
            print('Two sample T-test: %s vs %s' % (catName1, catName2))
            if self.rbScalp.isChecked():
                X1 = s[:, :, (whichCat[:, config.TwoTCatVal1] > 0)]
                X2 = s[:, :, (whichCat[:, config.TwoTCatVal2] > 0)]
            else:
                X1 = sden[:, :, (whichCat[:, config.TwoTCatVal1] > 0)]
                X2 = sden[:, :, (whichCat[:, config.TwoTCatVal2] > 0)]

            XMean1 = np.mean(X1, axis=2)
            XSigma1 = np.std(X1, axis=2)
            XMean2 = np.mean(X2, axis=2)
            XSigma2 = np.std(X2, axis=2)
            statOut1 = permustat_fun.one_sample_t(X1, SigLevel / 2)
            statOut2 = permustat_fun.one_sample_t(X2, SigLevel / 2)

            if self.rbPara.isChecked():
                statOut = permustat_fun.two_sample_t(X1, X2, SigLevel)
                perm_plot.twoT(XMean1, XSigma1, statOut1['T'],
                               statOut1['nSigS'], catName1, XMean2, XSigma2,
                               statOut2['T'], statOut2['nSigS'], catName2,
                               statOut['T'], statOut['nSigS'], msSamples)
            else:
                statOut = permustat_fun.two_sample_permu(
                    X1, X2, SigLevel / 2, NumSim)
                logPvalST = np.log(statOut['Pval'])
                perm_plot.permT(statOut['T'], logPvalST, msSamples)

            config.Stat = statOut['T']

        elif self.rbPairT.isChecked():
            catName1 = categoryName[config.PairTCatVal1]
            catName2 = categoryName[config.PairTCatVal2]
            print('Pair T-test: %s vs %s' % (catName1, catName2))
            if self.rbScalp.isChecked():
                X1 = s[:, :, (whichCat[:, config.PairTCatVal1] > 0)]
                X2 = s[:, :, (whichCat[:, config.PairTCatVal2] > 0)]
            else:
                X1 = sden[:, :, (whichCat[:, config.PairTCatVal1] > 0)]
                X2 = sden[:, :, (whichCat[:, config.PairTCatVal2] > 0)]

            XMean1 = np.mean(X1, axis=2)
            XSigma1 = np.std(X1, axis=2)
            XMean2 = np.mean(X2, axis=2)
            XSigma2 = np.std(X2, axis=2)
            statOut1 = permustat_fun.one_sample_t(X1, SigLevel / 2)
            statOut2 = permustat_fun.one_sample_t(X2, SigLevel / 2)

            if self.rbPara.isChecked():
                statOut = permustat_fun.pairt(X1, X2, SigLevel)
                perm_plot.pairT(XMean1, XSigma1, statOut1['T'],
                                statOut1['nSigS'], catName1, XMean2, XSigma2,
                                statOut2['T'], statOut2['nSigS'], catName2,
                                statOut['T'], statOut['nSigS'], msSamples)
            else:
                statOut = permustat_fun.pairt_permu(X1, X2, SigLevel / 2,
                                                    NumSim)
                logPvalST = np.log(statOut['Pval'])
                perm_plot.permPairT(statOut['T'], logPvalST, msSamples)

            config.Stat = statOut['T']

        elif self.rbAnova.isChecked():
            if self.rbScalp.isChecked():
                statOut = permustat_fun.anova_f(s, whichCat, nCategory,
                                                SigLevel)
            else:
                statOut = permustat_fun.anova_f(sden, whichCat, nCategory,
                                                SigLevel)
            perm_plot.anova(statOut['F'], statOut['Pval'], statOut['Sig'],
                            msSamples)
            config.Stat = statOut['F']

        config.Pval = statOut['Pval']
        config.Sig = statOut['Sig']
        config.StatOut = statOut

        return statOut
コード例 #3
0
ファイル: PermuStat.py プロジェクト: jesong1126/PermuStat
    def pbRunStat_Callback(self):        
        import numpy as np 
        import config 
        from permustat import permustat_fun, perm_plot 

        msSamples = config.msSamples
        s = config.s
        sden = config.sden
        categoryName = config.categoryName
        whichCat = config.whichCat 
        nCategory = config.nCategory
        
        #---------------------------------------------------------------------                
        SigLevel = self.editSigLevel.text()
        SigLevel = float(SigLevel)
        print("Significant level is %3.2f" %SigLevel)      

        NumSim = self.editNumSim.text()
        NumSim = int(NumSim)
         
        if self.rbPara.isChecked():
            config.ParaVal = 0
            print("Parametric is selected")
        else:
            config.ParaVal = 1
            print("Non-Parametric is selected and Num Sim is %d" %NumSim)      

        ##---------------------------------------------------------------------
        if self.rbOneT.isChecked():
            catName = categoryName[config.OneTCatVal] 
            print("One sample T-test:%s" %catName)
            if self.rbScalp.isChecked():
                X = s[:,:, (whichCat[:, config.OneTCatVal]>0)]        
            else: 
                X = sden[:,:, (whichCat[:, config.OneTCatVal]>0)]    
            XMean = np.mean(X, axis=2)
            XSigma = np.std(X, axis=2)   
            statOut = permustat_fun.one_sample_t(X, SigLevel)         
            perm_plot.oneT(XMean, XSigma, statOut['T'], statOut['nSigS'], catName, msSamples)
            config.Stat = statOut['T']                  

        elif self.rbTwoT.isChecked():
            catName1 = categoryName[config.TwoTCatVal1]
            catName2 = categoryName[config.TwoTCatVal2]
            print('Two sample T-test: %s vs %s' %(catName1, catName2)) 
            if self.rbScalp.isChecked():
                X1 = s[:,:, (whichCat[:, config.TwoTCatVal1]>0)]        
                X2 = s[:,:, (whichCat[:, config.TwoTCatVal2]>0)]        
            else: 
                X1 = sden[:,:, (whichCat[:, config.TwoTCatVal1]>0)]        
                X2 = sden[:,:, (whichCat[:, config.TwoTCatVal2]>0)]        
                
            XMean1 = np.mean(X1, axis=2); XSigma1 = np.std(X1, axis=2);
            XMean2 = np.mean(X2, axis=2); XSigma2 = np.std(X2, axis=2);   
            statOut1 = permustat_fun.one_sample_t(X1, SigLevel/2) 
            statOut2 = permustat_fun.one_sample_t(X2, SigLevel/2) 
            
            if self.rbPara.isChecked():
                statOut = permustat_fun.two_sample_t(X1, X2, SigLevel) 
                perm_plot.twoT(XMean1, XSigma1, statOut1['T'], statOut1['nSigS'], catName1, 
                               XMean2, XSigma2, statOut2['T'], statOut2['nSigS'], catName2, statOut['T'], statOut['nSigS'], msSamples)
            else:
                statOut = permustat_fun.two_sample_permu(X1, X2, SigLevel/2, NumSim)
                logPvalST = np.log(statOut['Pval'])
                perm_plot.permT(statOut['T'], logPvalST, msSamples) 
            
            config.Stat = statOut['T']                  

        elif self.rbPairT.isChecked():
            catName1 = categoryName[config.PairTCatVal1]
            catName2 = categoryName[config.PairTCatVal2]
            print('Pair T-test: %s vs %s' %(catName1, catName2)) 
            if self.rbScalp.isChecked():
                X1 = s[:,:, (whichCat[:, config.PairTCatVal1]>0)]        
                X2 = s[:,:, (whichCat[:, config.PairTCatVal2]>0)]        
            else: 
                X1 = sden[:,:, (whichCat[:, config.PairTCatVal1]>0)]        
                X2 = sden[:,:, (whichCat[:, config.PairTCatVal2]>0)]        
            
            XMean1 = np.mean(X1, axis=2); XSigma1 = np.std(X1, axis=2);
            XMean2 = np.mean(X2, axis=2); XSigma2 = np.std(X2, axis=2);   
            statOut1 = permustat_fun.one_sample_t(X1, SigLevel/2) 
            statOut2 = permustat_fun.one_sample_t(X2, SigLevel/2) 
                
            if self.rbPara.isChecked():
                statOut = permustat_fun.pairt(X1, X2, SigLevel) 
                perm_plot.pairT(XMean1, XSigma1, statOut1['T'], statOut1['nSigS'], catName1, 
                               XMean2, XSigma2, statOut2['T'], statOut2['nSigS'], catName2, statOut['T'], statOut['nSigS'], msSamples)
            else:
                statOut = permustat_fun.pairt_permu(X1, X2, SigLevel/2, NumSim)
                logPvalST = np.log(statOut['Pval'])
                perm_plot.permPairT(statOut['T'], logPvalST, msSamples) 
            
            config.Stat = statOut['T']                  
            
        elif self.rbAnova.isChecked():
            if self.rbScalp.isChecked():
                statOut = permustat_fun.anova_f(s, whichCat, nCategory, SigLevel)
            else: 
                statOut = permustat_fun.anova_f(sden, whichCat, nCategory, SigLevel)
            perm_plot.anova(statOut['F'], statOut['Pval'], statOut['Sig'], msSamples)              
            config.Stat = statOut['F']

        config.Pval = statOut['Pval']  
        config.Sig = statOut['Sig'] 
        config.StatOut = statOut

        return statOut
コード例 #4
0
        if (trialsName[i] == categoryName[j]):
            whichCat[i, j] = 1
whichCat = np.array(whichCat, dtype='i')

catName1 = categoryName[0]
catName2 = categoryName[1]
print('Two sample T-test: %s vs %s' % (catName1, catName2))
X1 = s[:, :, (whichCat[:, 0] > 0)]
X2 = s[:, :, (whichCat[:, 1] > 0)]

nX1 = X1.shape[2]
SigLevel = 0.05

XMean1 = np.mean(X1, axis=2)
XSigma1 = np.std(X1, axis=2)
statOut1 = permustat_fun.one_sample_t(X1, SigLevel / 2)

Gfp1 = np.std(XMean1, axis=0)
fig = plt.figure()
plt.plot(msSamples, Gfp1)
plt.axvline(43, color='black', lw=2)

fig = plt.figure()
plt.imshow(statOut1['Sig'])

tsid = np.where(msSamples == 43)[0]
statOut1['Sig'][:, tsid]

up = XMean1[:, tsid] + 3 * XSigma1[:, tsid] / np.sqrt(nX1)
bt = XMean1[:, tsid] - 3 * XSigma1[:, tsid] / np.sqrt(nX1)