검정 통계량 시각화하기
이 연습 문제에서는 두 가지 서로 다른 방식으로 얻은 검정 통계량의 분포를 비교하여 영가설에 접근해 보겠습니다.
먼저, 이른 시간대와 늦은 시간대로 묶인 두 "모집단"을 살펴보고 검정 통계량 분포를 계산합니다. 다음으로, 두 모집단을 섞어서 데이터의 시간 순서를 없애고 각 집단에 이른/늦은 시간이 혼합되도록 한 뒤, 검정 통계량 분포를 다시 계산합니다.
시작할 수 있도록, 두 시간 구간 그룹 group_duration_short와 group_duration_long, 그리고 두 함수 shuffle_and_split()과 plot_test_statistic()을 미리 로드해 두었습니다.
이 연습은 강의의 일부입니다
Python으로 배우는 선형 모델 입문
연습 안내
np.random.choice()를 사용해group_duration_short와group_duration_long을 리샘플링하고, 두 리샘플의 차이를 내어test_statistic_unshuffled를 계산하세요.- 원본
group_duration_short와group_duration_long에 대해 이 순서로shuffle_and_split()을 사용해 두 개의 새로운 혼합 모집단을 만드세요. - 섞인 모집단을 리샘플링하고,
resample_long에서resample_short를 빼서 새로운test_statistic_shuffled를 계산하세요. plot_test_statistic()을 사용해 두 검정 통계량 분포를 모두 그려 보고 시각적으로 비교하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# From the unshuffled groups, compute the test statistic distribution
resample_short = np.random.choice(____, size=500, replace=____)
resample_long = np.random.choice(____, size=500, replace=____)
test_statistic_unshuffled = ____ - ____
# Shuffle two populations, cut in half, and recompute the test statistic
shuffled_half1, shuffled_half2 = shuffle_and_split(____, ____)
resample_half1 = np.random.choice(____, size=500, replace=____)
resample_half2 = np.random.choice(____, size=500, replace=____)
test_statistic_shuffled = resample_half2 - resample_half1
# Plot both the unshuffled and shuffled results and compare
fig = plot_test_statistic(____, label='Unshuffled')
fig = plot_test_statistic(____, label='Shuffled')