Python scipy.stats 模块,ttest_1samp() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用scipy.stats.ttest_1samp()

项目:mrqap-python    作者:lisette-espin    | 项目源码 | 文件源码
def _ttest(self):
        utils.printf('')
        utils.printf('========== T-TEST ==========')
        utils.printf('{:25s} {:25s} {:25s} {:25s}'.format('IND. VAR.','COEF.','T-STAT','P-VALUE'))

        ts = {}
        lines = {}
        for k,vlist in self.betas.items():
            t = stats.ttest_1samp(vlist,self.model.params[k])
            ts[k] = abs(round(float(t[0]),6))
            lines[k] = '{:20s} {:25f} {:25f} {:25f}'.format(k,self.model.params[k],round(float(t[0]),6),round(float(t[1]),6))

        ts = utils.sortDictByValue(ts,True)
        for t in ts:
            utils.printf(lines[t[0]])


    #####################################################################################
    # Plots
    #####################################################################################
项目:ipanda    作者:varnivey    | 项目源码 | 文件源码
def calculate_single_sample_ttest_pvals(self):
        '''Calculate p-values from single sample t-test'''

        expr_t = self.expr_t
        expr_n = self.expr_n

        mes_size, gene_size = expr_t.shape

        all_pvals = []

        for i in range(gene_size):
            n_sample  = expr_n[:,i]
            cur_pvals = []
            n_sample_r = randomize_samples(n_sample)

            cur_pvals = [ttest_func2(n_sample_r,expr_val)[1] for expr_val in expr_t[:,i]]

            all_pvals.append(cur_pvals)

        all_pvals = np.array(all_pvals).T
        all_pvals[all_pvals == 0] = sys.float_info.min

        self.s_pval_list = all_pvals
项目:ABtests    作者:leodema    | 项目源码 | 文件源码
def test_analysis(self):
        my_test = Ttest1Sample(self.mean, np.array(self.a))
        p_value = my_test.p_value
        t, p_value_expected = ttest_1samp(self.a, self.mean)

        self.assertEqual(round(p_value_expected, self.max_precision),
                         round(p_value, self.max_precision))
项目:ABtests    作者:leodema    | 项目源码 | 文件源码
def test_analysis_list(self):
        my_test = Ttest1Sample(self.mean, np.array(self.a))
        p_value = my_test.p_value
        my_test.report()
        t, p_value_expected = ttest_1samp(self.a, self.mean)

        self.assertEqual(round(p_value_expected, self.max_precision),
                         round(p_value, self.max_precision))
项目:dopelearning    作者:ekQ    | 项目源码 | 文件源码
def analyze(log_fname, nn=True, max_bin=6, n_first_removed=3):
    """
    Analyze anonymized deepbeat.org usage logs.

    Input:
        log_fname -- Path to the log file.
        nn -- Use scores with the NN feature or not.
        max_bin -- Maximum score difference considered
                   (if too large, the last bins get very noisy).
        n_first_removed -- From each user, remove this many first selections,
                           since in the beginning the user might be just
                           playing with the tool.       
    Output:
        bin_centers
        probabilities to select the better line according to the algorithm
        standard deviations
    """
    users, selections = read_log(log_fname)
    print "%d selections, %d unique users" % (len(selections), len(set(users)))
    us = {}    # user -> selections
    for u, s in zip(users, selections):
        if u not in us:
            us[u] = []
        us[u].append(s)
    lens = [len(s) for s in us.itervalues()]
    lens = np.array(lens)

    score_differences = extract_feedback(us, n_first_removed, nn)
    print "t-test:", stats.ttest_1samp(score_differences, 0)

    sel_ranks = [s['selectedLine'] for s in selections]
    print "Histogram of selected line indices:"
    print np.histogram(sel_ranks, range(21))

    xs, probs, stds = compute_probs(score_differences, max_bin)
    return xs, probs, stds
项目:sdnpwn    作者:smythtech    | 项目源码 | 文件源码
def testForSDN(testMethod, dstIP, count, interval):
  global verbose
  rtt = []
  sentMS = 0

  if(testMethod == "icmp"):
    sdnpwn.message("Testing with ICMP", sdnpwn.NORMAL)
    icmp = (IP(dst=dstIP)/ICMP())
    for i in range(0,count):
      sentMS = int(round(time.time() * 1000))
      resp = sr1(icmp)
      rtt.append((int(round(time.time() * 1000))) - sentMS)
      time.sleep(interval)

  elif(testMethod == "arp"):
    sdnpwn.message("Testing with ARP", sdnpwn.NORMAL)
    for i in range(0,count):
      sentMS = int(round(time.time() * 1000))
      resp = arping(dstIP)
      rtt.append((int(round(time.time() * 1000))) - sentMS)
      time.sleep(interval)

  initValue = rtt[0]
  rtt.pop(0)
  #Perform T-Test to check if first latency value is significantly different from others in our sample
  res = stats.ttest_1samp(rtt, initValue)
  if(verbose == True):
    sdnpwn.message("Initial RTT: " + str(initValue), sdnpwn.VERBOSE)
    sdnpwn.message("RTTs for other traffic: " + str(rtt), sdnpwn.VERBOSE)
    sdnpwn.message("Calculated p-value for inital RTT is " + str(res[1]), sdnpwn.VERBOSE)
  if(res[1] < .05 and all(i < initValue for i in rtt)): #If the p-value is less that 5% we can say that initValue is significant
    return True
  else:
    return False