본문 바로가기
- 배움이 있는 삶/- Software

python- 비율검정 ( 1 proportion / 2 proportion) test

by story of interesting 2022. 8. 30.
반응형

파이선으로 2개의 서로다른 조직에 대한 측정한 비율이 같은지, 다른지를 측정하는 통계 기법임

 

# 1 proportion z test
# A중학교에는 100명 중에 45명이 흡연을 한다. 국가 통계를 보니 중학생 흡연율은 35%라고 한다. 같나?
# import numpy as np
# from statsmodels.stats.proportion import proportions_ztest
#
# count = np.array([45])
# nobs = np.array([100])
# val = 0.35
#
# z, p = proportions_ztest(count=count, nobs=nobs, value=val)
# print(z)
# print(p)


# 2 proportion z test #
# 복날에 A회사 사람들 300명 중 100명이 삼계탕을 먹었고, B회사 사람들 400명 중 170명이 삼계탕을 먹었다. 비율이 같냐?
import numpy as np
from statsmodels.stats.proportion import proportions_ztest

count = np.array([100, 170])  # pass count
nobs = np.array([300, 400])   # total trial count

z, p = proportions_ztest(count=count, nobs=nobs, value=0)
print(z)
print(p)  #소수점이 너무 길어짐  
print("%.5f" %p)  #소수점 5자리까지 출력하면, p value값 확인용이 (p vlue <0.005 대립가설채택 (서로 같지 않다))

 

여기서 파이선에 그냥 사용하면 error가 발생함

- Interpreter를 추가해 줘야 함  :  statsmodels  

 

 

(참고 site )

https://www.statsmodels.org/dev/generated/statsmodels.stats.proportion.proportions_ztest.html

 

statsmodels.stats.proportion.proportions_ztest — statsmodels

The alternative hypothesis can be either two-sided or one of the one- sided tests, smaller means that the alternative hypothesis is prop < value and larger means prop > value. In the two sample test, smaller means that the alternative hypothesis is p1 < p2

www.statsmodels.org

 

http://www.databaser.net/moniwiki/wiki.php/Python-%EB%B9%84%EC%9C%A8%EA%B2%80%EC%A0%95

 

DataBaser.Net: Python - 비율 검정

목차 1 one-sample 2 two-sample 1 one-sample # A중학교에는 100명 중에 45명이 흡연을 한다. 국가 통계를 보니 중학생 흡연율은 35%라고 한다. 같나? import numpy as np from statsmodels.stats.proportion import proportions_ztest

www.databaser.net

 

반응형