本文整理汇总了Python中CGAT.Stats.doChiSquaredTest方法的典型用法代码示例。如果您正苦于以下问题:Python Stats.doChiSquaredTest方法的具体用法?Python Stats.doChiSquaredTest怎么用?Python Stats.doChiSquaredTest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGAT.Stats
的用法示例。
在下文中一共展示了Stats.doChiSquaredTest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from CGAT import Stats [as 别名]
# 或者: from CGAT.Stats import doChiSquaredTest [as 别名]
#.........这里部分代码省略.........
if len(options.parameters) == 0:
raise "out of parameters - please supply probability or filename with probabilities."
param = options.parameters[0]
del options.parameters[0]
if options.write_separators:
probabilities = IOTools.ReadMap(
IOTools.openFile(param, "r"), map_functions=(str, float))
else:
probability = float(param)
for x in range(len(chunks) - 1):
ninput += 1
matrix, row_headers, col_headers = MatlabTools.readMatrix(
StringIO("".join(lines[chunks[x] + 1:chunks[x + 1]])),
format=options.input_format,
headers=options.headers)
nrows, ncols = matrix.shape
if options.loglevel >= 2:
options.stdlog.write("# read matrix: %i x %i, %i row titles, %i colum titles.\n" %
(nrows, ncols, len(row_headers), len(col_headers)))
if options.write_separators:
options.stdout.write(lines[chunks[x]][1:-1] + "\t")
pairs = []
if options.iteration == "pairwise":
pairs = []
for row1 in range(0, len(row_headers)):
for row2 in range(row1 + 1, len(row_headers)):
pairs.append((row1, row2))
elif options.iteration == "all-vs-all":
pairs = []
for row1 in range(0, len(row_headers)):
for row2 in range(0, len(row_headers)):
if row1 == row2:
continue
pairs.append((row1, row2))
if options.method == "chi-squared":
for row1, row2 in pairs:
row_header1 = row_headers[row1]
row_header2 = row_headers[row2]
try:
result = Stats.doChiSquaredTest(
numpy.vstack((matrix[row1], matrix[row2])))
except ValueError:
nskipped += 1
continue
noutput += 1
options.stdout.write("\t".join((
"%s" % row_header1,
"%s" % row_header2,
"%i" % result.mSampleSize,
"%i" % min(matrix.flat),
"%i" % max(matrix.flat),
options.value_format % result.mChiSquaredValue,
"%i" % result.mDegreesFreedom,
options.pvalue_format % result.mProbability,
"%s" % result.mSignificance,
options.value_format % result.mPhi)) + "\n")
elif options.method == "pearson-chi-squared":
if nrows != 2:
raise ValueError("only implemented for 2xn table")
if options.write_separators:
id = re.match("(\S+)", lines[chunks[x]][1:-1]).groups()[0]
probability = probabilities[id]
for col in range(ncols):
options.stdout.write("%s\t" % col_headers[col])
result = Stats.doPearsonChiSquaredTest(
probability, sum(matrix[:, col]), matrix[0, col])
options.stdout.write("\t".join((
"%i" % result.mSampleSize,
"%f" % probability,
"%i" % result.mObserved,
"%f" % result.mExpected,
options.value_format % result.mChiSquaredValue,
"%i" % result.mDegreesFreedom,
options.pvalue_format % result.mProbability,
"%s" % result.mSignificance,
options.value_format % result.mPhi)))
if col < ncols - 1:
options.stdout.write("\n")
if options.write_separators:
options.stdout.write(lines[chunks[x]][1:-1] + "\t")
options.stdout.write("\n")
E.info("# ninput=%i, noutput=%i, nskipped=%i\n" %
(ninput, noutput, nskipped))
E.Stop()
示例2: range
# 需要导入模块: from CGAT import Stats [as 别名]
# 或者: from CGAT.Stats import doChiSquaredTest [as 别名]
for row2 in range( row1+1, len(row_headers) ):
pairs.append( (row1, row2) )
elif options.iteration == "all-vs-all":
pairs = []
for row1 in range( 0, len(row_headers) ):
for row2 in range( 0, len(row_headers) ):
if row1 == row2: continue
pairs.append( (row1, row2) )
if options.method == "chi-squared":
for row1, row2 in pairs:
row_header1 = row_headers[row1]
row_header2 = row_headers[row2]
try:
result = Stats.doChiSquaredTest( numpy.vstack( (matrix[row1], matrix[row2] ) ) )
except ValueError:
nskipped += 1
continue
noutput += 1
options.stdout.write( "\t".join( ( "%s" % row_header1,
"%s" % row_header2,
"%i" % result.mSampleSize,
"%i" % min(matrix.flat),
"%i" % max(matrix.flat),
options.value_format % result.mChiSquaredValue,
"%i" % result.mDegreesFreedom,
options.pvalue_format % result.mProbability,
"%s" % result.mSignificance,
options.value_format % result.mPhi ) ) + "\n" )