Python 使用scipy stats,如何在if-else语句中实现统计测试?

Python 使用scipy stats,如何在if-else语句中实现统计测试?,python,if-statement,statistics,scipy,Python,If Statement,Statistics,Scipy,如何在python中的if-else语句中实现统计测试?我使用的是scipy统计数据。我希望实现此功能的代码的一小部分是: def choose(): global sample if q1.get() == 1 and q2.get() == 1 and q3.get() == 2 and q4.get() == 2 and q5.get() == 1 and q6.get() == 2 and q7.get() == 2 and q8.get() ==

如何在python中的if-else语句中实现统计测试?我使用的是scipy统计数据。我希望实现此功能的代码的一小部分是:

def choose():

        global sample

        if q1.get() == 1 and q2.get() == 1 and q3.get() == 2 and q4.get() == 2 and  q5.get() == 1 and q6.get() == 2 and q7.get() == 2 and q8.get() == 2 and q9.get() == 2 :
            tkMessageBox.showinfo( 'decision', 'You should use the t-test!')
            stats.ttest_1samp()
            #will do t-test here
            print sample
            # now sample list contains the data for doing t-test,
            #you just need to call t-test to get the results and show it on message box

不清楚你想测试什么
stats.ttest_1samp()
接受两个参数,一个是观察样本(在您的案例中,
sample
,应该是浮点值/整数值列表),另一个是总体平均值。T检验如果你的样本平均值与总体平均值(你也应该提供)显著不同

T检验返回2个值,第一个是所谓的T分数,第二个是与该T分数相关的概率(小概率表示样本平均值与总体平均值之间的差异非常显著)。这一部分很简单,只需获取值,将它们转换为
str
,并在消息框中显示它们。比如:

MessageBox.showinfo( 't test', "t-value is %s, p=%s"%stats.ttest_1samp(sample, YOUR_POPULATION_MEAN))