Python的Scipy.stats中的norm.ppf与norm.cdf有什么区别?

8
我已经复制了完整的代码以供参考,我想知道ppf和cdf在这里的作用是什么?你能解释一下吗?我做了一些研究,发现ppf(percent point function百分点函数)是CDF(cumulative distribution function累积分布函数)的反函数。如果它们真的是这样,那么如果我将ppf和cdf替换为1/cdf和1/ppf,这段代码不应该也可以工作吗?
请解释一下它们之间的区别,以及如何和何时使用哪个。
顺便说一下,这是假设检验。对不起,有这么多注释,只不过是为了以后自己的参考而已。(如果任何评论与此有关是错误的,请指出来)
ball_bearing_radius = [2.99, 2.99, 2.70, 2.92, 2.88, 2.92, 2.82, 2.83, 3.06, 2.85]




import numpy as np

from math import sqrt
from scipy.stats import norm

# h1 : u != U_0
# h0 : u = u_0
#case study : ball bearing example, claim is that radius = 3, do hypothesis testing 
mu_0 = 3
sigma = 0.1

#collect sample
sample = ball_bearing_radius

#compute mean
mean = np.mean(sample)

#compute n
n = len(sample)

#compute test statistic
z = (mean - mu_0) /(sigma/sqrt(n))

#set alpha
a = 0.01

#-------------------------

#calculate the z_a/2, by using percent point function of the norm of scipy
#ppf = percent point function, inverse of CDF(comulative distribution function)
#also, CDF = pr(X<=x), i.e., probability to the left of the distribution

z_critical = norm.ppf(1-a/2)    #this returns a value for which the probab to the left is 0.975

p_value = 2*(1 - norm.cdf(np.abs(z)))

p_value = float("{:.4f}".format(p_value))


print('z : ',z)
print('\nz_critical :', z_critical)
print('\nmean :', mean, "\n\n")

#test the hypothesis

if (np.abs(z) > z_critical):
    print("\nREJECT THE NULL HYPOTHESIS : \n p-value = ", p_value, "\n Alpha = ", a )

else:
    print("CANNOT REJECT THE NULL HYPOTHESIS. NOT ENOUGH EVIDENCE TO REJECT IT: \n p-value = ", p_value, "\n Alpha = ", a )

这份文档与统计学技术相关,不仅仅是这两个函数的直接反转。请点击链接查看:http://eric.univ-lyon2.fr/~ricco/tanagra/fichiers/en_Tanagra_Calcul_P_Value.pdf - srishtigarg
1个回答

17

.cdf()函数计算给定正态分布值的概率,而.ppf()函数计算给定概率所需的正态分布值。 在这种特定意义下,它们是相互反转的。

为了说明这个计算过程,请查看下面的示例代码。

from scipy.stats import norm
print(norm.ppf(0.95))
print(norm.cdf(1.6448536269514722))

在此输入图片描述

这张图片可以让你清晰地看到上面的代码。

谢谢!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接