P-값 시각화하기
이번 연습에서는 p-값을 시각화해 볼 거예요. p-값은 우리가 추정한 효과(또는 "속도")가 표본의 무작위 변동으로 인해 나타났을 가능성을 의미해요. 무작위로 섞지 않은 표본에서 계산한 검정 통계량의 평균("효과 크기")의 오른쪽에 위치하는, 섞인 검정 통계량 분포의 점들이 차지하는 비율로 이를 시각화하는 것이 목표예요.
시작할 수 있도록, group_duration_short와 group_duration_long, 그리고 함수 compute_test_statistic(), shuffle_and_split(), plot_test_statistic_effect()를 미리 불러왔어요.
이 연습은 강의의 일부입니다
Python으로 배우는 선형 모델 입문
연습 안내
compute_test_statistic()을(를) 사용해group_duration_short와group_duration_long에서test_statistic_unshuffled를 구한 다음,np.mean()으로 효과 크기(effect size)를 계산하세요.shuffle_and_split()을(를) 사용해shuffle_half1와shuffle_half2를 만들고,compute_test_statistic()으로test_statistic_shuffled를 계산하세요.- 불리언 마스크
condition을 만들어test_statistic_shuffled값이effect_size보다 크거나 같도록 지정한 뒤, 이 마스크를 사용해p_value를 계산하세요. p_value를 출력하고plot_test_statistic_effect()으로 두 검정 통계량을 모두 그리세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Compute the test stat distribution and effect size for two population groups
test_statistic_unshuffled = compute_test_statistic(____, ____)
effect_size = np.mean(____)
# Randomize the two populations, and recompute the test stat distribution
shuffled_half1, ____ = shuffle_and_split(group_duration_short, ____)
test_statistic_shuffled = compute_test_statistic(shuffled_half1, ____)
# Compute the p-value as the proportion of shuffled test stat values >= the effect size
condition = ____ >= ____
p_value = len(test_statistic_shuffled[____]) / len(test_statistic_shuffled)
# Print p-value and overplot the shuffled and unshuffled test statistic distributions
print("The p-value is = {}".format(____))
fig = plot_test_stats_and_pvalue(test_statistic_unshuffled, test_statistic_shuffled)