【问题标题】:One Sided One Sample T Test Python单边一个样本 T 测试 Python
【发布时间】:2017-12-10 08:41:16
【问题描述】:

在 Python 中,我使用 SciPy 进行单样本 t 检验:

from scipy import stats

one_sample_data = [177.3, 182.7, 169.6, 176.3, 180.3, 179.4, 178.5, 177.2, 181.8, 176.5]

one_sample = stats.ttest_1samp(one_sample_data, 175.3)

这是一个双尾测试,但我在 scipy.stats.ttest_1samp 中看不到进行单尾测试的选项。

如果我在 R 中使用 t.test(),我会简单地设置 alternative="less"(或“更大”)。在 Python 中最简单的方法是什么?

【问题讨论】:

标签: python scipy statistics


【解决方案1】:

根据 cmets 中提供的链接,我将执行以下操作:

from scipy import stats
def one_sample_one_tailed(sample_data, popmean, alpha=0.05, alternative='greater'):
    t, p = stats.ttest_1samp(sample_data, popmean)
    print ('t:',t)
    print ('p:',p)
    if alternative == 'greater' and (p/2 < alpha) and t > 0:
        print ('Reject Null Hypothesis for greater-than test')
    if alternative == 'less' and (p/2 < alpha) and t < 0:
        print ('Reject Null Hypothesis for less-thane test')
sample_data = [177.3, 182.7, 169.6, 176.3, 180.3, 179.4, 178.5, 177.2, 181.8, 176.5]        
one_sample_one_tailed(sample_data,175.3)  

这给出了输出:

t: 2.295568968083183
p: 0.04734137339747034
Reject Null Hypothesis for greater-than test

此解决方案基于链接中接受的答案:

接着说 scipy 总是给出测试统计数据为 签。这意味着给定来自双尾检验的 p 和 t 值, 当 p/2 0,以及当 p/2

【讨论】:

  • 如何只得到一个p值?
【解决方案2】:

现在 'alternative' 参数可用于最新版本的 Scipy (>=1.6) 这是链接:

https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.ttest_1samp.html

【讨论】:

    猜你喜欢
    • 2020-06-25
    • 1970-01-01
    • 1970-01-01
    • 2020-09-05
    • 1970-01-01
    • 2012-06-08
    • 1970-01-01
    • 2010-10-24
    • 1970-01-01
    相关资源
    最近更新 更多