當前位置: 首頁>>代碼示例>>Python>>正文


Python Stats.doLogLikelihoodTest方法代碼示例

本文整理匯總了Python中CGAT.Stats.doLogLikelihoodTest方法的典型用法代碼示例。如果您正苦於以下問題:Python Stats.doLogLikelihoodTest方法的具體用法?Python Stats.doLogLikelihoodTest怎麽用?Python Stats.doLogLikelihoodTest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在CGAT.Stats的用法示例。


在下文中一共展示了Stats.doLogLikelihoodTest方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testLRT

# 需要導入模塊: from CGAT import Stats [as 別名]
# 或者: from CGAT.Stats import doLogLikelihoodTest [as 別名]
    def testLRT(self):
        """test that the false positive rate is in the same order as mSignificance.

        Sample from a normal distribution and compare two models:

        1. mean estimated = complex model (1 df)
        2. mean given     = simple model  (0 df)

        Likelihood = P(model | data)
        """
        simple_np = 0
        complex_np = 1

        npassed = 0

        for replicate in range(0, self.mNumReplicates):
            sample = scipy.stats.norm.rvs(
                size=self.mNumSamples, loc=0.0, scale=1.0)
            mean = scipy.mean(sample)

            complex_ll = numpy.sum(
                numpy.log(scipy.stats.norm.pdf(sample, loc=mean, scale=1.0)))
            simple_ll = numpy.sum(
                numpy.log(scipy.stats.norm.pdf(sample, loc=0.0, scale=1.0)))

            a = Stats.doLogLikelihoodTest(complex_ll, complex_np,
                                          simple_ll, simple_np,
                                          significance_threshold=self.mSignificance)

            if a.mPassed:
                npassed += 1

        r = float(npassed) / self.mNumReplicates

        self.assertAlmostEqual(self.mSignificance, r, places=self.nplaces)
開發者ID:lesheng,項目名稱:cgat,代碼行數:37,代碼來源:Stats_test.py

示例2: increased

# 需要導入模塊: from CGAT import Stats [as 別名]
# 或者: from CGAT.Stats import doLogLikelihoodTest [as 別名]
                if options.mode == "pairs":
                    reference_result = last_result
                    reference_id = x - 1
                elif options.mode == "1xn":
                    reference_result = first_result
                    reference_id = 0

                if reference_result.mNumParameters >= result.mNumParameters:
                    if options.loglevel >= 1:
                        options.stdlog.write("number of parameters of full model not increased (null=%i, full=%i).\n" % (
                            reference_result.mNumParameters, result.mNumParameters))
                    continue

                lrt = Stats.doLogLikelihoodTest(
                    result.mLogLikelihood, result.mNumParameters,
                    reference_result.mLogLikelihood, reference_result.mNumParameters,
                    options.significance_threshold)

                if lrt.mPassed:
                    c = "passed"
                else:
                    c = "failed"

                options.stdout.write("%s%i\t%i\t%s\t%f\t%i\t%f\t%i\t%5.2e\n" % (prefix_row, reference_id, x, c,
                                                                                lrt.mFullLogLikelihood, lrt.mFullNumParameters,
                                                                                lrt.mNullLogLikelihood, lrt.mNullNumParameters,
                                                                                lrt.mProbability,
                                                                                ))

                last_result = result
                x += 1
開發者ID:CGATOxford,項目名稱:Optic,代碼行數:33,代碼來源:codeml2tsv.py

示例3: main

# 需要導入模塊: from CGAT import Stats [as 別名]
# 或者: from CGAT.Stats import doLogLikelihoodTest [as 別名]

#.........這裏部分代碼省略.........
                h.append("df%s" % (model))
                h.append("chi%s" % (model))
                h.append("lrt%s" % (model))

            options.stdout.write("\t".join(h))
            options.stdout.write("\tcons\tpassed\tfilename\n")

            nmethod = 0

            consistent_cols = [None for x in range(len(options.analysis))]
            passed_tests = {}
            for m in options.models:
                passed_tests[m] = 0

            for result in results:

                row_consistent = None

                if options.prefix:
                    options.stdout.write("%s" % (options.prefix))

                options.stdout.write("%i" % nmethod)
                options.stdout.write("\t%i" % (result.mNumSequences))

                npassed = 0

                for model in options.models:

                    sites = result.mSites[model]

                    # do significance test
                    full_model, null_model = model, map_nested_models[model]

                    lrt = Stats.doLogLikelihoodTest(
                        result.mSites[full_model].mLogLikelihood,
                        result.mSites[full_model].mNumParameters,
                        result.mSites[null_model].mLogLikelihood,
                        result.mSites[null_model].mNumParameters,
                        options.significance_threshold)

                    x = 0
                    for analysis in options.analysis:

                        if analysis == "neb":
                            s = set(
                                map(extract_f, filter(filter_f, sites.mNEB.mPositiveSites)))

                        elif analysis == "beb":
                            s = set(
                                map(extract_f, filter(filter_f, sites.mBEB.mPositiveSites)))

                        options.stdout.write("\t%i" % (len(s)))

                        if not lrt.mPassed:
                            s = set()

                        if row_consistent is None:
                            row_consistent = s
                        else:
                            row_consistent = row_consistent.intersection(s)

                        if consistent_cols[x] is None:
                            consistent_cols[x] = s
                        else:
                            consistent_cols[x] = consistent_cols[
                                x].intersection(s)
開發者ID:Charlie-George,項目名稱:cgat,代碼行數:70,代碼來源:codemls2tsv.py

示例4: set

# 需要導入模塊: from CGAT import Stats [as 別名]
# 或者: from CGAT.Stats import doLogLikelihoodTest [as 別名]
                
                options.stdout.write("%i" % nmethod)
                options.stdout.write("\t%i" % (result.mNumSequences ))
                                         
                npassed = 0
                
                for model in options.models:

                    sites = result.mSites[model]

                    ## do significance test
                    full_model, null_model = model, map_nested_models[model]
                    
                    lrt = Stats.doLogLikelihoodTest(
                        result.mSites[full_model].mLogLikelihood, 
                        result.mSites[full_model].mNumParameters, 
                        result.mSites[null_model].mLogLikelihood, 
                        result.mSites[null_model].mNumParameters, 
                        options.significance_threshold )

                    x = 0
                    for analysis in options.analysis:
                        
                        if analysis == "neb":
                            s = set(map( extract_f, filter( filter_f, sites.mNEB.mPositiveSites)))
                            
                        elif analysis == "beb":
                            s = set(map( extract_f, filter( filter_f, sites.mBEB.mPositiveSites)))                            
                            
                        options.stdout.write("\t%i" % ( len(s) ) )

                        if not lrt.mPassed:
開發者ID:siping,項目名稱:cgat,代碼行數:34,代碼來源:codemls2tsv.py

示例5: float

# 需要導入模塊: from CGAT import Stats [as 別名]
# 或者: from CGAT.Stats import doLogLikelihoodTest [as 別名]
            lnl_simple = float(row['%s:lnL' % b])
            df_complex = map_model2params[a]
            df_simple = map_model2params[b]
            if options.loglevel >= 3:
                options.stdlog.write("# testing %s: ll=%f,df=%i versus %s:lnl=%f,df=%i\n" %\
                                         (a,
                                          lnl_complex,df_complex, 
                                          b, lnl_simple,
                                          df_simple))

            if lnl_complex < lnl_simple:
                nerrors += 1
                options.stdout.write( "\tna\tna" )
                continue

            lrt = Stats.doLogLikelihoodTest( lnl_complex, df_complex, lnl_simple, df_simple )
            if lrt.mPassed: stats[(a,b)] += 1
            
            options.stdout.write( "\t%s\t%5.2e" % (
                    Stats.getSignificance( lrt.mProbability), 
                    lrt.mProbability ) )
            
        options.stdout.write( "\n" )

        noutput += 1

    options.stdout.write( "npassed" )
    for a, b in tests:
        options.stdout.write( "\t%i\t%5.2f" % (stats[(a, b)], 100.0 * stats[(a,b)] / noutput ) )
    options.stdout.write( "\n" )
開發者ID:BioinformaticsArchive,項目名稱:cgat,代碼行數:32,代碼來源:xrate_tms_lrt.py


注:本文中的CGAT.Stats.doLogLikelihoodTest方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。