올바른 통계 검정 선택

Python으로 배우는 실험 설계

James Chapman

Curriculum Manager, DataCamp

적절한 검정 선택

 

  • 데이터셋 특성
    • 데이터 타입
    • 분포 → 많은 검정에서 정규성 가정!
    • 변수 개수
  • 가설

결과: 정확하고 신뢰할 수 있는 결론!

  • t-검정, ANOVA, 카이제곱

도구와 책의 라이브러리

Python으로 배우는 실험 설계

데이터셋: 운동 성과

  • 훈련 프로그램과 식단이 운동 성과에 미치는 영향
athletic_perf.sample(n=5)
 Athlete_ID  Training_Program     Diet_Type  Initial_Fitness  Performance_Inc 
        167         Endurance   Plant-Based             High         9.113040               
        289         Endurance          Keto              Low        11.039744               
        164         Endurance   Plant-Based           Medium        11.614835              
         30          Strength          Keto           Medium         7.384686               
        186              HIIT  High-Protein              Low         6.776078
Python으로 배우는 실험 설계

독립표본 t-검정

  • 두 집단의 평균 비교
  • 가정: 정규분포, 등분산
from scipy.stats import ttest_ind
group1 = athletic_perf[athletic_perf['Training_Program'] == 'HIIT']['Performance_Inc']
group2 = athletic_perf[athletic_perf['Training_Program'] == 'Endurance']['Performance_Inc']

t_stat, p_val = ttest_ind(group1, group2) print(f"T-statistic: {t_stat}, P-value: {p_val}")
T-statistic: 0.20671020082911742, P-value: 0.8364563849070663

p_val > $\alpha$ → 평균 차이에 대한 증거 불충분

Python으로 배우는 실험 설계

일원분산분석(ANOVA)

  • 여러 집단(>2) 간 평균 비교
  • 가정: 집단 간 등분산
from scipy.stats import f_oneway
program_types = ['HIIT', 'Endurance', 'Strength']
groups = [athletic_perf_data[athletic_perf_data['Training_Program'] == program]
['Performance_Increase'] for program in program_types]

f_stat, p_val = f_oneway(*groups) print(f"F-statistic: {f_stat}, P-value: {p_val}")
F-statistic: 1.5270022393256704, P-value: 0.2188859009050602

p_val > $\alpha$ → 평균 차이에 대한 증거 불충분

Python으로 배우는 실험 설계

카이제곱 독립성 검정

  • 범주형 변수 간 관계 검정
  • 분포에 대한 가정 없음
from scipy.stats import chi2_contingency
import pandas as pd
contingency_table = pd.crosstab(athletic_perf['Training_Program'],
                                athletic_perf['Diet_Type'])
Diet_Type         High-Protein  Keto  Plant-Based
Training_Program                                 
Endurance                   33    28           33
HIIT                        27    32           40
Strength                    38    29           40
Python으로 배우는 실험 설계

카이제곱 독립성 검정

chi2_stat, p_val, dof, expected = chi2_contingency(contingency_table)
print(f"Chi2-statistic: {chi2_stat}, P-value: {p_val}")
Chi2-statistic: 2.154450885821988, P-value: 0.7073764021451127

p_val > $\alpha$ → 연관성에 대한 증거 불충분

Python으로 배우는 실험 설계

연습해 봅시다!

Python으로 배우는 실험 설계

Preparing Video For Download...