Python에서 배우는 추론 통계 기초
Paul Savala
Assistant Professor of Mathematics
| 표본 크기 | 효과 크기 | 유의수준(알파) |
|---|---|---|
![]() |
![]() |
![]() |
from scipy.stats import norm# 대조군: 평균 0파운드, 표준편차 1파운드control = norm.rvs(loc=0,scale=1,size=100)# 처치군: 평균 -2파운드, 표준편차 1파운드treatment = norm.rvs(loc=-2, scale=1, size=100)
$H_0$: 체중 감소 차이 없음(오답)
$H_a$: 처치군이 체중 감소(정답)
결론: $H_0$를 기각하고 $H_a$를 채택함(정답).
from scipy.stats import ttest_ind# t-검정 수행 alpha = 0.05 t_test = ttest_ind(treatment, control, alternative='less')# 유의성 확인 print(t_test.pvalue < alpha)
TRUE
control = norm.rvs(loc=0, scale=1, size=5) treatment = norm.rvs(loc=-2, scale=1, size=5)# t-검정 수행 tt = ttest_ind(treatment, control, alternative='less')print(tt.pvalue < 0.05)
FALSE
결론: H0 기각 실패(오류)
# 체중 감소 = 0.2파운드, 표본 크기 = 100treatment = norm.rvs(loc=-0.2, scale=1, size=100)# t-검정 수행 t_test = ttest_ind(treatment, control, alternative='less')print(t_test.pvalue < 0.05)
FALSE

유의한 효과가 있으면, 검정이 이를 탐지할까요?

검정력: 대립가설(Ha)이 참일 때, 주어진 데이터로 영가설(H0)을 기각할 확률은?
표본 수집 전 검정력을 계산하십시오
from statsmodels.stats import power # 검정력 함수 tt_power = power.TTestIndPower()# 검정력 계산 pwr = tt_power.power(effect_size=0.2,nobs1=100,alpha=0.05)print(pwr)
0.291
탐지 확률이 낮습니다!
nobs1 = TTestIndPower().solve_power(effect_size=-0.2, nobs1=None, # Solve for alpha=0.05, power=0.8)print(nobs1)
13735.26
Python에서 배우는 추론 통계 기초