在 Python 中将 Z 分数(Z 值,标准分数)转换为正态分布的 p 值 [英] Convert Z-score (Z-value, standard score) to p-value for normal distribution in Python

查看:122
本文介绍了在 Python 中将 Z 分数(Z 值,标准分数)转换为正态分布的 p 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 Z-scoreZ 分布(标准正态分布,高斯分布)p-value?我还没有在 Scipy 的 stats 模块中找到神奇的功能要做到这一点,但必须有人在那里.

How does one convert a Z-score from the Z-distribution (standard normal distribution, Gaussian distribution) to a p-value? I have yet to find the magical function in Scipy's stats module to do this, but one must be there.

推荐答案

我更喜欢正态分布的生存函数(上尾概率)好一点,因为函数名的信息量更大:

I like the survival function (upper tail probability) of the normal distribution a bit better, because the function name is more informative:

p_values = scipy.stats.norm.sf(abs(z_scores)) #one-sided

p_values = scipy.stats.norm.sf(abs(z_scores))*2 #twosided

正态分布norm"是 scipy.stats 中大约 90 个分布之一

normal distribution "norm" is one of around 90 distributions in scipy.stats

norm.sf 也调用了 scipy.special 中的相应函数,如 gotgenes 示例中那样

norm.sf also calls the corresponding function in scipy.special as in gotgenes example

生存函数的小优势,sf:对于接近 1 的分位数,数值精度应该比使用 cdf 更好

small advantage of survival function, sf: numerical precision should better for quantiles close to 1 than using the cdf

这篇关于在 Python 中将 Z 分数(Z 值,标准分数)转换为正态分布的 p 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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