검정력 분석 - Part II
이전에 우리는 실험을 한 번만 시뮬레이션해 p-값을 생성했어요. 이제 이 틀을 사용해 통계적 검정력을 계산해 보겠습니다. 실험의 검정력(power)은 실제로 차이가 있을 때 처리군과 대조군 간의 차이를 찾아낼 수 있는 능력을 말합니다. 일반적으로 80% 검정력을 목표로 삼는 것이 바람직해요.
우리 웹사이트의 경우, 체류 시간이 10% 증가했을 때 이를 80% 검정력으로 검출하려면 각 변형안에 몇 명이 방문해야 하는지 알고 싶다고 가정해 봅시다. 이를 위해 작은 표본(50)으로 시작해, 이 실험을 여러 번 시뮬레이션하고 검정력을 확인합니다. 만약 80% 검정력에 도달하면 중단하고, 그렇지 않으면 표본 크기를 늘려 다시 시도해요.
이 연습은 강의의 일부입니다
Python으로 하는 통계 시뮬레이션
연습 안내
time_spent랜덤 변수에서size를 튜플로 설정해 모양이sample_size\(\times\)sims가 되도록 하세요.- p-값 중 0.05보다 작은 비율(통계적으로 유의함)을
power로 계산하세요. power가 80% 이상이면 while 루프에서break하세요. 그렇지 않으면sample_size를 10씩 계속 늘리세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
sample_size = 50
# Keep incrementing sample size by 10 till we reach required power
while 1:
control_time_spent = np.random.normal(loc=control_mean, scale=control_sd, size=(____,____)))
treatment_time_spent = np.random.normal(loc=control_mean*(1+effect_size), scale=control_sd, size=(____,____))
t, p = st.ttest_ind(treatment_time_spent, control_time_spent)
# Power is the fraction of times in the simulation when the p-value was less than 0.05
power = (p < 0.05).sum()/____
if ____:
____
else:
____ += ____
print("For 80% power, sample size required = {}".format(sample_size))