当前位置: 首页>>代码示例>>Python>>正文


Python Stats.getSignificance方法代码示例

本文整理汇总了Python中CGAT.Stats.getSignificance方法的典型用法代码示例。如果您正苦于以下问题:Python Stats.getSignificance方法的具体用法?Python Stats.getSignificance怎么用?Python Stats.getSignificance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CGAT.Stats的用法示例。


在下文中一共展示了Stats.getSignificance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from CGAT import Stats [as 别名]
# 或者: from CGAT.Stats import getSignificance [as 别名]

#.........这里部分代码省略.........
    ## read data matrix
    if options.input_filename:
        lines = open(options.input_filename, "r").readlines()
    else:
        ## note: this will not work for interactive viewing, but
        ## creating hardcopy plots works.
        lines = sys.stdin.readlines()

    lines = filter( lambda x: x[0] != "#", lines)
    
    if len(lines) == 0:
        if options.fail_on_empty:
            raise IOError ( "no input" )
        E.warn( "empty input" )
        E.Stop()
        return

    matrix, headers, colours, legend = readTable( lines,
                                                  "matrix",
                                                  take_columns = options.columns,
                                                  headers=True,
                                                  colours=options.colours,
                                                  row_names = options.legend )

    if options.input_filename2:
        ## read another matrix (should be of the same format.
        matrix2, headers2, colours2, legend2 = readTable( lines,
                                                 "matrix2",
                                                 take_columns = options.columns,
                                                 headers=True,
                                                 colours=options.colours,
                                                 row_names = options.legend )
    R.assign("headers", headers)

    ndata = R( """length( matrix[,1] )""" )[0]

    if options.loglevel >=1:
        options.stdlog.write("# read matrix: %ix%i\n" % (len(headers),ndata) )

    if colours:
        R.assign("colours", colours)

    for method in options.statistics:

        if method == "correlation":
            cor = R.cor(matrix, use="pairwise.complete.obs" )
            writeMatrix( sys.stdout, cor, headers=headers, format = "%5.2f" )

        elif method == "pearson":
            options.stdout.write( "\t".join( ("var1", 
                                              "var2",
                                              "coeff",
                                              "passed",
                                              "pvalue",
                                              "n",
                                              "method",
                                              "alternative" )) + "\n" )
            for x in range(len(headers)-1):
                for y in range( x+1, len(headers)):
                    try:
                        result = R("""cor.test( matrix[,%i], matrix[,%i] )""" % (x + 1, y + 1))
                    except rpy.RPyException, msg:
                        E.warn( "correlation not computed for columns %i(%s) and %i(%s): %s" % (x, headers[x], y, headers[y], msg) )
                        options.stdout.write( "%s\t%s\t%s\t%s\t%s\t%i\t%s\t%s\n" % \
                                                  (headers[x], headers[y],
                                                   "na",
                                                   "na",
                                                   "na",
                                                   0,
                                                   "na",
                                                   "na" ))

                    else:
                        options.stdout.write( "%s\t%s\t%6.4f\t%s\t%e\t%i\t%s\t%s\n" % \
                                                  (headers[x], headers[y],
                                                   result.rx2('estimate').rx2('cor')[0], 
                                                   Stats.getSignificance( float(result.rx2('p.value')[0]) ),
                                                   result.rx2('p.value')[0],
                                                   result.rx2('parameter').rx2('df')[0],
                                                   result.rx2('method')[0], 
                                                   result.rx2('alternative')[0]) )

        elif method == "spearman":
            options.stdout.write( "\t".join( ("var1", "var2",
                                              "coeff",
                                              "passed",
                                              "pvalue",
                                              "method",
                                              "alternative" )) + "\n" )
            for x in range(len(headers)-1):
                for y in range( x+1, len(headers)):
                    result = R("""cor.test( matrix[,%i], matrix[,%i], method='spearman' )""" % (x + 1, y + 1))
                    options.stdout.write( "%s\t%s\t%6.4f\t%s\t%e\t%i\t%s\t%s\n" % \
                                              (headers[x], headers[y],
                                               result['estimate']['rho'], 
                                               Stats.getSignificance( float(result['p.value']) ),
                                               result['p.value'],
                                               result['parameter']['df'],
                                               result['method'], 
                                               result['alternative']))
开发者ID:BioinformaticsArchive,项目名称:cgat,代码行数:104,代码来源:r_table2scatter.py

示例2: main

# 需要导入模块: from CGAT import Stats [as 别名]
# 或者: from CGAT.Stats import getSignificance [as 别名]

#.........这里部分代码省略.........

        elif method == "pearson":
            options.stdout.write("\t".join(("var1",
                                            "var2",
                                            "coeff",
                                            "passed",
                                            "pvalue",
                                            "n",
                                            "method",
                                            "alternative")) + "\n")
            for x in range(len(headers) - 1):
                for y in range(x + 1, len(headers)):
                    try:
                        result = R(
                            """cor.test( matrix[,%i], matrix[,%i] )""" % (x + 1, y + 1))
                    except rpy.RPyException as msg:
                        E.warn("correlation not computed for columns %i(%s) and %i(%s): %s" % (
                            x, headers[x], y, headers[y], msg))
                        options.stdout.write("%s\t%s\t%s\t%s\t%s\t%i\t%s\t%s\n" %
                                             (headers[x], headers[y],
                                              "na",
                                              "na",
                                              "na",
                                              0,
                                              "na",
                                              "na"))

                    else:
                        options.stdout.write(
                            "%s\t%s\t%6.4f\t%s\t%e\t%i\t%s\t%s\n" %
                            (headers[x], headers[y],
                             result.rx2('estimate').rx2(
                                 'cor')[0],
                             Stats.getSignificance(
                                 float(result.rx2('p.value')[0])),
                             result.rx2('p.value')[0],
                             result.rx2('parameter').rx2(
                                 'df')[0],
                             result.rx2('method')[0],
                             result.rx2('alternative')[0]))

        elif method == "spearman":
            options.stdout.write("\t".join(("var1", "var2",
                                            "coeff",
                                            "passed",
                                            "pvalue",
                                            "method",
                                            "alternative")) + "\n")
            for x in range(len(headers) - 1):
                for y in range(x + 1, len(headers)):
                    result = R(
                        """cor.test( matrix[,%i], matrix[,%i], method='spearman')""" % (x + 1, y + 1))
                    options.stdout.write(
                        "%s\t%s\t%6.4f\t%s\t%e\t%i\t%s\t%s\n" %
                        (headers[x], headers[y],
                         result['estimate']['rho'],
                         Stats.getSignificance(float(result['p.value'])),
                         result['p.value'],
                         result['parameter']['df'],
                         result['method'],
                         result['alternative']))

        elif method == "count":
            # number of shared elements > threshold
            m, r, c = MatlabTools.ReadMatrix(open(options.input_filename, "r"),
                                             take=options.columns,
开发者ID:CGATOxford,项目名称:cgat,代码行数:70,代码来源:r_table2scatter.py

示例3: open

# 需要导入模块: from CGAT import Stats [as 别名]
# 或者: from CGAT.Stats import getSignificance [as 别名]
                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" )

    if options.filename_graph:
        outfile = open( options.filename_graph, 'w' )
        for a, b in tests:
            outfile.write( "%s\t%s\t%i\t%5.2f\n" % (a, b, stats[(a, b)], 100.0 * stats[(a,b)] / noutput ) )
开发者ID:BioinformaticsArchive,项目名称:cgat,代码行数:33,代码来源:xrate_tms_lrt.py


注:本文中的CGAT.Stats.getSignificance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。