안녕하세요. 그녀입니다.👩🏻🏫
데이터 분석에 필요한 통계를 주제로 몇 가지 포스팅 해보려 합니다~
그 중 첫번째는 T-Test 검정인데요,
실무에서 A/B Test나 Switchback test진행 시, 기본적으로 사용하는 통계기법이기에 이참에 저도 한 판 정리를 해보려고 합니다!!
1. t-test는 언제쓰죠?
가설의 독립변수가 범주형이고, 종속변수가 연속형일 때 사용 할 수 있는 검정 방식인데요.
t-test는 두 개의 표본 평균간의 차이를 검정합니다!
검정한다는 뜻은 평균간의 차이가 유의미한지 통계적으로 확인하는 과정이다 라고 이해하시면 됩니다.

2. 무엇을 검정하나요?
모집단의 분산이나 표준편차를 알지 못 할 때, 모집단을 대표하는 표본으로부터 추정된 분산이나 표준편차를 가지고 검정하는 방법입니다.
주로, 채택하고자 하는 바를 "대립가설"에 두고 통계적 검정을 진행하게 됩니다.
- 귀무가설 (null hypothesis): 두 모집단의 평균은 차이가 없다. (H₀: µ₁=µ₂)
- 대립가설 (althernate hypothesis): 두 모집단의 평균은 차이가 있다. (H1: µ₁≠µ₂)
가설 설정에 대해 설명이 더 필요하다면 https://funziit.tistory.com/28 참고해주세요~
3. 검정 방법
t-test는 아래 3가지의 검정 방식이 있는데요

구분 | 일표본 T 검정(One sample t-test) | 독립표본 T 검정(Independent sample t-test) |
대응표본 T 검정(Paired sample t-test)
|
정의 | 표본의 평균과 특정 기준값의 차이 분석 | 독립된 두 표본(=집단)의 평균 차이 분석 |
짝을 이룬 데이터의 평균 변화 분석
|
예시 | A대학의 남학생 평균 키가 180cm와 같은지, 다른지 비교 |
고객 등급별 평균 매출액 차이
|
신제품 출시에 따른 광고 전, 후 매출액의 차이 |
python code | stats.ttest_1samp(data_diff, 기준값) |
stats.ttest_ind(dat_M, dat_F, alternative=")
- 양측 : ‘two-sided’ (default) - 단측 : ‘less’ ‘greater’ - ‘less’: the mean of the distribution underlying the first sample is less than the mean of the distribution underlying the second sample. - ‘greater’: the mean of the distribution underlying the first sample is greater than the mean of the distribution underlying the second sample. |
stats.ttest_rel(dat_M, dat_F) |
4. t-value

- 단측검정(ond-tailed test) : 샘플 데이터의 평균이 X와 같다 / 같지 않다. 를 검정하는 내용
- 양측검정(two-tailed test) : 샘플 데이터의 평균이 X보다 크다 혹은 작다 를 검정하는 내용

5. 해석
예를 들어, 유의 수준(α)을 0.05라고 가정할 때, t값이 커져서 (평균차이가 있을 가능성이 커져서) 기각역에 존재하여 유의확률(p값, p-value)이 0.05보다 작으면 평균 차이가 유의미한 것으로 해석되어 귀무가설을 기각합니다.
그 반대의 경우, 평균 차이가 유의미하지 않으므로 귀무가설을 수용합니다.
6. python code
일표본 T 검정(One sample t-test)
stats.ttest_1samp(data_diff, 기준값)
독립표본 T 검정(Independent sample t-test)
stats.ttest_ind(data1, data2, alternative ='two-sided')
# 양측 : ‘two-sided’ (default)
# 단측 : ‘less’ ‘greater’
# - ‘less’: the mean of the distribution underlying the first sample is less than the mean of the distribution underlying the second sample.
# - ‘greater’: the mean of the distribution underlying the first sample is greater than the mean of the distribution underlying the second sample.
대응표본 T 검정(Paired sample t-test)
import scipy.stats
scipy.stats.ttest_rel(dat_M, dat_F)
'그녀의 일' 카테고리의 다른 글
[Streamlit] 초기세팅 / 데이터브릭스 (databricks) & 스프레드시트 (gspread) 연동 (1) | 2024.06.21 |
---|---|
[SQL] 리텐션 구하기 | N-Day Retention, Range Retention, Rolling Retention (0) | 2023.04.25 |
기초 통계 용어 정리 | 귀무가설, 대립가설, 유의수준, p-value (0) | 2023.04.07 |
Swtichback test란? (0) | 2023.03.23 |
Apach Kafka 란? | producer, consumer, topic, partition 용어 설명 (0) | 2023.03.16 |