我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用scipy.stats.wilcoxon()。
def significance(metric): if not args.significance: return {} desc, rank = sorted(results.items(), key=lambda item: item[1][metric], reverse=True), 1 ranks = {} for (path1, results1), (path2, results2) in pairwise(desc): x, y = list(results1['scores'][metric]), list(results2['scores'][metric]) ranks[path1] = rank rank += int(wilcoxon(x, y).pvalue < args.alpha) ranks[path2] = rank return ranks
def score_event(nx, ny, ncommon, barcode_frequencies, resamples=100): """ perform a resampling test, based on the number of fragments in each region and the barcode frequency distribution (the latter because some barcodes have more DNA in them than others) """ samples = [] for _ in range(resamples): s1 = numpy.random.choice(len(barcode_frequencies), nx, replace=False, p=barcode_frequencies) s2 = numpy.random.choice(len(barcode_frequencies), ny, replace=False, p=barcode_frequencies) common = len(set(s1).intersection(set(s2))) samples.append(common) # make a one-sided one-sample Wilcoxon test statistic, pvalue = stats.wilcoxon(numpy.array(samples)-ncommon) if numpy.mean(samples) > ncommon: pvalue = 1 - pvalue/2.0 else: pvalue = pvalue/2.0 # result = r["wilcox.test"](samples, mu=ncommon, alternative="less") # pvalue2 = result.rx2("p.value")[0] # print "::::::", nx, ny, ncommon, (numpy.array(samples)>ncommon).sum(), pvalue, pvalue2 return pvalue
def _evalstat(x, bsl, meth, n_perm, metric, maxstat, tail): """Statistical evaluation of features [x] = [xn] = (nFce, npts, nTrials) [bsl] = (nFce, nTrials) """ # Get shape of xF : nf, npts, nt = x.shape pvalues = np.ones((nf, npts)) # Permutations : if meth == 'permutation': perm = perm_swaparray(a, b, n_perm=200, axis=-1, rndstate=0) from brainpipe.xPOO.stats import permutation # Pre-define permutations : pObj = permutation(n_perm) perm = np.zeros((n_perm, nf, npts)) # For each permutation : for p in range(n_perm): # Get 1D iterations : ite = product(range(nf), range(npts)) permT = np.random.permutation(2*nt) for f, pts in ite: bs, xs = bsl[f, :], x[f, pts, :] # Reshape data : subX = np.vstack((bsl[f, :], x[f, pts, :])).reshape(2*nt,) # Shuffle data : subX = subX[permT].reshape(nt, 2) # Normalize data : subX = normalize(subX[:, 0], subX[:, 1], norm=norm) # Get mean of data : perm[p, f, pts] = np.mean(subX) # Get final pvalues : pvalues = pObj.perm2p(np.mean(xn, 2), perm, tail=tail, maxstat=maxstat) # Wilcoxon test : elif meth == 'wilcoxon': from scipy.stats import wilcoxon # Get iterations : ite = product(range(nf), range(npts)) # Compute wilcoxon : for k, i in ite: _, pvalues[k, i] = wilcoxon(x[k, i, :], bsl[k, :]) # Kruskal-Wallis : elif meth == 'kruskal': from scipy.stats import kruskal # Get iterations : ite = product(range(nf), range(npts)) # Compute Kruskal-Wallis : for k, i in ite: _, pvalues[k, i] = kruskal(x[k, i, :], bsl[k, :]) return pvalues