如何计算两个浮点数列表的 p 值? [英] How to calculate p-value for two lists of floats?
问题描述
所以我有浮动列表.像 [1.33,2.555,3.2134,4.123123]
等.这些列表是某物的平均频率.如何证明两个列表不同?我想过计算 p 值.有没有一个功能可以做到这一点?我查看了 scipy 文档,但不知道该使用什么.
谁能给点建议?
假设您有一个像这样的浮动列表:
<预><代码>>>>数据 = {... 'a': [0.9, 1.0, 1.1, 1.2],... 'b': [0.8, 0.9, 1.0, 1.1],... 'c': [4.9, 5.0, 5.1, 5.2],... }显然,a
与 b
非常相似,但都与 c
不同.
您可能需要进行两种比较.
- Pairwise:
a
是否与b
相似?a
和c
一样吗?b
和c
一样吗? - 组合:
a
、b
和c
是否来自同一组?(这通常是一个更好的问题)
前者可以使用独立的t-tests来实现如下:
<预><代码>>>>从 itertools 导入组合>>>从 scipy.stats 导入 ttest_ind>>>对于列表 1、列表 2 的组合(data.keys(), 2):... t, p = ttest_ind(data[list1], data[list2])... 打印 list1, list2, p...a c 9.45895002589e-09a b 0.315333596201c b 8.15963804843e-09这提供了相关的 p 值,并暗示 a
和 c
是不同,b
和 c
不同,但 a
和 b
可能相似.
后者可以使用单向实现方差分析如下:
<预><代码>>>>从 scipy.stats 导入 f_oneway>>>t, p = f_oneway(*data.values())>>>磷7.959305946160327e-12p 值表明 a
、b
和 c
不太可能来自同一群体.
So I have lists of floats. Like [1.33,2.555,3.2134,4.123123]
etc. Those lists are mean frequencies of something. How do I proof that two lists are different? I thought about calculating p-value. Is there a function to do that? I looked through scipy documentation, but couldn't figure out what to use.
Can anyone please advice?
Let's say you have a list of floats like this:
>>> data = {
... 'a': [0.9, 1.0, 1.1, 1.2],
... 'b': [0.8, 0.9, 1.0, 1.1],
... 'c': [4.9, 5.0, 5.1, 5.2],
... }
Clearly, a
is very similar to b
, but both are different from c
.
There are two kinds of comparisons you may want to do.
- Pairwise: Is
a
similar tob
? Isa
similar toc
? Isb
similar toc
? - Combined: Are
a
,b
andc
drawn from the same group? (This is generally a better question)
The former can be achieved using independent t-tests as follows:
>>> from itertools import combinations
>>> from scipy.stats import ttest_ind
>>> for list1, list2 in combinations(data.keys(), 2):
... t, p = ttest_ind(data[list1], data[list2])
... print list1, list2, p
...
a c 9.45895002589e-09
a b 0.315333596201
c b 8.15963804843e-09
This provides the relevant p-values, and implies that that a
and c
are
different, b
and c
are different, but a
and b
may be similar.
The latter can be achieved using the one-way ANOVA as follows:
>>> from scipy.stats import f_oneway
>>> t, p = f_oneway(*data.values())
>>> p
7.959305946160327e-12
The p-value indicates that a
, b
, and c
are unlikely to be from the same population.
这篇关于如何计算两个浮点数列表的 p 值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!