How to perform two-sample one-tailed t-test with numpy/scipy

前端 未结 5 1026
[愿得一人]
[愿得一人] 2020-12-07 20:35

In R, it is possible to perform two-sample one-tailed t-test simply by using

> A = c(0.19826790, 1.36836629, 1.37950911, 1.46951540, 1.481977         


        
5条回答
  •  一个人的身影
    2020-12-07 21:04

    When null hypothesis is Ho: P1>=P2 and alternative hypothesis is Ha: P1. In order to test it in Python, you write ttest_ind(P2,P1). (Notice the position is P2 first).

    first = np.random.normal(3,2,400)
    second = np.random.normal(6,2,400)
    stats.ttest_ind(first, second, axis=0, equal_var=True)
    

    You will get the result like below Ttest_indResult(statistic=-20.442436213923845,pvalue=5.0999336686332285e-75)

    In Python, when statstic <0 your real p-value is actually real_pvalue = 1-output_pvalue/2= 1-5.0999336686332285e-75/2, which is approximately 0.99. As your p-value is larger than 0.05, you cannot reject the null hypothesis that 6>=3. when statstic >0, the real z score is actually equal to -statstic, the real p-value is equal to pvalue/2.

    Ivc's answer should be when (1-p/2) < alpha and t < 0, you can reject the less than hypothesis.

提交回复
热议问题