def analyse_sample_set(self, samples): """ Analyses a set of sample of length sample_size """ result = self.template.copy() result.update( { 'index' : self.index, 'mean' : get_average(samples)[0], 'median': get_median(samples), } ) self.rev_results.append(result) if len(set(samples)) == 1: t_prob1 = -1 t_prob2 = -1 t_prob3 = -1 else: (t_stat, t_prob1) = stats.ttest_1samp(samples, self.popmean) (t_stat, t_prob2) = stats.ttest_1samp(samples, min(int(self.popmean * (1-self.threshold)), self.popmean - 1)) (t_stat, t_prob3) = stats.ttest_1samp(samples, max(int(self.popmean * (1+self.threshold)), self.popmean + 1)) result = self.template.copy() result.update( { 'index' : self.index, 'same' : t_prob1 > 0.05, 'same_stat' : t_prob1, 'less' : t_prob2 < 0.05, 'less_stat' : t_prob2, 'more' : t_prob3 < 0.05, 'more_stat' : t_prob3, } ) self.conf_results.append(result)
def test_ttest_1samp(self): "Testing ttest_1samp" data = [self.L, self.A] results = (-1.1338934190276817, 0.27094394816451473) i = 0 for d in data: self.assertEqual(stats.ttest_1samp(d, 12)[i], results[i]) i += 1
def test_ttest_1samp(self): "Testing ttest_1samp" data = [ self.L, self.A ] results = (-1.1338934190276817, 0.27094394816451473) i = 0 for d in data: self.assertEqual( stats.ttest_1samp( d, 12 )[i], results[i] ) i += 1
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:') print(stats.ttest_1samp(l, 12)) print(stats.ttest_1samp(a, 12)) print('ttest_ind:') print(stats.ttest_ind(l, m)) print(stats.ttest_ind(a, b)) print('ttest_rel:') print(stats.ttest_rel(l, m)) print(stats.ttest_rel(a, b)) print('chisquare:') print(stats.chisquare(l)) print(stats.chisquare(a)) print('ks_2samp:') print(stats.ks_2samp(l, m)) print(stats.ks_2samp(a, b)) print('mannwhitneyu:')
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:' print stats.ttest_1samp(l,12) print stats.ttest_1samp(a,12) print 'ttest_ind:' print stats.ttest_ind(l,m) print stats.ttest_ind(a,b) print 'ttest_rel:' print stats.ttest_rel(l,m) print stats.ttest_rel(a,b) print 'chisquare:' print stats.chisquare(l) print stats.chisquare(a) print 'ks_2samp:' print stats.ks_2samp(l,m) print stats.ks_2samp(a,b) print 'mannwhitneyu:'
from statlib import stats, pstat reload(stats) from Numeric import * reload(pstat) import statshelp print '\n\nSingle Sample t-test' x = [50, 75, 65, 72, 68, 65, 73, 59, 64] print 'SHOULD BE ... t=-3.61, p<0.01 (df=8) ... Basic Stats 1st ed, p.307' stats.ttest_1samp(x, 75, 1) stats.attest_1samp(array(x), 75, 1) print '\n\nIndependent Samples t-test' a = [11, 16, 20, 17, 10, 12] b = [8, 11, 15, 11, 11, 12, 11, 7] print '\n\nSHOULD BE ??? <p< (df=) ... ' stats.ttest_ind(a, b, 1) stats.attest_ind(array(a), array(b), 0, 1) print '\n\nRelated Samples t-test' before = [11, 16, 20, 17, 10] after = [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') stats.attest_rel(array(before), array(after), 1, 'Before', 'After') print "\n\nPearson's r"
def evaluate(self, *args, **params): return _stats.ttest_1samp(*args, **params)
parser = argparse.ArgumentParser(description="") parser.add_argument('-l', '--length', help="Length of the structure") parser.add_argument('-m', '--mfe', help="MFE of the structure") args = parser.parse_args() al = int(args.length) am = int(args.mfe) a = [] m = re.compile("(?P<l>\d+)\s(?P<m>\d+)") L = sys.stdin.readlines() for l in L: s = m.match(l) length = int(s.group("l")) if (abs(length - al) < 5): a.append(int(s.group("m"))) print a print 't-statistic = %6.3f pvalue = %s' % stats.ttest_1samp(a,am) # length -= length%10 +5 # a[length].append(int(s.group("m"))) # b = [] # for i in xrange(200,501): # if (a[i] != []): # print i, stats.mean(a[i]), stats.stdev(a[i]) # b.append(len(a[i])) # print stats.mean(b), stats.stdev(b)
from statlib import stats, pstat reload(stats) from Numeric import * reload(pstat) import statshelp print '\n\nSingle Sample t-test' x = [50,75,65,72,68,65,73,59,64] print 'SHOULD BE ... t=-3.61, p<0.01 (df=8) ... Basic Stats 1st ed, p.307' stats.ttest_1samp(x,75,1) stats.attest_1samp(array(x),75,1) print '\n\nIndependent Samples t-test' a = [11,16,20,17,10,12] b = [8,11,15,11,11,12,11,7] print '\n\nSHOULD BE ??? <p< (df=) ... ' stats.ttest_ind(a,b,1) stats.attest_ind(array(a),array(b),0,1) print '\n\nRelated Samples t-test' before = [11,16,20,17,10] after = [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') stats.attest_rel(array(before),array(after),1,'Before','After')
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:' print stats.ttest_1samp(l, 12) print stats.ttest_1samp(a, 12) print 'ttest_ind:' print stats.ttest_ind(l, m) print stats.ttest_ind(a, b) print 'ttest_rel:' print stats.ttest_rel(l, m) print stats.ttest_rel(a, b) print 'chisquare:' print stats.chisquare(l) print stats.chisquare(a) print 'ks_2samp:' print stats.ks_2samp(l, m) print stats.ks_2samp(a, b) print 'mannwhitneyu:'