python正态转换的函数 python 正态性检验_概率论


对正态总体参数的单侧假设检验,可以用如下的p值法进行。设显著水平为python正态转换的函数 python 正态性检验_ci_02,考虑假设python正态转换的函数 python 正态性检验_假设检验_03的右侧检验。首先,注意到检验统计量的分布对应显著水平python正态转换的函数 python 正态性检验_ci_02的右分位点python正态转换的函数 python 正态性检验_ci_05,实际上就是其残存函数python正态转换的函数 python 正态性检验_方差_06python正态转换的函数 python 正态性检验_概率论_07)在该点处的函数值python正态转换的函数 python 正态性检验_python正态转换的函数_08恰为python正态转换的函数 python 正态性检验_ci_02,即python正态转换的函数 python 正态性检验_假设检验_10。我们知道在假设python正态转换的函数 python 正态性检验_假设检验_03的右侧检验中,python正态转换的函数 python 正态性检验_假设检验_03的拒绝域为python正态转换的函数 python 正态性检验_概率论_13。若检验统计量观测值python正态转换的函数 python 正态性检验_python正态转换的函数_14落在拒绝域内,则必有python正态转换的函数 python 正态性检验_python正态转换的函数_15。而若检验统计量观测值python正态转换的函数 python 正态性检验_概率论_16落在非拒绝域内,则应有python正态转换的函数 python 正态性检验_方差_17,如下图所示。

python正态转换的函数 python 正态性检验_概率论_18


相仿地,对假设python正态转换的函数 python 正态性检验_假设检验_03的左侧检验而言,设检验统计量的分布对应显著水平python正态转换的函数 python 正态性检验_ci_02的右侧分位点为python正态转换的函数 python 正态性检验_概率论_21,则分布函数python正态转换的函数 python 正态性检验_假设检验_22。若检验统计量观测值python正态转换的函数 python 正态性检验_概率论_16满足python正态转换的函数 python 正态性检验_python正态转换的函数_24,则python正态转换的函数 python 正态性检验_概率论_16落在python正态转换的函数 python 正态性检验_假设检验_03的非拒绝域内,而若检验统计量观测值python正态转换的函数 python 正态性检验_python正态转换的函数_14满足python正态转换的函数 python 正态性检验_python正态转换的函数_28,则python正态转换的函数 python 正态性检验_python正态转换的函数_14落在python正态转换的函数 python 正态性检验_假设检验_03的拒绝域内,如下图所示。

python正态转换的函数 python 正态性检验_假设检验_31


已知正态总体方差python正态转换的函数 python 正态性检验_概率论_32的情况下,对总体均值python正态转换的函数 python 正态性检验_ci_33作显著水平为python正态转换的函数 python 正态性检验_ci_02的假设检验,采用Z检验法。单侧检验的计算步骤为

1.构造检验统计量观测值python正态转换的函数 python 正态性检验_假设检验_35
2.计算对应于python正态转换的函数 python 正态性检验_python正态转换的函数_36的累积分布函数值python正态转换的函数 python 正态性检验_概率论_37(左侧检验)或残存函数值python正态转换的函数 python 正态性检验_方差_38(右侧检验);
3.比较python正态转换的函数 python 正态性检验_概率论_39结果为真,则接受假设,否则拒绝假设。
将此算法编写如下计算总体均值单侧假设检验的Python函数。

from scipy.stats import norm    #导入norm
def ztestL(z, alpha):           #左侧检验函数
    p=norm.cdf(z)               #F(z)
    return p>=alpha             #检验
def ztestR(z, alpha):           #右侧检验函数
    p=norm.sf(z)                #S(z)
    return p>=alpha             #检验

程序的第2~4行定义Z方法左侧检验函数ztestL,第5~7行定义右侧检验函数ztestR。两个函数函数的参数z和alpha分别表示检测统计量观测值python正态转换的函数 python 正态性检验_方差_40和显著水平python正态转换的函数 python 正态性检验_ci_02。返回的布尔值或为True,则接受假设python正态转换的函数 python 正态性检验_概率论_42(或python正态转换的函数 python 正态性检验_python正态转换的函数_43),否则拒绝python正态转换的函数 python 正态性检验_假设检验_03
例1 公司从生产商购买牛奶。公司怀疑生产商在牛奶中掺水以牟利。通过测定牛奶的冰点,可以检验出牛奶是否掺水。天然牛奶的冰点温度近似服从python正态转换的函数 python 正态性检验_ci_45,牛奶掺水可使冰点温度升高而接近于水的冰点温度(python正态转换的函数 python 正态性检验_概率论_46C)。测得生产商提交的5批牛奶的冰点温度,其均值为python正态转换的函数 python 正态性检验_python正态转换的函数_47C,问是否可以认为生产商在牛奶中掺了水(python正态转换的函数 python 正态性检验_概率论_48)?
解: 按题意,需对假设python正态转换的函数 python 正态性检验_ci_49,即牛奶未掺水进行右侧检验。下列代码完成本例计算。

import numpy as np                              #导入numpy
xmean=-0.535                                    #样本均值
s0=0.008                                        #总体均方差
mu0=-0.545                                      #总体均值假设值
n=5                                             #样本容量
alpha=0.05                                      #显著水平
z=(xmean-mu0)/(s0/np.sqrt(n))                   #检验统计量
accept=ztestR(z, alpha)                         #右侧检验
print('mu<=%.3f is %s.'%(mu0, accept))

第2~6行设置各项数据。第7行计算检验统计量观测值python正态转换的函数 python 正态性检验_方差_40,第8行调用函数ztestR对假设python正态转换的函数 python 正态性检验_方差_51作右侧检验。运行程序,输出

mu<=-0.545 is False.

表示拒绝假设python正态转换的函数 python 正态性检验_方差_51,即拒绝假设:牛奶未掺水。
例2 要求一种元件平均使用寿命不得低于1000h。生产者从一批这种元件中随机抽取25件,测得其寿命的平均值为950h。已知该种元件寿命服从标准差python正态转换的函数 python 正态性检验_方差_53h的正态分布。试在显著水平python正态转换的函数 python 正态性检验_概率论_48下判断这批元件是否合格。
解: 按题意,需要对假设python正态转换的函数 python 正态性检验_python正态转换的函数_55,即寿命不低于1000小时进行左侧检验。下列代码完成本例计算。

import numpy as np
xmean=950
sigma=100
mu0=1000
n=25
alpha=0.05
z=(xmean-mu0)/(s0/np.sqrt(n))
accept=ztestL(z, alpha)
print('mu>=%d is %s.'%(mu0, accept))

本例计算的是对假设python正态转换的函数 python 正态性检验_python正态转换的函数_55的左侧检验,故第8行调用函数ztestL执行计算。运行程序,输出

mu>=1000 is False.

即拒绝假设python正态转换的函数 python 正态性检验_python正态转换的函数_55,认为本批次产品不合格。
写博不易,敬请支持:
如果阅读本文于您有所获,敬请点赞、评论、收藏,谢谢大家的支持!
代码诚可贵,原理价更高。若为AI学,读正版书好