728x90
반응형

1. 모분산이 다음과 같은 정규모집단의 모평균에 대한 95% 신뢰도를 갖는 구간을 추정하기 위하여 크기가 50인 표본을 선정한다. 이때 오차한계를 구하라.

 

1> 모분산 = 5

 

x = np.arange(-5,5 , .001)

fig = plt.figure(figsize=(15,8))

ax = sns.lineplot(x , stats.norm.pdf(x, loc=0 , scale =1)) #정의역 범위 , 평균 = 0 , 표준편차 =1 인 정규분포 플롯

trust = 95 #신뢰도

# z_1 = round((0.05) / math.sqrt( 0.0018532 ) ,2)
# # z_2 = round((34.5 - 35) / math.sqrt(5.5**2 / 25) , 2)
z_1 = round(scipy.stats.norm.ppf(1 - (1-(trust/100))/2) ,3 )

ax.fill_between(x, stats.norm.pdf(x, loc=0 , scale =1) , 0 , where = (x<=z_1) & (x>=-z_1) , facecolor = 'skyblue') # x값 , y값 , 0 , x<=0 인곳 , 색깔



area = scipy.stats.norm.cdf(z_1) - scipy.stats.norm.cdf(-z_1)
plt.annotate('' , xy=(0, .1), xytext=(2 , .1)  , arrowprops = dict(facecolor = 'black'))

ax.vlines(x= z_1, ymin= 0 , ymax= stats.norm.pdf(z_1, loc=0 , scale =1) , color = 'black' , linestyle ='solid' , label ='{}'.format(2))
ax.vlines(x= -z_1, ymin= 0 , ymax= stats.norm.pdf(-z_1, loc=0 , scale =1) , color = 'black' , linestyle ='solid' , label ='{}'.format(2))

ax.text(2 , .1, f'P({-z_1}<=Z<={z_1}) : {round(area,4)}',fontsize=15)

ax.text(2 , .15, f'신뢰구간 모평균에 대한 {trust}% : \n' + r'$\overline{X}$' +f'-{z_1}' + r'$\dfrac{\sigma}{\sqrt{n}},\overline{X}$' + f'+{z_1}' + r'$\dfrac{\sigma}{\sqrt{n}}$',fontsize=15)

#A = [2.2 , 3.1 , 3.8 , 2.7 , 4.0 , 2.6 , 2.4 , 1.6 , 2.3]
#MEANS = round(np.mean(A) ,2)
STDS = round(math.sqrt(5),3)
n = 50
#print((z_1 * STDS / math.sqrt(len(A))))
# ax.text(2 , .25, f'신뢰구간 모평균에 대한 {trust}% : \n' + f'{round(MEANS - (z_1 * STDS ),2)} ~ {round(MEANS + (z_1 * STDS ),2)}' , fontsize= 15)


ax.text(2 , .35,  r'$\sigma = $' + f'{STDS}\n' + r'$\sqrt{n} = $' + f'{round(math.sqrt(n),3)}',fontsize=15)

ax.text(2 , .3,  r'신뢰구간 L = $2*{%.3f}\dfrac{\sigma}{\sqrt{n}} = $' % z_1 + f'{round(2* z_1 * STDS / math.sqrt(n),3)}',fontsize=15)

ax.text(2 , .25,  r'오차한계 = ${%.3f}\dfrac{\sigma}{\sqrt{n}} = $' % z_1 + f'{round(z_1 * STDS / math.sqrt(n),3)}',fontsize=15)

오차한계 표준정규분포

오차한계 = 1.96*모표준편차 / 루트(개수) = 0.62

 

2> 모분산 = 15

 

오차한계 표준정규분포

오차한계 = 1.96*모표준편차 / 루트(개수) = 1.074

 

 

3> 모분산 = 25

 

오차한계 표준정규분포

오차한계 = 1.96*모표준편차 / 루트(개수) = 1.386

 

4> 모분산 = 35

 

오차한계 표준정규분포

오차한계 = 1.96*모표준편차 / 루트(개수) = 1.64

 

2. 모분산이 4인 정규모집단의 모평균에 대한 95% 신뢰도를 갖는 구간을 추정하기 위하여 다음과 같은 크기의 표본을 선정한다. 이때 오차한계를 구하라.

 

1> n = 50

 

x = np.arange(-5,5 , .001)

fig = plt.figure(figsize=(15,8))
ax = sns.lineplot(x , stats.norm.pdf(x, loc=0 , scale =1)) #정의역 범위 , 평균 = 0 , 표준편차 =1 인 정규분포 플롯

trust = 95 #신뢰도

# z_1 = round((0.05) / math.sqrt( 0.0018532 ) ,2)
# # z_2 = round((34.5 - 35) / math.sqrt(5.5**2 / 25) , 2)
z_1 = round(scipy.stats.norm.ppf(1 - (1-(trust/100))/2) ,3 )

ax.fill_between(x, stats.norm.pdf(x, loc=0 , scale =1) , 0 , where = (x<=z_1) & (x>=-z_1) , facecolor = 'skyblue') # x값 , y값 , 0 , x<=0 인곳 , 색깔



area = scipy.stats.norm.cdf(z_1) - scipy.stats.norm.cdf(-z_1)
plt.annotate('' , xy=(0, .1), xytext=(2 , .1)  , arrowprops = dict(facecolor = 'black'))

ax.vlines(x= z_1, ymin= 0 , ymax= stats.norm.pdf(z_1, loc=0 , scale =1) , color = 'black' , linestyle ='solid' , label ='{}'.format(2))
ax.vlines(x= -z_1, ymin= 0 , ymax= stats.norm.pdf(-z_1, loc=0 , scale =1) , color = 'black' , linestyle ='solid' , label ='{}'.format(2))

ax.text(2 , .1, f'P({-z_1}<=Z<={z_1}) : {round(area,4)}',fontsize=15)

ax.text(2 , .15, f'신뢰구간 모평균에 대한 {trust}% : \n' + r'$\overline{X}$' +f'-{z_1}' + r'$\dfrac{\sigma}{\sqrt{n}},\overline{X}$' + f'+{z_1}' + r'$\dfrac{\sigma}{\sqrt{n}}$',fontsize=15)


STDS = round(math.sqrt(4),3) #모표준편차
n = 50



ax.text(2 , .35,  r'$\sigma = $' + f'{STDS}\n' + r'$\sqrt{n} = $' + f'{round(math.sqrt(n),3)}',fontsize=15)

ax.text(2 , .3,  r'신뢰구간 L = $2*{%.3f}\dfrac{\sigma}{\sqrt{n}} = $' % z_1 + f'{round(2* z_1 * STDS / math.sqrt(n),3)}',fontsize=15)

ax.text(2 , .25,  r'오차한계 = ${%.3f}\dfrac{\sigma}{\sqrt{n}} = $' % z_1 + f'{round(z_1 * STDS / math.sqrt(n),3)}',fontsize=15)

오차한계 표준정규분포

오차한계 = 1.96*모표준편차 / 루트(개수) = 0.554

 

2> n = 100

 

오차한계 표준정규분포

오차한계 = 1.96*모표준편차 / 루트(개수) = 0.392

 

3> n = 200

 

오차한계 표준정규분포

오차한계 = 1.96*모표준편차 / 루트(개수) = 0.277

 

4> n = 500

 

오차한계 표준정규분포

오차한계 = 1.96*모표준편차 / 루트(개수) = 0.175

 

 

3. 모비율에 대한 95% 신뢰도를 갖는 구간을 추정하기 위하여 다음과 같은 크기의 표본을 선정하여 조사한 결과, 표본비율이 ^p = 0.75였다. 이때 오차한계를 구하라.

 

1> n = 50

 

x = np.arange(-5,5 , .001)

fig = plt.figure(figsize=(15,8))

ax = sns.lineplot(x , stats.norm.pdf(x, loc=0 , scale =1)) #정의역 범위 , 평균 = 0 , 표준편차 =1 인 정규분포 플롯

trust = 95 #신뢰구간

# z_1 = round((0.05) / math.sqrt( 0.0018532 ) ,2)
# # z_2 = round((34.5 - 35) / math.sqrt(5.5**2 / 25) , 2)
z_1 = round(scipy.stats.norm.ppf(1 - (1-(trust/100))/2) ,3 )

ax.fill_between(x, stats.norm.pdf(x, loc=0 , scale =1) , 0 , where = (x<=z_1) & (x>=-z_1) , facecolor = 'skyblue') # x값 , y값 , 0 , x<=0 인곳 , 색깔



area = scipy.stats.norm.cdf(z_1) - scipy.stats.norm.cdf(-z_1)
plt.annotate('' , xy=(0, .1), xytext=(2 , .1)  , arrowprops = dict(facecolor = 'black'))

ax.vlines(x= z_1, ymin= 0 , ymax= stats.norm.pdf(z_1, loc=0 , scale =1) , color = 'black' , linestyle ='solid' , label ='{}'.format(2))
ax.vlines(x= -z_1, ymin= 0 , ymax= stats.norm.pdf(-z_1, loc=0 , scale =1) , color = 'black' , linestyle ='solid' , label ='{}'.format(2))

ax.text(2 , .1, f'P({-z_1}<=Z<={z_1}) : {round(area,4)}',fontsize=15)

ax.text(2 , .15, f'신뢰구간 모평균에 대한 {trust}% : \n' + r'$\widehat{p}$' +f'-{z_1}' + r'$\sqrt{\dfrac{\widehat{p}\widehat{q}}{n}}$' +' , '+ r'$\widehat{p}$' +f'+ {z_1}' + r'$\sqrt{\dfrac{\widehat{p}\widehat{q}}{n}}$',fontsize=15)




# print((z_1 * STDS / math.sqrt(len(A))))

# STDS = round(math.sqrt(4),3) #모표준편차
RATIO = 0.75
n = 50


ax.text(2 , .35,  r'$\sqrt{\widehat{p}\widehat{q}} = $' + f'{round(math.sqrt(RATIO * (1-RATIO)),3)}\n'  + r'$\sqrt{n} = $' + f'{round(math.sqrt(n),2)}',fontsize=15)


ax.text(2 , .3,  r'신뢰구간 L = $2*{%.3f}\sqrt{\dfrac{\widehat{p}\widehat{q}}{n}} = $' % z_1 + f'{round(2* z_1 * math.sqrt(RATIO * (1-RATIO) / n),3)}',fontsize=15)

ax.text(2 , .25,  r'오차한계 = ${%.3f}\dfrac{\sigma}{\sqrt{n}} = $' % z_1 + f'{round(z_1 * math.sqrt(RATIO * (1-RATIO) / n),3)}',fontsize=15)




print(z_1)

모비율에 대한 오차한계

 

오차한계 : 0.12

 

 

2> n = 100

 

모비율에 대한 오차한계

오차한계 : 0.085

 

3> n = 200

 

모비율에 대한 오차한계

 

오차한계 : 0.06

 

4> n = 500

 

모비율에 대한 오차한계

 

오차한계 : 0.038

 

출처 :  [쉽게 배우는 생활속의 통계학]  [북스힐 , 이재원] 

※혼자 공부 정리용

728x90
반응형

+ Recent posts