【问题标题】:Why scipy and Excel generate slightly different p-value for two-sample t-test?为什么 scipy 和 Excel 为两个样本 t 检验生成略有不同的 p 值?
【发布时间】:2018-05-03 10:45:55
【问题描述】:

对于python,默认为two-side test

from scipy import stats
import numpy as np
wt = np.array([71.93636,71.34689,72.2162])
mut = np.array([71.58995,70.82698,70.89562])
t, p = stats.ttest_ind(wt, mut, equal_var=False)
print(t,p)

我明白了

2.06163943002 0.108425721876

ExcelData 选项卡 - Data Analysis - t-Test: Two-Sample Assuming Unequal Variances 中,t 的值相同,但 p 的值略有不同(0.1084... 与 0.1082...)

我能问为什么吗?

【问题讨论】:

  • 我想如果你去阅读那些函数定义,你会发现参数有不同的含义或者在计算中引入了一些额外的因素。检查是否有一侧或两侧的睾丸。去源头,你可能会找出原因。
  • 或者它可能依赖于实现,或者由于算法之间的数值稳定性。
  • 如果您在调用stats.ttest_ind() 时使用equal_var=True,则p 值与Excel 中的值匹配。您在 Excel 中使用的公式来自哪里?您还没有向我们展示 Excel 代码;我们看到的只是数字。
  • 你用过T.TEST吗?如果是这样,您为 Type 参数使用了什么值?

标签: python excel scipy t-test


【解决方案1】:

如果你使用

from scipy import stats
stats.ttest_rel(wt,mut)

它应该与 Excel 中的相同计算匹配。

rel 用于相关样本,ind 用于独立样本。

【讨论】:

  • 谢谢,但stats.ttest_relstats.ttest_ind 有什么区别?
  • 编辑了我的答案以给出不同之处。
猜你喜欢
  • 1970-01-01
  • 2016-11-16
  • 2017-07-11
  • 2022-06-17
  • 2011-11-22
  • 1970-01-01
  • 2022-01-07
  • 2020-06-25
  • 2015-12-09
相关资源
最近更新 更多