如何在python中的if-else语句中实现统计测试?我用的是科幻数据。我想要实现的代码的一小部分是:
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
应该是float/int值的列表),另一个是总体平均值。T检验你的样本平均值是否与总体平均值有显著差异(你也应该提供)。
T检验返回两个值,第一个是所谓的T分数,第二个是与该T分数相关的概率(小概率表示sample
平均值和总体平均值之间的差异非常显著)。这一部分很简单,只需获取值,将它们转换为str
,并在消息框中的某个位置显示它们。类似于:
MessageBox.showinfo( 't test', "t-value is %s, p=%s"%stats.ttest_1samp(sample, YOUR_POPULATION_MEAN))