首页 > 解决方案 > 将 scipy.stats.ttest_ind 用于整个数组与两个向量时的不同结果

问题描述

我正在使用多个 t 检验在两组(男性和女性)之间进行体素比较。为此,我正在使用scipy.stats.ttest_ind. 我有 541443 个体素作为我想要执行独立 t 检验的因变量。一切似乎都很好,但是当我检查结果并对随机挑选的体素进行单次 t 检验时,我得到了不同的结果。

这是我的代码:

statistics,p_values = ttest_ind(male_data,female_data)

为 t 值生成:array([-5.23764997e-16, -1.59544316e-15, 7.88216339e-16, ..., 1.11783465e-15, -2.22874323e-16, -9.35188323e-16])

single_stat,single_p_value = ttest_ind(female_data[:,0],male_data[:,0])

产生:-4.3805762173832176e-16 作为 t 值

我希望第一个 t 检验的输出相等(所以 ~ -5.237 或 ~ -4.380)。有谁知道这里可能出了什么问题?

我还尝试了第三种方法,它使用 for 循环进行多个 t 检验。似乎有一个一致的效果,即 for-loop-method 的结果总是与 single-t-test 方法的输出相同(这是有道理的,因为它基本上是在做多个 singlettest_ind然后附加的输出每个 t 检验到一个列表)。然而,这两个结果都不同于整个数组的输出ttest_ind。我还按照评论中的建议将数据切成不同的大小,我发现这三种方法(或两种,因为 for-loop 和单 t 检验似乎总是相同)的结果变得更多和更相似,但返回的 t 值和 p 值变得非常小或大。还有,蜘蛛当我想ttest_ind在最后一种情况下(n = 5)单击整个数组的输出时崩溃。

n_rows = 150
Output from for-loop method (first t-value in the list):
t-value: -0.050583527798906465
p-value: 0.9596912767683707

Output from the t-test performed on only the first column:
t-value: -0.050583527798906465
p-value: 0.9596912767683707

Output from the t-test performed on the whole array (first t-value):
t-value: -0.050583527798907256
p-value: 0.9596912767683701

---------------------------------------
n_rows = 75
Output from for-loop method (first t-value in the list):
t-value: 0.9760289069224989
p-value: 0.33064277748038773

Output from the t-test performed on only the first column:
t-value: 0.9760289069224989
p-value: 0.33064277748038773

Output from the t-test performed on the whole array (first t-value):
t-value: 0.9760289069224984
p-value: 0.33064277748038795

---------------------------------------
n_rows = 5
Output from for-loop method (first t-value in the list):
t-value: 6111430044112607.0
p-value: 5.755396703077005e-124

Output from the t-test performed on only the first column:
t-value: 6111430044112607.0
p-value: 5.755396703077005e-124

Output from the t-test performed on the whole array (first t-value):
t-value: 6111430044112607.0
p-value: 5.755396703077005e-124

---------------------------------------

标签: pythonscipy

解决方案


推荐阅读