我已经复制了完整的代码以供参考,我想知道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 )