검정 통계량과 효과 크기
부트스트랩 리샘플링으로 선형 관계를 어떻게 탐색할 수 있을까요? 다시 트레일로 돌아가 보죠! 각 하이킹을 하나의 점으로 그리면, 총 이동 거리와 경과 시간 사이에 선형 관계가 있음을 볼 수 있어요. 경과 시간을 원인으로 보고 이동 거리를 그에 따른 "효과"로 간주하면, 선형 회귀와 통계적 추론 사이의 연결고리를 탐색할 수 있습니다.
이 연습에서는 데이터를 두 개의 모집단(또는 "범주")으로 나눕니다: 초기 시간대와 후기 시간대. 그런 다음 각 모집단 내에서의 총 이동 거리의 차이를 살펴봅니다. 이 차이가 "검정 통계량" 역할을 하며, 그 분포를 통해 시간을 기준으로 거리를 나누는 효과를 검정합니다.

이 연습은 강의의 일부입니다
Python으로 배우는 선형 모델 입문
연습 안내
numpy의 논리 인덱싱(예:sample_distances[sample_times < 5])을 사용해 샘플distances를 초기·후기 시간대의 두 모집단으로 분리하세요.- 두 시간 구간 각각에 대해
np.random.choice()를replacement=True로 설정하여resample을 생성하세요. test_statistic배열을resample_long - resample_short로 계산하고,np.mean(),np.std()로 효과 크기와 불확실성을 계산해 출력하세요.- 미리 정의된
fig = plot_test_statistic()을 사용해test_statistic분포를 그리세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Create two poulations, sample_distances for early and late sample_times.
# Then resample with replacement, taking 500 random draws from each population.
group_duration_short = sample_distances[____ < 5]
group_duration_long = sample_distances[____ > 5]
resample_short = np.random.choice(____, size=500, replace=____)
resample_long = np.random.choice(____, size=500, replace=____)
# Difference the resamples to compute a test statistic distribution, then compute its mean and stdev
test_statistic = resample_long - resample_short
effect_size = np.mean(____)
standard_error = np.std(____)
# Print and plot the results
print('Test Statistic: mean={:0.2f}, stdev={:0.2f}'.format(____, ____))
fig = plot_test_statistic(____)