def wilcoxon(x,y=None): """ Calculates the Wilcoxon signed-rank test for the null hypothesis that two samples come from the same distribution. A non-parametric T-test. (need N > 20) Returns: t-statistic, two-tailed p-value """ if y is None: d = x else: x, y = map(asarray, (x, y)) if len(x) <> len(y): raise ValueError, 'Unequal N in wilcoxon. Aborting.' d = x-y d = compress(not_equal(d,0),d) # Keep all non-zero differences count = len(d) if (count < 10): print "Warning: sample size too small for normal approximation." r = stats.rankdata(abs(d)) r_plus = sum((d > 0)*r) r_minus = sum((d < 0)*r) T = min(r_plus, r_minus) mn = count*(count+1.0)*0.25 se = math.sqrt(count*(count+1)*(2*count+1.0)/24) if (len(r) != len(unique(r))): # handle ties in data replist, repnum = find_repeats(r) corr = 0.0 for i in range(len(replist)): si = repnum[i] corr += 0.5*si*(si*si-1.0) V = se*se - corr se = sqrt((count*V - T*T)/(count-1.0)) z = (T - mn)/se prob = 2*(1.0 -stats.zprob(abs(z))) return T, prob
def _make_complex_eigvecs(w,vin,cmplx_tcode): v = scipy_base.array(vin,typecode=cmplx_tcode) ind = scipy_base.nonzero(scipy_base.not_equal(w.imag,0.0)) vnew = scipy_base.zeros((v.shape[0],len(ind)>>1),cmplx_tcode) vnew.real = scipy_base.take(vin,ind[::2],1) vnew.imag = scipy_base.take(vin,ind[1::2],1) count = 0 conj = scipy_base.conjugate for i in range(len(ind)/2): v[:,ind[2*i]] = vnew[:,count] v[:,ind[2*i+1]] = conj(vnew[:,count]) count += 1 return v