如何计算两个浮点数列表的 p 值? [英] How to calculate p-value for two lists of floats?

查看:35
本文介绍了如何计算两个浮点数列表的 p 值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有浮动列表.像 [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],... }

显然,ab 非常相似,但都与 c 不同.

您可能需要进行两种比较.

  1. Pairwise:a 是否与 b 相似?ac 一样吗?bc 一样吗?
  2. 组合:abc 是否来自同一组?(这通常是一个更好的问题)

前者可以使用独立的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 值,并暗示 ac 是不同,bc 不同,但 ab 可能相似.

后者可以使用单向实现方差分析如下:

<预><代码>>>>从 scipy.stats 导入 f_oneway>>>t, p = f_oneway(*data.values())>>>磷7.959305946160327e-12

p 值表明 abc 不太可能来自同一群体.

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.

  1. Pairwise: Is a similar to b? Is a similar to c? Is b similar to c?
  2. Combined: Are a, b and c 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆