def pearson_correlation(v1,v2): try: pc= stats.pearsonr(v1,v2)[0] except : pc= -1 return (pc+1.0)/2.0
def signs(self): """Calculates signs of correlation coefficients between a child and its parents """ res={} for i,p in enumerate(self.parents): try: sign = stats.pearsonr(self.data[i],self.data[-1])[0] except ValueError: print self.data[i],self.data[-1] if sign >=0: res[p]="+" else: res[p]="-" return res
def pearson_correlation(v1,v2): '''>>> v1=[0,10,10,0,10] >>> v2=[10,0,0,10,0] >>> pearson_correlation(v1,v2) 0.0 >>> v2=v1 >>> pearson_correlation(v1,v2) 1.0 >>> v2=[0,10,0,10,0] >>> pearson_correlation(v1,v2) 0.41666666666666669 ''' try: pc= stats.pearsonr(v1,v2)[0] except : pc= -1 return (pc+1.0)/2.0
def pearson_correlation(v1, v2): '''>>> v1=[0,10,10,0,10] >>> v2=[10,0,0,10,0] >>> pearson_correlation(v1,v2) 0.0 >>> v2=v1 >>> pearson_correlation(v1,v2) 1.0 >>> v2=[0,10,0,10,0] >>> pearson_correlation(v1,v2) 0.41666666666666669 ''' try: pc = stats.pearsonr(v1, v2)[0] except: pc = -1 return (pc + 1.0) / 2.0
def tempfunc(lmbda, xvals, samps): y = boxcox(samps,lmbda) yvals = sort(y) r, prob = stats.pearsonr(xvals, yvals) return 1-r
def tempfunc(shape, mi, yvals, func): xvals = func(mi, shape) r, prob = stats.pearsonr(xvals, yvals) return 1-r
aa = N.array(ll) m = range(4,24) m[10] = 34 b = N.array(m) pb = [0]*9 + [1]*11 apb = N.array(pb) print('paired:') # stats.paired(l,m) # stats.paired(a,b) print(print) print('pearsonr:') print(stats.pearsonr(l,m)) print(stats.pearsonr(a,b)) print('spearmanr:') print(stats.spearmanr(l,m)) print(stats.spearmanr(a,b)) print('pointbiserialr:') print(stats.pointbiserialr(pb,l)) print(stats.pointbiserialr(apb,a)) print('kendalltau:') print(stats.kendalltau(l,m)) print(stats.kendalltau(a,b)) print('linregress:') print(stats.linregress(l,m)) print(stats.linregress(a,b)) print('\nINFERENTIAL') print('ttest_1samp:')
m = range(4,24) m[10] = 34 b = N.array(m) pb = [0]*9 + [1]*11 apb = N.array(pb) print 'paired:' #stats.paired(l,m) #stats.paired(a,b) print print print 'pearsonr:' print stats.pearsonr(l,m) print stats.pearsonr(a,b) print 'spearmanr:' print stats.spearmanr(l,m) print stats.spearmanr(a,b) print 'pointbiserialr:' print stats.pointbiserialr(pb,l) print stats.pointbiserialr(apb,a) print 'kendalltau:' print stats.kendalltau(l,m) print stats.kendalltau(a,b) print 'linregress:' print stats.linregress(l,m) print stats.linregress(a,b) print '\nINFERENTIAL'
m = range(4, 24) m[10] = 34 b = N.array(m) pb = [0] * 9 + [1] * 11 apb = N.array(pb) print 'paired:' # stats.paired(l,m) # stats.paired(a,b) print print print 'pearsonr:' print stats.pearsonr(l, m) print stats.pearsonr(a, b) print 'spearmanr:' print stats.spearmanr(l, m) print stats.spearmanr(a, b) print 'pointbiserialr:' print stats.pointbiserialr(pb, l) print stats.pointbiserialr(apb, a) print 'kendalltau:' print stats.kendalltau(l, m) print stats.kendalltau(a, b) print 'linregress:' print stats.linregress(l, m) print stats.linregress(a, b) print '\nINFERENTIAL'
l = [float(f) for f in list(range(1,21))] ll = [l]*5 m = dyn([float(f) for f in list(range(4,24))]) m[10] = 34. pb = dyn([0.]*9 + [1.]*11) print('paired:') #stats.paired(l,m) #stats.paired(l,l) print() print() print('pearsonr:') print(stats.pearsonr(l,m)) print(stats.pearsonr(l,l)) print('spearmanr:') print('pointbiserialr:') print(stats.pointbiserialr(pb,l)) print(stats.pointbiserialr(pb,l)) print('kendalltau:') print(stats.kendalltau(l,m)) print(stats.kendalltau(l,l)) print('linregress:') print(stats.linregress(l,m)) print(stats.linregress(l,l)) print('\nINFERENTIAL') print('ttest_1samp:') print(stats.ttest_1samp(l,12))
print('\n\nRelated Samples t-test') before = list(map(float,[11,16,20,17,10])) after = list(map(float,[8,11,15,11,11])) print('\n\nSHOULD BE t=+2.88, 0.01<p<0.05 (df=4) ... Basic Stats 1st ed, p.359') stats.ttest_rel(before,after,1,'Before','After') print("\n\nPearson's r") y = list(map(float,[8,7,7,6,5,4,4,4,2,0])) x = list(map(float,[0,0,1,1,1,2,2,3,3,4])) print('SHOULD BE -0.94535 (N=10) ... Basic Stats 1st ed, p.190',x,y) print(stats.pearsonr(x,y)) print("\n\nSpearman's r") x = list(map(float,[4,1,9,8,3,5,6,2,7])) y = list(map(float,[3,2,8,6,5,4,7,1,9])) print('\nSHOULD BE +0.85 on the dot (N=9) ... Basic Stats 1st ed, p.193',x,y) print(stats.spearmanr(x,y)) print('\n\nPoint-Biserial r') gender = list(map(float,[1,1,1,1,2,2,2,2,2,2])) score = list(map(float,[35, 38, 41, 40, 60, 65, 65, 68, 68, 64])) print('\nSHOULD BE +0.981257 (N=10) ... Basic Stats 1st ed, p.197')