手记

两个正态总体N(μ₁,σ₁²),N(μ₂,σ₂²)的均值差μ₁-μ₂的置信区间(σ₁²=σ₂²=σ²,且σ²未知时)

置信系数1-α=0.95

ltx=[221,244,243,288,233,220,210,258,245]
lty=[268,213,188,189,217,207]
def compute(ltx):
    le=len(ltx)
    sum=0
    S=0
    for i in range(0,le):
        sum+=ltx[i]
    avg=sum/le
    print('avg:',avg)
    for i in range(0,le):
        S+=(ltx[i]-avg)*(ltx[i]-avg)
    s=S/(le-1)
    print('S²:',s)
    return s,avg
S1,x=compute(ltx)
S2,y=compute(lty)
n1=len(ltx)
n2=len(lty)
v=n1+n2-2
Sw=(((n1-1)*S1+(n2-1)*S2)/v)**0.5
print("自由度v:",v)
print("Sw:",Sw)
#查表t₀.₀₂₅[v]=2.1604
N=(1/n1+1/n2)**0.5
print("N:",N)
se1=x-y-2.1604*Sw*N
se2=x-y+2.1604*Sw*N
print('μ₁-μ₂的置信区间为',(se1,se2))


0人推荐
随时随地看视频
慕课网APP